Skip to content

Commit aa4ecd5

Browse files
feat: add type to demo thing
1 parent 09cbcc7 commit aa4ecd5

File tree

15 files changed

+176
-27
lines changed

15 files changed

+176
-27
lines changed

src/1-Libraries/Application/Application.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<ItemGroup>
99
<PackageReference Include="CodeBlock.DevKit.Application" Version="1.3.5" />
1010
<PackageReference Include="CodeBlock.DevKit.Contracts" Version="1.3.5" />
11+
<PackageReference Include="CodeBlock.DevKit.Identity" Version="1.3.5" />
1112
</ItemGroup>
1213
<ItemGroup>
1314
<ProjectReference Include="..\Core\Core.csproj" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Domain.DemoThings;
23
using CanBeYours.Core.Resources;
4+
using CodeBlock.DevKit.Core.Resources;
35

46
namespace CanBeYours.Application.Dtos;
57

68
public class CreateDemoThingDto
79
{
10+
[Display(Name = nameof(SharedResource.DemoThing_Name), ResourceType = typeof(SharedResource))]
811
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Name))]
912
public string Name { get; set; }
1013

14+
[Display(Name = nameof(SharedResource.DemoThing_Description), ResourceType = typeof(SharedResource))]
1115
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Description))]
1216
public string Description { get; set; }
17+
18+
[Display(Name = nameof(SharedResource.DemoThing_Type), ResourceType = typeof(SharedResource))]
19+
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
20+
public DemoThingType Type { get; set; }
1321
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using CanBeYours.Core.Domain.DemoThings;
12
using CodeBlock.DevKit.Contracts.Dtos;
23

34
namespace CanBeYours.Application.Dtos;
@@ -6,4 +7,6 @@ public class GetDemoThingDto : GetEntityDto
67
{
78
public string Name { get; set; }
89
public string Description { get; set; }
10+
public DemoThingType Type { get; set; }
11+
public string UserId { get; set; }
912
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Domain.DemoThings;
23
using CanBeYours.Core.Resources;
4+
using CodeBlock.DevKit.Core.Resources;
35

46
namespace CanBeYours.Application.Dtos;
57

68
public class UpdateDemoThingDto
79
{
10+
[Display(Name = nameof(SharedResource.DemoThing_Name), ResourceType = typeof(SharedResource))]
811
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Name))]
912
public string Name { get; set; }
1013

14+
[Display(Name = nameof(SharedResource.DemoThing_Description), ResourceType = typeof(SharedResource))]
1115
[Required(ErrorMessageResourceType = typeof(SharedResource), ErrorMessageResourceName = nameof(SharedResource.DemoThing_Description))]
1216
public string Description { get; set; }
17+
18+
[Display(Name = nameof(SharedResource.DemoThing_Type), ResourceType = typeof(SharedResource))]
19+
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
20+
public DemoThingType Type { get; set; }
1321
}

src/1-Libraries/Application/Services/DemoThings/DemoThingService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public async Task<Result<GetDemoThingDto>> GetDemoThing(string id)
2121

2222
public async Task<Result<CommandResult>> CreateDemoThing(CreateDemoThingDto input)
2323
{
24-
return await _requestDispatcher.SendCommand(new CreateDemoThingRequest(input.Name, input.Description));
24+
return await _requestDispatcher.SendCommand(new CreateDemoThingRequest(input.Name, input.Description, input.Type));
2525
}
2626

2727
public async Task<Result<CommandResult>> UpdateDemoThing(string id, UpdateDemoThingDto input)
2828
{
29-
return await _requestDispatcher.SendCommand(new UpdateDemoThingRequest(id, input.Name, input.Description));
29+
return await _requestDispatcher.SendCommand(new UpdateDemoThingRequest(id, input.Name, input.Description, input.Type));
3030
}
3131

3232
public async Task<Result<SearchOutputDto<GetDemoThingDto>>> SearchDemoThings(SearchDemoThingsInputDto input)

src/1-Libraries/Application/UseCases/DemoThings/CreateDemoThing/CreateDemoThingRequest.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Domain.DemoThings;
23
using CanBeYours.Core.Resources;
34
using CodeBlock.DevKit.Application.Commands;
45
using CodeBlock.DevKit.Core.Resources;
@@ -7,10 +8,11 @@ namespace CanBeYours.Application.UseCases.DemoThings.CreateDemoThing;
78

89
internal class CreateDemoThingRequest : BaseCommand
910
{
10-
public CreateDemoThingRequest(string name, string description)
11+
public CreateDemoThingRequest(string name, string description, DemoThingType type)
1112
{
1213
Name = name;
1314
Description = description;
15+
Type = type;
1416
}
1517

1618
[Display(Name = nameof(SharedResource.DemoThing_Name), ResourceType = typeof(SharedResource))]
@@ -20,4 +22,8 @@ public CreateDemoThingRequest(string name, string description)
2022
[Display(Name = nameof(SharedResource.DemoThing_Description), ResourceType = typeof(SharedResource))]
2123
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
2224
public string Description { get; }
25+
26+
[Display(Name = nameof(SharedResource.DemoThing_Type), ResourceType = typeof(SharedResource))]
27+
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
28+
public DemoThingType Type { get; }
2329
}

