Skip to content

Commit

Permalink
Merge pull request #30 from bentran1vn/Features/Group/SendMailAndAccept
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
PhucNghi176 authored Oct 17, 2024
2 parents a4a701a + 8561f76 commit 4245a15
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class CurrentUserService(IHttpContextAccessor httpContextAccessor) : ICur
private readonly ClaimsPrincipal? _claimsPrincipal = httpContextAccessor?.HttpContext?.User;

public string? UserId => _claimsPrincipal?.FindFirstValue("UserId");
public string? Role => _claimsPrincipal?.FindFirstValue(ClaimTypes.Role);

public string? UserName => _claimsPrincipal?.FindFirstValue(ClaimTypes.Name);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using MBS_COMMAND.Contract.Abstractions.Messages;
using MBS_COMMAND.Contract.Abstractions.Shared;
using MBS_COMMAND.Contract.Services.Feedbacks;
using MBS_COMMAND.Domain.Abstractions.Repositories;
using MBS_COMMAND.Domain.Entities;

namespace MBS_COMMAND.Application.UserCases.Commands.Feedbacks;

public class CreateFeedbackCommandHandler : ICommandHandler<Command.CreateFeedback>
{
private readonly IRepositoryBase<Feedback, Guid> _feedbackRepository;
private readonly ICurrentUserService _currentUserService;

public CreateFeedbackCommandHandler(IRepositoryBase<Feedback, Guid> feedbackRepository,
ICurrentUserService currentUserService)
{
_feedbackRepository = feedbackRepository;
_currentUserService = currentUserService;
}

public async Task<Result> Handle(Command.CreateFeedback request, CancellationToken cancellationToken)
{
var role = _currentUserService.Role == "2";
var feedback = new Feedback
{
Content = request.Content,
GroupId = request.GroupId,
Rating = request.Rating,
ScheduleId = request.ScheduleId,
IsMentor = role,
};
_feedbackRepository.Add(feedback);
return Result.Success();
}
}
8 changes: 8 additions & 0 deletions MBS_COMMAND.Contract/Services/Feedbacks/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using MBS_COMMAND.Contract.Abstractions.Messages;

namespace MBS_COMMAND.Contract.Services.Feedbacks;

public static class Command
{
public record CreateFeedback(Guid GroupId, string? Content,Guid ScheduleId, int Rating) : ICommand;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ public interface ICurrentUserService
{
string? UserId { get; }
string? UserName { get; }
string? Role { get; }
}
14 changes: 9 additions & 5 deletions MBS_COMMAND.Domain/Entities/Feedback.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
using MBS_COMMAND.Domain.Abstractions.Entities;
using System.ComponentModel.DataAnnotations;
using MBS_COMMAND.Domain.Abstractions.Entities;

namespace MBS_COMMAND.Domain.Entities;

public class Feedback : Entity<Guid>, IAuditableEntity
{

[MaxLength(100)]
public string? Content { get; set; }
[Range(1,5)]
public int Rating { get; set; }
public Guid? SlotId { get; set; }
public virtual Slot? Slot { get; set; }
public Guid? ScheduleId { get; set; }
public virtual Schedule? Schedule { get; set; }
public Guid? GroupId { get; set; }
public virtual Group? Group { get; set; }
public bool IsMentor { get; set; }
public DateTimeOffset CreatedOnUtc { get; set; }
public DateTimeOffset? ModifiedOnUtc { get; set; }
}
}
3 changes: 2 additions & 1 deletion MBS_COMMAND.Domain/Entities/Schedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ public class Schedule : Entity<Guid>, IAuditableEntity
{
public Guid MentorId { get; set; }
public virtual User? Mentor { get; set; }

public Guid SlotId { get; set; }
public virtual Slot? Slot { get; set; }
public Guid GroupId { get; set; }
public virtual Group? Group { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,15 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("uniqueidentifier");

b.Property<string>("Content")
.HasColumnType("nvarchar(max)");
.HasMaxLength(100)
.HasColumnType("nvarchar(100)");

b.Property<DateTimeOffset>("CreatedOnUtc")
.HasColumnType("datetimeoffset");

b.Property<Guid?>("GroupId")
.HasColumnType("uniqueidentifier");

b.Property<bool>("IsDeleted")
.HasColumnType("bit");

Expand All @@ -123,12 +127,14 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("Rating")
.HasColumnType("int");

b.Property<Guid?>("SlotId")
b.Property<Guid?>("ScheduleId")
.HasColumnType("uniqueidentifier");

b.HasKey("Id");

b.HasIndex("SlotId");
b.HasIndex("GroupId");

b.HasIndex("ScheduleId");

b.ToTable("Feedbacks");
});
Expand Down Expand Up @@ -279,6 +285,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<DateTimeOffset?>("ModifiedOnUtc")
.HasColumnType("datetimeoffset");

b.Property<Guid>("SlotId")
.HasColumnType("uniqueidentifier");

b.Property<TimeOnly>("StartTime")
.HasColumnType("time");

Expand All @@ -291,6 +300,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("MentorId");

b.HasIndex("SlotId");

b.HasIndex("SubjectId");

b.ToTable("Schedules");
Expand Down Expand Up @@ -565,11 +576,17 @@ protected override void BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("MBS_COMMAND.Domain.Entities.Feedback", b =>
{
b.HasOne("MBS_COMMAND.Domain.Entities.Slot", "Slot")
b.HasOne("MBS_COMMAND.Domain.Entities.Group", "Group")
.WithMany()
.HasForeignKey("SlotId");
.HasForeignKey("GroupId");

b.Navigation("Slot");
b.HasOne("MBS_COMMAND.Domain.Entities.Schedule", "Schedule")
.WithMany()
.HasForeignKey("ScheduleId");

b.Navigation("Group");

b.Navigation("Schedule");
});

modelBuilder.Entity("MBS_COMMAND.Domain.Entities.Group", b =>
Expand Down Expand Up @@ -645,6 +662,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("MBS_COMMAND.Domain.Entities.Slot", "Slot")
.WithMany()
.HasForeignKey("SlotId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();

b.HasOne("MBS_COMMAND.Domain.Entities.Subject", "Subject")
.WithMany()
.HasForeignKey("SubjectId")
Expand All @@ -655,6 +678,8 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.Navigation("Mentor");

b.Navigation("Slot");

b.Navigation("Subject");
});

Expand Down
21 changes: 21 additions & 0 deletions MBS_COMMAND.Presentation/APIs/Feedbacks/FeedbackApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MBS_COMMAND.Contract.Services.Feedbacks;
using MBS_COMMAND.Presentation.Abstractions;

namespace MBS_COMMAND.Presentation.APIs.Feedbacks;

public class FeedbackApi : ApiEndpoint,ICarterModule
{
private const string BaseUrl = "api/v{version:apiVersion}/feedbacks";
public void AddRoutes(IEndpointRouteBuilder app)
{
var gr1 = app.NewVersionedApi("Feedbacks").MapGroup(BaseUrl).HasApiVersion(1);
gr1.MapPost(string.Empty, CreateFeedback).RequireAuthorization();

}

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

0 comments on commit 4245a15

Please sign in to comment.