-
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 #30 from bentran1vn/Features/Group/SendMailAndAccept
Update
- Loading branch information
Showing
8 changed files
with
108 additions
and
12 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
35 changes: 35 additions & 0 deletions
35
MBS_COMMAND.Application/UserCases/Commands/Feedbacks/CreateFeedbackCommandHandler.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,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(); | ||
} | ||
} |
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,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; | ||
} |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ public interface ICurrentUserService | |
{ | ||
string? UserId { get; } | ||
string? UserName { get; } | ||
string? Role { get; } | ||
} |
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,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; } | ||
} | ||
} |
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
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); | ||
} | ||
} |