-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(groups): implemented group creation
- Loading branch information
Samuel Verdejo
committed
Nov 16, 2023
1 parent
1140e93
commit 814cfc4
Showing
36 changed files
with
609 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Application.Shared.Command; | ||
|
||
namespace Application; | ||
|
||
public sealed record CreateGroupCommand(Guid GroupId, string GroupName, Guid UserId) : ICommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Application.Shared.Command; | ||
using Domain; | ||
using Domain.Groups; | ||
|
||
namespace Application; | ||
|
||
public class CreateGroupCommandHandler : ICommandHandler<CreateGroupCommand> | ||
{ | ||
private readonly IGroupRepository _groupRepository; | ||
|
||
public CreateGroupCommandHandler(IGroupRepository groupRepository) | ||
{ | ||
_groupRepository = groupRepository; | ||
} | ||
|
||
public async Task Handle(CreateGroupCommand request, CancellationToken cancellationToken = default) | ||
{ | ||
var name = GroupName.Create(request.GroupName); | ||
var id = GroupId.Create(request.GroupId); | ||
var admin = UserId.Create(request.UserId); | ||
|
||
var group = Group.Create(id, name, admin); | ||
|
||
await _groupRepository.Add(group); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Domain.Shared.Base; | ||
|
||
namespace Domain.Groups; | ||
|
||
public class Group : AggregateRoot<Group> | ||
{ | ||
public GroupId Id { get; private set; } | ||
|
||
public GroupName Name { get; private set; } | ||
|
||
public UserId Admin { get; private set; } | ||
|
||
public HashSet<UserId> Members { get; private set; } = new(); | ||
|
||
public List<GroupRecords> Records { get; private set; } = new(); | ||
|
||
private Group() | ||
{ | ||
} | ||
|
||
protected Group(GroupId id, GroupName name, UserId admin) | ||
{ | ||
} | ||
|
||
public static Group Create(GroupId id, GroupName name, UserId admin) | ||
{ | ||
var group = new Group(id, name, admin); | ||
|
||
group.RecordEvent(new GroupCreatedEvent(id.Value, name.Value, admin.Value)); | ||
|
||
return group; | ||
} | ||
|
||
public void Join(UserId user) | ||
{ | ||
if (Members.Contains(user) is true) | ||
throw new AlreadyMemberException(user, this); | ||
|
||
Members.Add(user); | ||
RecordEvent(new MemberJoinedEvent(user.Value, this.Id.Value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Domain.Shared.Base; | ||
|
||
namespace Domain.Groups; | ||
|
||
public class AlreadyMemberException : DomainException | ||
{ | ||
public AlreadyMemberException(UserId user, Group group) : base($"The user with ID [{user.Value}] is alread member of group [{group.Name.Value} | {group.Id.Value}]") | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Domain.Shared.Base; | ||
|
||
namespace Domain.Groups; | ||
|
||
public sealed class GroupCreatedEvent(Guid GroupId, string GroupName, Guid AdminId) : IDomainEvent; | ||
Check warning on line 5 in Domain/Groups/Events/GroupCreatedEvent.cs GitHub Actions / Build project and run Architectural and Unit testing
Check warning on line 5 in Domain/Groups/Events/GroupCreatedEvent.cs GitHub Actions / Build project and run Architectural and Unit testing
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Domain.Shared.Base; | ||
|
||
namespace Domain.Groups; | ||
|
||
public sealed class MemberJoinedEvent(Guid MemberId, Guid GroupId) : IDomainEvent; | ||
Check warning on line 5 in Domain/Groups/Events/MemberJoinedEvent.cs GitHub Actions / Build project and run Architectural and Unit testing
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Domain.Shared.Base; | ||
|
||
namespace Domain.Groups; | ||
|
||
public interface IGroupRepository : IRepository<Group> | ||
{ | ||
public Task Delete(Group group); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Domain.Groups; | ||
|
||
public record GroupId(Guid Value) | ||
{ | ||
public static GroupId Create(Guid value) => new(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Domain.Groups; | ||
|
||
public record GroupName(string Value) | ||
{ | ||
public static GroupName Create(string name) => new(name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Domain.Groups; | ||
|
||
public class GroupRecords | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.