| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using Application.Abstractions.Messaging;
- using Microsoft.AspNetCore.Mvc;
- using System.Security.Claims;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.Feed;
- internal sealed class Create : IEndpoint
- {
- public sealed class Request
- {
- public string Content { get; set; } = "";
- public List<string>? Tags { get; set; }
- public List<string>? Medias { get; set; }
- }
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapPost("api/feed", async (
- ClaimsPrincipal user,
- [FromForm] Request request,
- HttpRequest httpRequest,
- ISender sender,
- CancellationToken ct
- ) => {
- var memberID = user.GetMemberID();
- if (memberID is null)
- {
- return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
- }
- var images = httpRequest.Form.Files.GetFiles("images").ToList();
- var command = new Application.Features.Api.Feed.Create.Command(
- memberID.Value,
- request.Content,
- request.Tags,
- images.Count > 0 ? images : null,
- request.Medias
- );
- var result = await sender.Send(command, ct);
- return result.Match(
- data => ApiResponse.Created(new { ID = data.PostID }),
- CustomResults.Problem
- );
- })
- .WithTags("Feed")
- .RequireAuthorization()
- .DisableAntiforgery();
- }
- }
|