-
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(authentication,groups): configured authentication & added groups…
… creation
- Loading branch information
Samuel Verdejo
committed
Nov 17, 2023
1 parent
814cfc4
commit 7781dcf
Showing
31 changed files
with
936 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
using Application.Shared.Command; | ||
|
||
namespace Application; | ||
namespace Application.Groups; | ||
|
||
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
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,30 @@ | ||
using Application.Shared.Command; | ||
using Domain; | ||
using Domain.Groups; | ||
using MediatR; | ||
|
||
namespace Application; | ||
|
||
public class JoinGroupCommandHandler : ICommandHandler<JoinGroupCommand> | ||
{ | ||
private readonly IGroupRepository _groupRepository; | ||
|
||
private readonly ISender sender; | ||
|
||
public JoinGroupCommandHandler(IGroupRepository groupRepository) | ||
Check warning on line 14 in Application/Groups/Handlers/JoinGroupCommandHandler.cs GitHub Actions / Build project and run Architectural and Unit testing
|
||
{ | ||
_groupRepository = groupRepository; | ||
} | ||
|
||
public async Task Handle(JoinGroupCommand request, CancellationToken cancellationToken = default) | ||
{ | ||
var groupId = GroupId.Create(request.GroupId); | ||
var memberId = UserId.Create(request.NewMember); | ||
|
||
var criteria = new GroupByIdCriteria(groupId); | ||
|
||
var group = await _groupRepository.MatchFirst(criteria); | ||
|
||
group.Join(memberId); | ||
} | ||
} |
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,18 @@ | ||
using Application.Shared.Command; | ||
|
||
namespace Application; | ||
|
||
public sealed record JoinGroupCommand : ICommand | ||
{ | ||
public JoinGroupCommand(Guid newMember, Guid groupId) | ||
{ | ||
NewMember = newMember; | ||
GroupId = groupId; | ||
} | ||
|
||
public Guid NewMember { get; set; } | ||
|
||
public Guid GroupId { get; set; } | ||
|
||
|
||
} |
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,11 @@ | ||
| ||
using Application.Shared.Command; | ||
|
||
namespace Application; | ||
|
||
public sealed record CreateUserCommand : ICommand | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public string Mail { get; set; } | ||
Check warning on line 10 in Application/Users/Commands/CreateUserCommand.cs GitHub Actions / Build project and run Architectural and Unit testing
|
||
} |
24 changes: 24 additions & 0 deletions
24
Application/Users/Commands/Handlers/CreateUserCommandHandler.cs
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,24 @@ | ||
using Application.Shared.Command; | ||
using Domain; | ||
|
||
namespace Application; | ||
|
||
public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand> | ||
{ | ||
private readonly IUserRepository _userRepository; | ||
|
||
public CreateUserCommandHandler(IUserRepository userRepository) | ||
{ | ||
_userRepository = userRepository; | ||
} | ||
|
||
public async Task Handle(CreateUserCommand request, CancellationToken cancellationToken) | ||
{ | ||
var id = UserId.Create(request.Id); | ||
var mail = UserMail.Create(request.Mail); | ||
|
||
var user = User.Create(id, mail); | ||
|
||
await _userRepository.Add(user); | ||
} | ||
} |
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,11 @@ | ||
using System.Linq.Expressions; | ||
using Domain.Shared.Base; | ||
|
||
namespace Domain.Groups; | ||
|
||
public class GroupByIdCriteria : Criteria<Group> | ||
{ | ||
public GroupByIdCriteria(GroupId groupId) : base(group => group.Id == groupId) | ||
{ | ||
} | ||
} |
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 @@ | ||
namespace Domain.Groups; | ||
|
||
public class GroupRecord | ||
{ | ||
public Decimal Amount { get; private set; } | ||
|
||
public UserId Creator { get; private set; } | ||
Check warning on line 7 in Domain/Groups/ValueObjects/GroupRecord.cs GitHub Actions / Build project and run Architectural and Unit testing
|
||
|
||
public List<RecordPercentage> Percentages { get; private set; } | ||
Check warning on line 9 in Domain/Groups/ValueObjects/GroupRecord.cs GitHub Actions / Build project and run Architectural and Unit testing
|
||
} |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
namespace Domain; | ||
|
||
public class RecordPercentage | ||
{ | ||
public UserId Member { get; set; } | ||
|
||
public Decimal Percentage { get; set; } | ||
|
||
private RecordPercentage() | ||
{ | ||
} | ||
|
||
private RecordPercentage(UserId member, Decimal percentage) | ||
{ | ||
Member = member; | ||
Percentage = percentage; | ||
} | ||
|
||
public static RecordPercentage Create(UserId member, Decimal percentage) | ||
{ | ||
if (percentage < 0 || percentage > 1) | ||
throw new ArgumentOutOfRangeException(nameof(percentage)); | ||
|
||
return new RecordPercentage(member, percentage); | ||
} | ||
} |
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
71 changes: 71 additions & 0 deletions
71
Persistance/Entities/Groups/Configuration/GroupConfiguration.cs
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,71 @@ | ||
using Domain; | ||
using Domain.Groups; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Persistance; | ||
|
||
public class GroupConfiguration : IEntityTypeConfiguration<Group> | ||
{ | ||
public void Configure(EntityTypeBuilder<Group> builder) | ||
{ | ||
builder.HasKey(group => group.Id); | ||
builder.HasIndex(group => group.Id); | ||
builder.Property(group => group.Id) | ||
.HasConversion( | ||
src => src.Value, | ||
raw => GroupId.Create(raw)); | ||
|
||
builder.Property(group => group.Admin) | ||
.HasConversion( | ||
src => src.Value, | ||
raw => UserId.Create(raw)); | ||
|
||
builder.Property(group => group.Name) | ||
.HasMaxLength(50) | ||
.HasConversion( | ||
src => src.Value, | ||
raw => GroupName.Create(raw)); | ||
|
||
builder.OwnsMany( | ||
group => group.Members, | ||
membersBuilder => { | ||
// TODO: review how to change this name from Value to MemberId | ||
membersBuilder.HasKey(memberId => memberId.Value); | ||
membersBuilder.ToTable("GroupMembers"); | ||
}); | ||
|
||
builder.OwnsMany(group => group.Records, | ||
recordBuilder => { | ||
var identityProperty = "GroupRecordId"; | ||
recordBuilder.Property<Guid>(identityProperty) | ||
.ValueGeneratedOnAdd(); | ||
recordBuilder.HasKey(identityProperty); | ||
recordBuilder.Property(record => record.Creator) | ||
.HasConversion( | ||
src => src.Value, | ||
raw => UserId.Create(raw)); | ||
recordBuilder.Property(record => record.Amount); | ||
recordBuilder.OwnsMany(record => record.Percentages, | ||
percentagesBuilder => { | ||
var percentageIdentityProperty = "MemberPercentageId"; | ||
percentagesBuilder.Property<Guid>(percentageIdentityProperty) | ||
.ValueGeneratedOnAdd(); | ||
percentagesBuilder.HasKey(percentageIdentityProperty); | ||
percentagesBuilder.Property(percentage => percentage.Member) | ||
.HasConversion( | ||
src => src.Value, | ||
raw => UserId.Create(raw)); | ||
percentagesBuilder.Property(percentage => percentage.Percentage); | ||
}); | ||
}); | ||
} | ||
} |
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,17 @@ | ||
using Domain.Groups; | ||
using Persistance.Shared; | ||
|
||
namespace Persistance; | ||
|
||
internal class GroupRepository : AbstractRepository<Group>, IGroupRepository | ||
{ | ||
public GroupRepository(ApplicationDbContext dbContext) : base(dbContext) | ||
{ | ||
} | ||
|
||
public Task Delete(Group group) | ||
{ | ||
_context.Set<Group>().Remove(group); | ||
return Task.CompletedTask; | ||
} | ||
} |
Oops, something went wrong.