src/1-Libraries/Application/UseCases/DemoThings/CreateDemoThing/CreateDemoThingUseCase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ namespace CanBeYours.Application.UseCases.DemoThings.CreateDemoThing;
1010
internal class CreateDemoThingUseCase : BaseCommandHandler, IRequestHandler<CreateDemoThingRequest, CommandResult>
1111
{
1212
private readonly IDemoThingRepository _demoThingRepository;
13+
private readonly ICurrentUser _currentUser;
1314

1415
public CreateDemoThingUseCase(
1516
IDemoThingRepository demoThingRepository,
1617
IRequestDispatcher requestDispatcher,
17-
ILogger<CreateDemoThingUseCase> logger
18+
ILogger<CreateDemoThingUseCase> logger,
19+
ICurrentUser currentUser
1820
)
1921
: base(requestDispatcher, logger)
2022
{
2123
_demoThingRepository = demoThingRepository;
24+
_currentUser = currentUser;
2225
}
2326

2427
public async Task<CommandResult> Handle(CreateDemoThingRequest request, CancellationToken cancellationToken)
2528
{
26-
var demoThing = DemoThing.Create(request.Name, request.Description);
29+
var demoThing = DemoThing.Create(request.Name, request.Description, request.Type, _currentUser.GetUserId());
2730

2831
await _demoThingRepository.AddAsync(demoThing);
2932

src/1-Libraries/Application/UseCases/DemoThings/UpdateDemoThing/UpdateDemoThingRequest.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Domain.DemoThings;
23
using CanBeYours.Core.Resources;
34
using CodeBlock.DevKit.Application.Commands;
45
using CodeBlock.DevKit.Core.Resources;
@@ -7,11 +8,12 @@ namespace CanBeYours.Application.UseCases.DemoThings.UpdateDemoThing;
78

89
internal class UpdateDemoThingRequest : BaseCommand
910
{
10-
public UpdateDemoThingRequest(string id, string name, string description)
11+
public UpdateDemoThingRequest(string id, string name, string description, DemoThingType type)
1112
{
1213
Id = id;
1314
Name = name;
1415
Description = description;
16+
Type = type;
1517
}
1618

1719
public string Id { get; }
@@ -23,4 +25,8 @@ public UpdateDemoThingRequest(string id, string name, string description)
2325
[Display(Name = nameof(SharedResource.DemoThing_Description), ResourceType = typeof(SharedResource))]
2426
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
2527
public string Description { get; }
26-
}
28+
29+
[Display(Name = nameof(SharedResource.DemoThing_Type), ResourceType = typeof(SharedResource))]
30+
[Required(ErrorMessageResourceName = nameof(CoreResource.Required), ErrorMessageResourceType = typeof(CoreResource))]
31+
public DemoThingType Type { get; }
32+
}

src/1-Libraries/Application/UseCases/DemoThings/UpdateDemoThing/UpdateDemoThingUseCase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public async Task<CommandResult> Handle(UpdateDemoThingRequest request, Cancella
3030

3131
var loadedVersion = demoThing.Version;
3232

33-
demoThing.Update(request.Name, request.Description);
33+
demoThing.Update(request.Name, request.Description, request.Type);
3434

3535
await _demoThingRepository.ConcurrencySafeUpdateAsync(demoThing, loadedVersion);
3636

src/1-Libraries/Core/Domain/DemoThings/DemoThing.cs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
using CodeBlock.DevKit.Core.Extensions;
1+
using System.ComponentModel.DataAnnotations;
2+
using CanBeYours.Core.Resources;
3+
using CodeBlock.DevKit.Core.Extensions;
24
using CodeBlock.DevKit.Domain.Entities;
35

46
namespace CanBeYours.Core.Domain.DemoThings;
57

68
public sealed class DemoThing : AggregateRoot
79
{
8-
private DemoThing(string name, string description)
10+
private DemoThing(string name, string description, DemoThingType type, string userId)
911
{
1012
Name = name;
1113
Description = description;
14+
Type = type;
15+
UserId = userId;
1216

1317
CheckPolicies();
1418

@@ -18,19 +22,22 @@ private DemoThing(string name, string description)
1822

1923
public string Name { get; private set; }
2024
public string Description { get; private set; }
25+
public DemoThingType Type { get; private set; }
26+
public string UserId { get; private set; }
2127

22-
public static DemoThing Create(string name, string description)
28+
public static DemoThing Create(string name, string description, DemoThingType type, string userId)
2329
{
24-
return new DemoThing(name, description);
30+
return new DemoThing(name, description, type, userId);
2531
}
2632

27-
public void Update(string name, string description)
33+
public void Update(string name, string description, DemoThingType type)
2834
{
29-
if (Name == name && Description == description)
35+
if (Name == name && Description == description && Type == type)
3036
return;
3137

3238
Name = name;
3339
Description = description;
40+
Type = type;
3441

3542
CheckPolicies();
3643

@@ -47,5 +54,20 @@ private void CheckPolicies()
4754

4855
if (Description.IsNullOrEmptyOrWhiteSpace())
4956
throw DemoThingDomainExceptions.DescriptionIsRequired();
57+
58+
if (UserId.IsNullOrEmptyOrWhiteSpace())
59+
throw DemoThingDomainExceptions.UserIdIsRequired();
5060
}
5161
}
62+
63+
public enum DemoThingType
64+
{
65+
[Display(Name = nameof(SharedResource.DemoThingType_DemoType1), ResourceType = typeof(SharedResource))]
66+
DemoType1 = 0,
67+
68+
[Display(Name = nameof(SharedResource.DemoThingType_DemoType2), ResourceType = typeof(SharedResource))]
69+
DemoType2 = 1,
70+
71+
[Display(Name = nameof(SharedResource.DemoThingType_DemoType3), ResourceType = typeof(SharedResource))]
72+
DemoType3 = 2,
73+
}

0 commit comments

Comments
 (0)