Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
PhucNghi176 committed Oct 24, 2024
1 parent 62dfde9 commit 428e46e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task<Result> Handle(Command.AddMemberToGroup request, CancellationT
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 });
var domain = configuration["Domain"];
await mailService.SendMail(new MailContent
{
Expand All @@ -41,10 +40,6 @@ Accept Invitation
</a>
"
});


//send mail to user

return Result.Success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ namespace MBS_COMMAND.Application.UserCases.Commands.Slots;
public sealed class CreateSlotCommandHandler(
IRepositoryBase<Slot, Guid> slotRepository,
IRepositoryBase<User, Guid> userRepository,
ICurrentUserService currentUserService,
IRepositoryBase<Semester, Guid> semesterRepository,
IUnitOfWork unitOfWork)
: ICommandHandler<Command.CreateSlot>
{
public async Task<Result> Handle(Command.CreateSlot request, CancellationToken cancellationToken)
{
// Parallel fetch of mentor and current semester
var mentor = await userRepository.FindByIdAsync(request.MentorId, cancellationToken);
var mentor = await userRepository.FindByIdAsync(Guid.Parse(currentUserService.UserId!), cancellationToken);
if (mentor == null)
return Result.Failure(new Error("404", "User Not Found"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task<Result> Handle(Command.GenerateSlotForSemester request, Cancel

// Get all mentors in parallel with first week slots
var mentors = await userRepository
.FindAll(x => x.Role == 2)
.FindAll(x => x.Role == 1)
.AsTracking()
.ToListAsync(cancellationToken);

Expand Down
7 changes: 4 additions & 3 deletions MBS_COMMAND.Contract/Services/Slots/Command.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using MBS_COMMAND.Contract.Abstractions.Messages;

namespace MBS_COMMAND.Contract.Services.Slots;
public static class Command
{
public record CreateSlot(Guid MentorId, List<SlotModel> SlotModels) : ICommand;
public record CreateSlot(List<SlotModel> SlotModels) : ICommand;

public record GenerateSlotForSemester: ICommand;
}
public record GenerateSlotForSemester : ICommand;
}
6 changes: 5 additions & 1 deletion MBS_COMMAND.Domain/Entities/Schedule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MBS_COMMAND.Domain.Abstractions.Entities;
using System.ComponentModel.DataAnnotations;
using MBS_COMMAND.Domain.Abstractions.Entities;

namespace MBS_COMMAND.Domain.Entities;

Expand All @@ -14,6 +15,9 @@ public class Schedule : Entity<Guid>, IAuditableEntity
public TimeOnly EndTime { get; set; }
public DateOnly Date { get; set; }
public Guid SubjectId { get; set; }

public string? Description { get; set; }

public virtual Subject? Subject { get; set; }
public DateTimeOffset CreatedOnUtc { get ; set ; }
public DateTimeOffset? ModifiedOnUtc { get ; set ; }
Expand Down
2 changes: 1 addition & 1 deletion MBS_COMMAND.Domain/Entities/Semester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace MBS_COMMAND.Domain.Entities;

public class Semester : Entity<Guid>, IAuditableEntity
public class Semester : Entity<Guid>, IAuditableEntity
{
public string Name { get; set; }
public DateOnly From { get; set; }
Expand Down
7 changes: 2 additions & 5 deletions MBS_COMMAND.Presentation/APIs/Groups/GroupApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void AddRoutes(IEndpointRouteBuilder app)
gr1.MapPost(string.Empty, CreateGroup).RequireAuthorization();
gr1.MapPost("member", AddMemberToGroup);
gr1.MapDelete("member", RemoveMemberFromGroup);
gr1.MapPut("change-leader", ChangeLeader).WithSummary("must login in order to use this api");
gr1.MapPut("member", ChangeLeader).WithSummary("must login in order to use this api");
gr1.MapPut(string.Empty, UpdateGroup);
gr1.MapGet("accept-invitation/{groupId}/{memberId}", AcceptGroupInvitation);
gr1.MapPost("mentor", AddMentorToGroup);
Expand All @@ -30,10 +30,7 @@ private static async Task<IResult> AcceptGroupInvitation(ISender sender, string
private static async Task<IResult> UpdateGroup(ISender sender, [FromBody] Command.UpdateGroup updateGroup)
{
var result = await sender.Send(updateGroup);
if (result.IsFailure)
return HandlerFailure(result);

return Results.Ok(result);
return result.IsFailure ? HandlerFailure(result) : Results.Ok(result);
}

private static async Task<IResult> ChangeLeader(ISender sender, [FromBody] Command.ChangeLeader request)
Expand Down
11 changes: 7 additions & 4 deletions MBS_COMMAND.Presentation/APIs/Slots/SlotApi.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
using MBS_COMMAND.Contract.Services.Slots;
using MBS_COMMAND.Presentation.Abstractions;

namespace MBS_COMMAND.Presentation.APIs.Slots;
public class SlotApi : ApiEndpoint,ICarterModule
public class SlotApi : ApiEndpoint, ICarterModule
{
private const string BaseUrl = "/api/v{version:apiVersion}/slots";

public void AddRoutes(IEndpointRouteBuilder app)
{
var gr1 = app.NewVersionedApi("Slots").MapGroup(BaseUrl).HasApiVersion(1);
gr1.MapPost(string.Empty, CreateSlot).WithSummary("mm/dd/yyyy");
gr1.MapPost(string.Empty, CreateSlot).WithSummary("mm/dd/yyyy").RequireAuthorization();
gr1.MapPost("generate", GenerateSlotForSemester);
}

private static async Task<IResult> CreateSlot(ISender sender,[FromBody] Command.CreateSlot command)
private static async Task<IResult> CreateSlot(ISender sender, [FromBody] Command.CreateSlot command)
{
var result = await sender.Send(command);
return result.IsFailure ? HandlerFailure(result) : Results.Ok(result);
}

private static async Task<IResult> GenerateSlotForSemester(ISender sender)
{
var result = await sender.Send(new Command.GenerateSlotForSemester());
return result.IsFailure ? HandlerFailure(result) : Results.Ok(result);
}
}
}

0 comments on commit 428e46e

Please sign in to comment.