-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from bentran1vn/Features/Group/SendMailAndAccept
Refactor settings, handlers, and add new command
- Loading branch information
Showing
10 changed files
with
866 additions
and
37 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 |
---|---|---|
|
@@ -69,5 +69,6 @@ | |
"WithThreadId" | ||
] | ||
}, | ||
"AllowedHosts": "*" | ||
"AllowedHosts": "*", | ||
"Domain" : "localhost:3000" | ||
} |
36 changes: 36 additions & 0 deletions
36
MBS_COMMAND.Application/UserCases/Commands/Groups/AcceptGroupInvitationCommandHandler.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,36 @@ | ||
using MBS_COMMAND.Contract.Abstractions.Messages; | ||
using MBS_COMMAND.Contract.Abstractions.Shared; | ||
using MBS_COMMAND.Domain.Abstractions; | ||
using MBS_COMMAND.Domain.Abstractions.Repositories; | ||
using MBS_COMMAND.Domain.Entities; | ||
using MBS_CONTRACT.SHARE.Services.Groups; | ||
using Command = MBS_COMMAND.Contract.Services.Groups.Command; | ||
|
||
namespace MBS_COMMAND.Application.UserCases.Commands.Groups; | ||
|
||
public class AcceptGroupInvitationCommandHandler( | ||
IRepositoryBase<User, Guid> userRepository, | ||
IRepositoryBase<Group, Guid> groupRepository, | ||
IUnitOfWork unitOfWork) | ||
: ICommandHandler<Command.AcceptGroupInvitation> | ||
{ | ||
public async Task<Result> Handle(Command.AcceptGroupInvitation request, CancellationToken cancellationToken) | ||
{ | ||
var u = await userRepository.FindByIdAsync(request.MemberId, cancellationToken); | ||
if (u == null) | ||
return Result.Failure(new Error("404", "User Not Found")); | ||
if (u.Status == 2) | ||
{ | ||
return Result.Failure(new Error("403", "User is blocked")); | ||
} | ||
|
||
var g = await groupRepository.FindSingleAsync(x => x.Id == request.GroupId, cancellationToken); | ||
if (g == null) | ||
return Result.Failure(new Error("404", "Group Not Found")); | ||
if (g.Members!.Any(x => x.StudentId == u.Id)) | ||
return Result.Failure(new Error("422", "Member already joined group")); | ||
g.Members!.Add(new Group_Student_Mapping { StudentId = u.Id, GroupId = g.Id }); | ||
unitOfWork.SaveChangesAsync(cancellationToken); | ||
return Result.Success("Member added to 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
Oops, something went wrong.