Skip to content

Commit 3666090

Browse files
feat: demo things
1 parent 35d28fe commit 3666090

31 files changed

Lines changed: 752 additions & 32 deletions

src/1-Libraries/Application/Application.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<TargetFramework>net8.0</TargetFramework>
44
<AssemblyName>CanBeYours.Application</AssemblyName>
55
<RootNamespace>CanBeYours.Application</RootNamespace>
6+
<ImplicitUsings>enable</ImplicitUsings>
67
</PropertyGroup>
78
<ItemGroup>
89
<PackageReference Include="CodeBlock.DevKit.Application" Version="1.3.4" />
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Resources;
3+
using CodeBlock.DevKit.Contracts.Dtos;
4+
5+
namespace CanBeYours.Application.Dtos;
6+
7+
public class CreateDemoThingDto : BaseDto
8+
{
9+
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Name))]
10+
public string Name { get; set; }
11+
12+
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Description))]
13+
public string Description { get; set; }
14+
}

src/1-Libraries/Application/Dtos/GetDemoThingDto.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
namespace CanBeYours.Application.Dtos;
44

5-
public class GetDemoThingDto : GetEntityDto
5+
public class GetDemoThingDto : BaseDto
66
{
7-
public GetDemoThingDto() { }
8-
97
public string Name { get; set; }
108
public string Description { get; set; }
119
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using CodeBlock.DevKit.Contracts.Dtos;
2+
3+
namespace CanBeYours.Application.Dtos;
4+
5+
public class SearchDemoThingsInputDto : SearchInputDto
6+
{
7+
// Add any additional search filters here if needed in the future
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Resources;
3+
using CodeBlock.DevKit.Contracts.Dtos;
4+
5+
namespace CanBeYours.Application.Dtos;
6+
7+
public class UpdateDemoThingDto : BaseDto
8+
{
9+
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Name))]
10+
public string Name { get; set; }
11+
12+
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Description))]
13+
public string Description { get; set; }
14+
}
Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1-
namespace CanBeYours.Application.Services.DemoThings;
1+
using CanBeYours.Application.Dtos;
2+
using CanBeYours.Application.UseCases.DemoThings.CreateDemoThing;
3+
using CanBeYours.Application.UseCases.DemoThings.GetDemoThing;
4+
using CanBeYours.Application.UseCases.DemoThings.SearchDemoThings;
5+
using CanBeYours.Application.UseCases.DemoThings.UpdateDemoThing;
6+
using CodeBlock.DevKit.Application.Srvices;
7+
using CodeBlock.DevKit.Contracts.Dtos;
8+
using CodeBlock.DevKit.Core.Helpers;
29

3-
public class DemoThingService : IDemoThingService { }
10+
namespace CanBeYours.Application.Services.DemoThings;
11+
12+
internal class DemoThingService : ApplicationService, IDemoThingService
13+
{
14+
public DemoThingService(IRequestDispatcher requestDispatcher)
15+
: base(requestDispatcher) { }
16+
17+
public async Task<Result<GetDemoThingDto>> GetDemoThing(string id)
18+
{
19+
return await _requestDispatcher.SendQuery(new GetDemoThingRequest(id));
20+
}
21+
22+
public async Task<Result<CommandResult>> CreateDemoThing(CreateDemoThingDto input)
23+
{
24+
return await _requestDispatcher.SendCommand(new CreateDemoThingRequest(input.Name, input.Description));
25+
}
26+
27+
public async Task<Result<CommandResult>> UpdateDemoThing(string id, UpdateDemoThingDto input)
28+
{
29+
return await _requestDispatcher.SendCommand(new UpdateDemoThingRequest(id, input.Name, input.Description));
30+
}
31+
32+
public async Task<Result<SearchOutputDto<GetDemoThingDto>>> SearchDemoThings(SearchDemoThingsInputDto input)
33+
{
34+
return await _requestDispatcher.SendQuery(
35+
new SearchDemoThingsRequest(input.Term, input.PageNumber, input.RecordsPerPage, input.SortOrder)
36+
);
37+
}
38+
}
Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1-
namespace CanBeYours.Application.Services.DemoThings;
1+
using CanBeYours.Application.Dtos;
2+
using CodeBlock.DevKit.Contracts.Dtos;
3+
using CodeBlock.DevKit.Core.Helpers;
24

3-
public interface IDemoThingService { }
5+
namespace CanBeYours.Application.Services.DemoThings;
6+
7+
public interface IDemoThingService
8+
{
9+
Task<Result<GetDemoThingDto>> GetDemoThing(string id);
10+
Task<Result<CommandResult>> CreateDemoThing(CreateDemoThingDto input);
11+
Task<Result<CommandResult>> UpdateDemoThing(string id, UpdateDemoThingDto input);
12+
Task<Result<SearchOutputDto<GetDemoThingDto>>> SearchDemoThings(SearchDemoThingsInputDto input);
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Resources;
3+
using CodeBlock.DevKit.Application.Commands;
4+
using CodeBlock.DevKit.Core.Resources;
5+
6+
namespace CanBeYours.Application.UseCases.DemoThings.CreateDemoThing;
7+
8+
internal class CreateDemoThingRequest : BaseCommand
9+
{
10+
public CreateDemoThingRequest(string name, string description)
11+
{
12+
Name = name;
13+
Description = description;
14+
}
15+
16+
[Display(Name = nameof(SharedResource.DemoThing_Name), ResourceType = typeof(SharedResource))]
17+
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
18+
public string Name { get; }
19+
20+
[Display(Name = nameof(SharedResource.DemoThing_Description), ResourceType = typeof(SharedResource))]
21+
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
22+
public string Description { get; }
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using CanBeYours.Core.Domain.DemoThings;
2+
using CodeBlock.DevKit.Application.Commands;
3+
using CodeBlock.DevKit.Application.Srvices;
4+
using CodeBlock.DevKit.Core.Helpers;
5+
using MediatR;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace CanBeYours.Application.UseCases.DemoThings.CreateDemoThing;
9+
10+
internal class CreateDemoThingUseCase : BaseCommandHandler, IRequestHandler<CreateDemoThingRequest, CommandResult>
11+
{
12+
private readonly IDemoThingRepository _demoThingRepository;
13+
14+
public CreateDemoThingUseCase(IDemoThingRepository demoThingRepository, IRequestDispatcher requestDispatcher, ILogger<CreateDemoThingUseCase> logger)
15+
: base(requestDispatcher, logger)
16+
{
17+
_demoThingRepository = demoThingRepository;
18+
}
19+
20+
public async Task<CommandResult> Handle(CreateDemoThingRequest request, CancellationToken cancellationToken)
21+
{
22+
var demoThing = DemoThing.Create(request.Name, request.Description);
23+
24+
await _demoThingRepository.AddAsync(demoThing);
25+
26+
await PublishDomainEventsAsync(demoThing.GetDomainEvents());
27+
28+
return CommandResult.Create(entityId: demoThing.Id);
29+
}
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using CanBeYours.Application.Dtos;
2+
using CodeBlock.DevKit.Application.Queries;
3+
4+
namespace CanBeYours.Application.UseCases.DemoThings.GetDemoThing;
5+
6+
internal class GetDemoThingRequest : BaseQuery<GetDemoThingDto>
7+
{
8+
public GetDemoThingRequest(string id)
9+
{
10+
Id = id;
11+
}
12+
13+
public string Id { get; }
14+
}

0 commit comments

Comments
 (0)