Skip to content

Commit

Permalink
Fix CreateSkill for mentor
Browse files Browse the repository at this point in the history
  • Loading branch information
bentran1vn committed Oct 18, 2024
1 parent f84cfe7 commit 3fa6a2f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions MBS_COMMAND.Presentation/APIs/MentorSkills/MentorSkillsApi.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -14,13 +17,20 @@ public void AddRoutes(IEndpointRouteBuilder app)
.MapGroup(BaseUrl).HasApiVersion(1);

gr1.MapPost("", CreateMentorSkills)
.RequireAuthorization(RoleNames.Mentor)
.Accepts<CommandV1.CreateMentorSkillsCommand>("multipart/form-data")
.DisableAntiforgery();
}

public static async Task<IResult> CreateMentorSkills(ISender sender, [FromForm] CommandV1.CreateMentorSkillsCommand command)
public static async Task<IResult> 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)
Expand Down

0 comments on commit 3fa6a2f

Please sign in to comment.