From 3fa6a2fff205de44729f38041ff85a79d3ef3383 Mon Sep 17 00:00:00 2001 From: bentran1vn Date: Fri, 18 Oct 2024 12:57:34 +0700 Subject: [PATCH] Fix CreateSkill for mentor --- .../APIs/MentorSkills/MentorSkillsApi.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/MBS_COMMAND.Presentation/APIs/MentorSkills/MentorSkillsApi.cs b/MBS_COMMAND.Presentation/APIs/MentorSkills/MentorSkillsApi.cs index 888512b..635466b 100644 --- a/MBS_COMMAND.Presentation/APIs/MentorSkills/MentorSkillsApi.cs +++ b/MBS_COMMAND.Presentation/APIs/MentorSkills/MentorSkillsApi.cs @@ -1,4 +1,7 @@ +using MBS_COMMAND.Application.Abstractions; using MBS_COMMAND.Presentation.Abstractions; +using MBS_COMMAND.Presentation.Constrants; +using Microsoft.AspNetCore.Authentication; namespace MBS_COMMAND.Presentation.APIs.MentorSkills; @@ -14,13 +17,20 @@ public void AddRoutes(IEndpointRouteBuilder app) .MapGroup(BaseUrl).HasApiVersion(1); gr1.MapPost("", CreateMentorSkills) + .RequireAuthorization(RoleNames.Mentor) .Accepts("multipart/form-data") .DisableAntiforgery(); } - public static async Task CreateMentorSkills(ISender sender, [FromForm] CommandV1.CreateMentorSkillsCommand command) + public static async Task CreateMentorSkills(ISender sender, [FromForm] CommandV1.CreateMentorSkillsCommand command, + HttpContext context, IJwtTokenService jwtTokenService) { - command.MentorId = new Guid("c74174e2-ce31-48fb-c3ba-08dce3193e4b"); + var accessToken = await context.GetTokenAsync("access_token"); + var (claimPrincipal, _) = jwtTokenService.GetPrincipalFromExpiredToken(accessToken!); + var userId = claimPrincipal.Claims.FirstOrDefault(c => c.Type == "UserId")!.Value; + + command.MentorId = new Guid(userId); + var result = await sender.Send(command); if (result.IsFailure)