From b06b054809bbe2dbe2b46191f6ad5f31b1db9c9b Mon Sep 17 00:00:00 2001 From: Phuc Nghi Date: Thu, 10 Oct 2024 01:38:37 +0700 Subject: [PATCH] Enhance group and member management features Updated namespaces across multiple files to align with new project structure. Enhanced dependency injection and middleware by adding ICurrentUserService and HttpContextAccessor. Updated configuration settings in appsettings.Development.json. Added new command handlers and API endpoints for group member management. Modified Group and User entities to support member collections. Improved error handling by removing implicit conversion from Error to string. Implemented CurrentUserService to provide current user information. Cleaned up unused using directives and updated namespaces. --- .../Extensions/CurrentUserService.cs | 21 ++++++++ .../Extensions/ServiceCollectionExtensions.cs | 2 +- MBS-COMMAND.API/Program.cs | 4 +- MBS-COMMAND.API/appsettings.Development.json | 11 ++-- .../AddListMemberToGroupCommandHandler.cs | 46 ++++++++++++++++ .../Groups/AddMemberToGroupCommandHandler.cs | 27 ++++++++++ .../Groups/CreateGroupCommandHandler.cs | 6 ++- ...RemoveListMemberFromGroupCommandHandler.cs | 54 +++++++++++++++++++ .../RemoveMemberFromGroupCommandHandler.cs | 32 +++++++++++ .../Abstractions/Shared/Error.cs | 1 - .../Services/Groups/Command.cs | 6 ++- .../Repositories/ICurrentUserService.cs | 7 +++ MBS_COMMAND.Domain/Entities/Group.cs | 8 ++- .../Entities/Group_Student_Mapping.cs | 4 +- MBS_COMMAND.Domain/Entities/Project.cs | 4 -- MBS_COMMAND.Domain/Entities/Schedule.cs | 3 +- MBS_COMMAND.Domain/Entities/Slot.cs | 3 +- MBS_COMMAND.Domain/Entities/Transaction.cs | 3 +- MBS_COMMAND.Domain/Entities/User.cs | 12 +++-- .../ApplicationDbContext.cs | 1 - .../APIs/Groups/GroupApi.cs | 38 ++++++++++++- 21 files changed, 259 insertions(+), 34 deletions(-) create mode 100644 MBS-COMMAND.API/DependencyInjection/Extensions/CurrentUserService.cs create mode 100644 MBS_COMMAND.Application/UserCases/Commands/Groups/AddListMemberToGroupCommandHandler.cs create mode 100644 MBS_COMMAND.Application/UserCases/Commands/Groups/AddMemberToGroupCommandHandler.cs create mode 100644 MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveListMemberFromGroupCommandHandler.cs create mode 100644 MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveMemberFromGroupCommandHandler.cs create mode 100644 MBS_COMMAND.Domain/Abstractions/Repositories/ICurrentUserService.cs diff --git a/MBS-COMMAND.API/DependencyInjection/Extensions/CurrentUserService.cs b/MBS-COMMAND.API/DependencyInjection/Extensions/CurrentUserService.cs new file mode 100644 index 0000000..97f20ba --- /dev/null +++ b/MBS-COMMAND.API/DependencyInjection/Extensions/CurrentUserService.cs @@ -0,0 +1,21 @@ +using MBS_COMMAND.Domain.Abstractions.Repositories; +using Microsoft.AspNetCore.Authorization; +using System.Security.Claims; + +namespace MBS_COMMAND.API.DependencyInjection.Extensions; + +public class CurrentUserService : ICurrentUserService +{ + private readonly ClaimsPrincipal? _claimsPrincipal; + + public CurrentUserService(IHttpContextAccessor httpContextAccessor) + { + _claimsPrincipal = httpContextAccessor?.HttpContext?.User; + + } + + public string? UserId => _claimsPrincipal?.FindFirstValue(ClaimTypes.NameIdentifier); + + public string? UserName => _claimsPrincipal?.FindFirstValue(ClaimTypes.Name); + +} diff --git a/MBS-COMMAND.API/DependencyInjection/Extensions/ServiceCollectionExtensions.cs b/MBS-COMMAND.API/DependencyInjection/Extensions/ServiceCollectionExtensions.cs index 07eb856..9d5424c 100644 --- a/MBS-COMMAND.API/DependencyInjection/Extensions/ServiceCollectionExtensions.cs +++ b/MBS-COMMAND.API/DependencyInjection/Extensions/ServiceCollectionExtensions.cs @@ -1,4 +1,4 @@ -namespace Antree_Ecommerce_BE.API.DependencyInjection.Extensions; +namespace MBS_COMMAND.API.DependencyInjection.Extensions; public static class ServiceCollectionExtensions { diff --git a/MBS-COMMAND.API/Program.cs b/MBS-COMMAND.API/Program.cs index 2294206..5d6636b 100644 --- a/MBS-COMMAND.API/Program.cs +++ b/MBS-COMMAND.API/Program.cs @@ -1,8 +1,8 @@ -using Antree_Ecommerce_BE.API.DependencyInjection.Extensions; using Carter; using MBS_COMMAND.API.DependencyInjection.Extensions; using MBS_COMMAND.API.Middlewares; using MBS_COMMAND.Application.DependencyInjection.Extensions; +using MBS_COMMAND.Domain.Abstractions.Repositories; using MBS_COMMAND.Infrastucture.DependencyInjection.Extensions; using MBS_COMMAND.Persistence.DependencyInjection.Extensions; using MBS_COMMAND.Persistence.DependencyInjection.Options; @@ -64,6 +64,8 @@ // Add Middleware => Remember using middleware builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddHttpContextAccessor(); var app = builder.Build(); diff --git a/MBS-COMMAND.API/appsettings.Development.json b/MBS-COMMAND.API/appsettings.Development.json index 8a72d54..72c90e3 100644 --- a/MBS-COMMAND.API/appsettings.Development.json +++ b/MBS-COMMAND.API/appsettings.Development.json @@ -1,6 +1,7 @@ { "ConnectionStrings": { - "ConnectionStrings": "Server=103.162.14.116;Database=PRN_SUPER;Uid=sa;Pwd=MyStrongPassword123@;Trust Server Certificate=True;", + // "ConnectionStrings": "Server=103.162.14.116;Database=PRN_SUPER;Uid=sa;Pwd=MyStrongPassword123@;Trust Server Certificate=True;", + "ConnectionStrings": "Server=(local);Database=PRN_SUPER;Uid=sa;Pwd=12345;Trust Server Certificate=True;", "Redis": "103.162.14.116:6379,password=MyStrongPassword123@,abortConnect=false" }, "JwtOption": { @@ -10,11 +11,11 @@ "ExpireMin": 5 }, "MasstransitConfiguration": { - "Host": "103.162.14.116", - "VHost": "myHost", + "Host": "localhost", + "VHost": "phucnghi", "Port": 5672, - "UserName": "sa", - "Password": "MyStrongPassword123@" + "UserName": "guest", + "Password": "guest" }, "MessageBusOptions": { "retryLimit": 3, diff --git a/MBS_COMMAND.Application/UserCases/Commands/Groups/AddListMemberToGroupCommandHandler.cs b/MBS_COMMAND.Application/UserCases/Commands/Groups/AddListMemberToGroupCommandHandler.cs new file mode 100644 index 0000000..2ec289c --- /dev/null +++ b/MBS_COMMAND.Application/UserCases/Commands/Groups/AddListMemberToGroupCommandHandler.cs @@ -0,0 +1,46 @@ +using MBS_COMMAND.Contract.Abstractions.Messages; +using MBS_COMMAND.Contract.Abstractions.Shared; +using MBS_COMMAND.Contract.Services.Groups; +using MBS_COMMAND.Domain.Abstractions; +using MBS_COMMAND.Domain.Abstractions.Repositories; +using MBS_COMMAND.Domain.Entities; + +namespace MBS_COMMAND.Application.UserCases.Commands.Groups; + +public sealed class AddListMemberToGroupCommandHandler(IRepositoryBase userRepository, IRepositoryBase groupRepository, IUnitOfWork unitOfWork) : ICommandHandler +{ + public async Task Handle(Command.AddListMemberToGroup request, CancellationToken cancellationToken) + { + //validate all MemberId + Dictionary MembersNotFound = []; + var G = await groupRepository.FindSingleAsync(x => x.Id == request.GroupId, cancellationToken); + if (G == null) + return Result.Failure(new Error("404", "Group Not Found")); + foreach (var memberId in request.MemberId) + { + var user = await userRepository.FindByIdAsync(memberId); + if (user == null) + { + MembersNotFound.Add(memberId, "Member Not Found"); + } + else + { + G.Members!.Add(new Group_Student_Mapping { StudentId = user!.Id, GroupId = G.Id }); + groupRepository.Update(G); + try + { + await unitOfWork.SaveChangesAsync(cancellationToken); + } + catch + { + MembersNotFound.Add(memberId, "Member already joined group"); + } + } + + } + var returns = string.Join(", ", MembersNotFound.Select(x => $"MemberId: {x.Key}, Error: {x.Value}")); + + + return MembersNotFound.Count > 0 ? Result.Failure(new Error("422", returns)) : Result.Success(); + } +} diff --git a/MBS_COMMAND.Application/UserCases/Commands/Groups/AddMemberToGroupCommandHandler.cs b/MBS_COMMAND.Application/UserCases/Commands/Groups/AddMemberToGroupCommandHandler.cs new file mode 100644 index 0000000..f349db2 --- /dev/null +++ b/MBS_COMMAND.Application/UserCases/Commands/Groups/AddMemberToGroupCommandHandler.cs @@ -0,0 +1,27 @@ +using MBS_COMMAND.Contract.Abstractions.Messages; +using MBS_COMMAND.Contract.Abstractions.Shared; +using MBS_COMMAND.Contract.Services.Groups; +using MBS_COMMAND.Domain.Abstractions; +using MBS_COMMAND.Domain.Abstractions.Repositories; +using MBS_COMMAND.Domain.Entities; + +namespace MBS_COMMAND.Application.UserCases.Commands.Groups; + +public sealed class AddMemberToGroupCommandHandler(IRepositoryBase groupRepository, IRepositoryBase userRepository, IUnitOfWork unitOfWork) : ICommandHandler +{ + public async Task Handle(Command.AddMemberToGroup request, CancellationToken cancellationToken) + { + var U = await userRepository.FindByIdAsync(request.MemberId); + if (U == null) + return Result.Failure(new Error("404", "User Not Found")); + 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 }); + groupRepository.Update(G); + await unitOfWork.SaveChangesAsync(cancellationToken); + return Result.Success(); + } +} diff --git a/MBS_COMMAND.Application/UserCases/Commands/Groups/CreateGroupCommandHandler.cs b/MBS_COMMAND.Application/UserCases/Commands/Groups/CreateGroupCommandHandler.cs index 8ab507f..661529f 100644 --- a/MBS_COMMAND.Application/UserCases/Commands/Groups/CreateGroupCommandHandler.cs +++ b/MBS_COMMAND.Application/UserCases/Commands/Groups/CreateGroupCommandHandler.cs @@ -1,5 +1,4 @@ -using MBS_AUTHORIZATION.Domain.Entities; -using MBS_COMMAND.Contract.Abstractions.Messages; +using MBS_COMMAND.Contract.Abstractions.Messages; using MBS_COMMAND.Contract.Abstractions.Shared; using MBS_COMMAND.Contract.Services.Groups; using MBS_COMMAND.Domain.Abstractions.Repositories; @@ -16,6 +15,7 @@ public CreateGroupCommandHandler(IRepositoryBase repositoryBase, IR { _groupRepository = repositoryBase; _userRepository = userRepository; + } public async Task Handle(Command.CreateGroupCommand request, CancellationToken cancellationToken) @@ -30,7 +30,9 @@ public async Task Handle(Command.CreateGroupCommand request, Cancellatio Stack = request.Stacks, }; + G.Members!.Add(new Group_Student_Mapping { StudentId = M.Id, GroupId = G.Id }); _groupRepository.Add(G); + return Result.Success(); } } diff --git a/MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveListMemberFromGroupCommandHandler.cs b/MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveListMemberFromGroupCommandHandler.cs new file mode 100644 index 0000000..2a221f8 --- /dev/null +++ b/MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveListMemberFromGroupCommandHandler.cs @@ -0,0 +1,54 @@ +using MBS_COMMAND.Contract.Abstractions.Messages; +using MBS_COMMAND.Contract.Abstractions.Shared; +using MBS_COMMAND.Contract.Services.Groups; +using MBS_COMMAND.Domain.Abstractions; +using MBS_COMMAND.Domain.Abstractions.Repositories; +using MBS_COMMAND.Domain.Entities; + +namespace MBS_COMMAND.Application.UserCases.Commands.Groups; + +public sealed class RemoveListMemberFromGroupCommandHandler(IRepositoryBase groupRepository, IRepositoryBase userRepository, IUnitOfWork unitOfWork) : ICommandHandler +{ + public async Task Handle(Command.RemoveListMemberFromGroup request, CancellationToken cancellationToken) + { + Dictionary MembersNotFound = []; + var G = await groupRepository.FindSingleAsync(x => x.Id == request.GroupId, cancellationToken); + if (G == null) + return Result.Failure(new Error("404", "Group Not Found")); + if (request.MemberId.Contains((Guid)G.LeaderId)) + return Result.Failure(new Error("422", "Mentor cannot be removed from group")); + foreach (var memberId in request.MemberId) + { + var user = await userRepository.FindByIdAsync(memberId); + if (user == null) + { + MembersNotFound.Add(memberId, "Member Not Found"); + } + else + { + var member = G.Members!.FirstOrDefault(x => x.StudentId == user!.Id); + if (member == null) + { + MembersNotFound.Add(memberId, "Member Not Found in Group"); + } + else + { + G.Members!.Remove(member); + groupRepository.Update(G); + try + { + await unitOfWork.SaveChangesAsync(cancellationToken); + } + catch + { + MembersNotFound.Add(memberId, "Member already removed from group"); + } + } + } + + } + var returns = string.Join(", ", MembersNotFound.Select(x => $"MemberId: {x.Key}, Error: {x.Value}")); + return MembersNotFound.Count > 0 ? Result.Failure(new Error("422", returns)) : Result.Success(); + + } +} diff --git a/MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveMemberFromGroupCommandHandler.cs b/MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveMemberFromGroupCommandHandler.cs new file mode 100644 index 0000000..99e13d9 --- /dev/null +++ b/MBS_COMMAND.Application/UserCases/Commands/Groups/RemoveMemberFromGroupCommandHandler.cs @@ -0,0 +1,32 @@ +using MBS_COMMAND.Contract.Abstractions.Messages; +using MBS_COMMAND.Contract.Abstractions.Shared; +using MBS_COMMAND.Contract.Services.Groups; +using MBS_COMMAND.Domain.Abstractions; +using MBS_COMMAND.Domain.Abstractions.Repositories; +using MBS_COMMAND.Domain.Entities; + +namespace MBS_COMMAND.Application.UserCases.Commands.Groups; + +public sealed class RemoveMemberFromGroupCommandHandler(IRepositoryBase groupRepository, IRepositoryBase userRepository, IUnitOfWork unitOfWork, ICurrentUserService currentUserService) : ICommandHandler +{ + public async Task Handle(Command.RemoveMemberFromGroup request, CancellationToken cancellationToken) + { + var CurrentUserId = currentUserService.UserId; + + var U = await userRepository.FindByIdAsync(request.MemberId); + if (U == null) + return Result.Failure(new Error("404", "User Not Found")); + var G = await groupRepository.FindSingleAsync(x => x.Id == request.GroupId, cancellationToken); + if (G == null) + return Result.Failure(new Error("404", "Group Not Found")); + if (CurrentUserId != null && G.LeaderId.ToString() == CurrentUserId) + return Result.Failure(new Error("403", "Leader cannot be removed from group")); + var member = G.Members!.FirstOrDefault(x => x.StudentId == U.Id); + if (member == null) + return Result.Failure(new Error("422", "Member are not found in group")); + G.Members!.Remove(member); + groupRepository.Update(G); + await unitOfWork.SaveChangesAsync(cancellationToken); + return Result.Success(); + } +} diff --git a/MBS_COMMAND.Contract/Abstractions/Shared/Error.cs b/MBS_COMMAND.Contract/Abstractions/Shared/Error.cs index fcff035..9a180d6 100644 --- a/MBS_COMMAND.Contract/Abstractions/Shared/Error.cs +++ b/MBS_COMMAND.Contract/Abstractions/Shared/Error.cs @@ -12,7 +12,6 @@ public Error(string code, string message) } public string Code { get; } public string Message { get; } - public static implicit operator string(Error error) => error.Code; public static bool operator ==(Error? a, Error? b) diff --git a/MBS_COMMAND.Contract/Services/Groups/Command.cs b/MBS_COMMAND.Contract/Services/Groups/Command.cs index 62b9cb0..2b8cb89 100644 --- a/MBS_COMMAND.Contract/Services/Groups/Command.cs +++ b/MBS_COMMAND.Contract/Services/Groups/Command.cs @@ -4,5 +4,9 @@ namespace MBS_COMMAND.Contract.Services.Groups; public static class Command { - public record CreateGroupCommand(string Name,Guid MentorId,string Stacks) : ICommand; + public record CreateGroupCommand(string Name, Guid MentorId, string Stacks) : ICommand; + public record AddListMemberToGroup(Guid GroupId, List MemberId) : ICommand; + public record RemoveListMemberFromGroup(Guid GroupId, List MemberId) : ICommand; + public record AddMemberToGroup(Guid GroupId, Guid MemberId) : ICommand; + public record RemoveMemberFromGroup(Guid GroupId, Guid MemberId) : ICommand; } diff --git a/MBS_COMMAND.Domain/Abstractions/Repositories/ICurrentUserService.cs b/MBS_COMMAND.Domain/Abstractions/Repositories/ICurrentUserService.cs new file mode 100644 index 0000000..4233de1 --- /dev/null +++ b/MBS_COMMAND.Domain/Abstractions/Repositories/ICurrentUserService.cs @@ -0,0 +1,7 @@ +namespace MBS_COMMAND.Domain.Abstractions.Repositories; + +public interface ICurrentUserService +{ + string? UserId { get; } + string? UserName { get; } +} diff --git a/MBS_COMMAND.Domain/Entities/Group.cs b/MBS_COMMAND.Domain/Entities/Group.cs index a5408d9..af1a0ae 100644 --- a/MBS_COMMAND.Domain/Entities/Group.cs +++ b/MBS_COMMAND.Domain/Entities/Group.cs @@ -1,6 +1,4 @@ -using MBS_AUTHORIZATION.Domain.Entities; -using MBS_COMMAND.Domain.Abstractions.Aggregates; -using MBS_COMMAND.Domain.Abstractions.Entities; +using MBS_COMMAND.Domain.Abstractions.Entities; namespace MBS_COMMAND.Domain.Entities; @@ -9,7 +7,6 @@ public class Group : Entity, IAuditableEntity public string Name { get; set; } public Guid? MentorId { get; set; } public virtual User? Mentor { get; set; } - public Guid? LeaderId { get; set; } public virtual User? Leader { get; set; } public string Stack { get; set; } @@ -17,7 +14,8 @@ public class Group : Entity, IAuditableEntity public virtual Project? Project { get; set; } public DateTimeOffset CreatedOnUtc { get; set; } public DateTimeOffset? ModifiedOnUtc { get; set; } - + public virtual ICollection? Members { get; set; } = []; + } diff --git a/MBS_COMMAND.Domain/Entities/Group_Student_Mapping.cs b/MBS_COMMAND.Domain/Entities/Group_Student_Mapping.cs index 7c91690..1d3ef5b 100644 --- a/MBS_COMMAND.Domain/Entities/Group_Student_Mapping.cs +++ b/MBS_COMMAND.Domain/Entities/Group_Student_Mapping.cs @@ -1,6 +1,4 @@ -using MBS_AUTHORIZATION.Domain.Entities; - -namespace MBS_COMMAND.Domain.Entities; +namespace MBS_COMMAND.Domain.Entities; public class Group_Student_Mapping { diff --git a/MBS_COMMAND.Domain/Entities/Project.cs b/MBS_COMMAND.Domain/Entities/Project.cs index 1739adb..2c4800f 100644 --- a/MBS_COMMAND.Domain/Entities/Project.cs +++ b/MBS_COMMAND.Domain/Entities/Project.cs @@ -6,10 +6,6 @@ public class Project : Entity, IAuditableEntity { public string Name { get ; set ; } public string Description { get ; set ; } - - - - public DateTimeOffset CreatedOnUtc { get ; set ; } public DateTimeOffset? ModifiedOnUtc { get ; set ; } } diff --git a/MBS_COMMAND.Domain/Entities/Schedule.cs b/MBS_COMMAND.Domain/Entities/Schedule.cs index 8d2f00b..be1bd1f 100644 --- a/MBS_COMMAND.Domain/Entities/Schedule.cs +++ b/MBS_COMMAND.Domain/Entities/Schedule.cs @@ -1,5 +1,4 @@ -using MBS_AUTHORIZATION.Domain.Entities; -using MBS_COMMAND.Domain.Abstractions.Entities; +using MBS_COMMAND.Domain.Abstractions.Entities; namespace MBS_COMMAND.Domain.Entities; diff --git a/MBS_COMMAND.Domain/Entities/Slot.cs b/MBS_COMMAND.Domain/Entities/Slot.cs index 93a22eb..884b7a0 100644 --- a/MBS_COMMAND.Domain/Entities/Slot.cs +++ b/MBS_COMMAND.Domain/Entities/Slot.cs @@ -1,5 +1,4 @@ -using MBS_AUTHORIZATION.Domain.Entities; -using MBS_COMMAND.Domain.Abstractions.Entities; +using MBS_COMMAND.Domain.Abstractions.Entities; namespace MBS_COMMAND.Domain.Entities; diff --git a/MBS_COMMAND.Domain/Entities/Transaction.cs b/MBS_COMMAND.Domain/Entities/Transaction.cs index 684c41b..6e3f45d 100644 --- a/MBS_COMMAND.Domain/Entities/Transaction.cs +++ b/MBS_COMMAND.Domain/Entities/Transaction.cs @@ -1,5 +1,4 @@ -using MBS_AUTHORIZATION.Domain.Entities; -using MBS_COMMAND.Domain.Abstractions.Entities; +using MBS_COMMAND.Domain.Abstractions.Entities; namespace MBS_COMMAND.Domain.Entities; diff --git a/MBS_COMMAND.Domain/Entities/User.cs b/MBS_COMMAND.Domain/Entities/User.cs index 52e40fc..88ec02e 100644 --- a/MBS_COMMAND.Domain/Entities/User.cs +++ b/MBS_COMMAND.Domain/Entities/User.cs @@ -1,8 +1,9 @@ -using MBS_COMMAND.Domain.Abstractions.Entities; +using MBS_COMMAND.Domain.Abstractions.Aggregates; +using MBS_COMMAND.Domain.Abstractions.Entities; -namespace MBS_AUTHORIZATION.Domain.Entities; +namespace MBS_COMMAND.Domain.Entities; -public class User : Entity, IAuditableEntity +public class User : AggregateRoot, IAuditableEntity { public string Email { get; set; } public string? FullName { get; set; } @@ -16,4 +17,9 @@ public class User : Entity, IAuditableEntity public virtual User? Mentor { get; set; } public DateTimeOffset CreatedOnUtc { get; set; } public DateTimeOffset? ModifiedOnUtc { get; set; } + + public virtual ICollection? Groups { get; set; } = []; + + + } \ No newline at end of file diff --git a/MBS_COMMAND.Persistence/ApplicationDbContext.cs b/MBS_COMMAND.Persistence/ApplicationDbContext.cs index 33f9ad6..bd28761 100644 --- a/MBS_COMMAND.Persistence/ApplicationDbContext.cs +++ b/MBS_COMMAND.Persistence/ApplicationDbContext.cs @@ -1,4 +1,3 @@ -using MBS_AUTHORIZATION.Domain.Entities; using MBS_COMMAND.Domain.Entities; using Microsoft.EntityFrameworkCore; diff --git a/MBS_COMMAND.Presentation/APIs/Groups/GroupApi.cs b/MBS_COMMAND.Presentation/APIs/Groups/GroupApi.cs index 3381217..e950c91 100644 --- a/MBS_COMMAND.Presentation/APIs/Groups/GroupApi.cs +++ b/MBS_COMMAND.Presentation/APIs/Groups/GroupApi.cs @@ -16,7 +16,11 @@ public void AddRoutes(IEndpointRouteBuilder app) { var gr1 = app.NewVersionedApi("Groups") .MapGroup(BaseUrl).HasApiVersion(1); - gr1.MapPost("", CreateGroup); + gr1.MapPost(string.Empty, CreateGroup); + gr1.MapPost("add-list-member", AddListMemberToGroup).WithSummary("add many at the time"); + gr1.MapDelete("remove-list-member", RemoveListMemberFromGroup).WithSummary("remove many at the time"); + gr1.MapPost("add-member", AddMemberToGroup); + gr1.MapDelete("remove-member", RemoveMemberFromGroup); } @@ -28,4 +32,36 @@ public static async Task CreateGroup(ISender sender, [FromBody] Command return Results.Ok(result); } + public static async Task AddListMemberToGroup(ISender sender, [FromBody] Command.AddListMemberToGroup request) + { + var result = await sender.Send(request); + if (result.IsFailure) + return HandlerFailure(result); + + return Results.Ok(result); + } + public static async Task RemoveListMemberFromGroup(ISender sender, [FromBody] Command.RemoveListMemberFromGroup request) + { + var result = await sender.Send(request); + if (result.IsFailure) + return HandlerFailure(result); + + return Results.Ok(result); + } + public static async Task AddMemberToGroup(ISender sender, [FromBody] Command.AddMemberToGroup request) + { + var result = await sender.Send(request); + if (result.IsFailure) + return HandlerFailure(result); + + return Results.Ok(result); + } + public static async Task RemoveMemberFromGroup(ISender sender, [FromBody] Command.RemoveMemberFromGroup request) + { + var result = await sender.Send(request); + if (result.IsFailure) + return HandlerFailure(result); + + return Results.Ok(result); + } }