Search.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using MediatR;
  2. using System.Security.Claims;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.Forum.Post;
  6. internal sealed class Search : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapGet("api/forum/posts", async (
  11. ISender sender,
  12. ClaimsPrincipal user,
  13. CancellationToken ct,
  14. int? boardID = null,
  15. int? boardPrefixID = null,
  16. int? search = null,
  17. string? keyword = null,
  18. string? startAt = null,
  19. string? endAt = null,
  20. int? sort = null,
  21. bool? isNotice = null,
  22. bool? isSecret = null,
  23. bool? isReply = null,
  24. bool? isDeleted = null,
  25. int page = 1,
  26. ushort perPage = 20
  27. ) =>
  28. {
  29. var memberID = user.GetMemberID();
  30. var query = new Application.Features.Api.Forum.Post.Search.Query(
  31. boardID,
  32. boardPrefixID,
  33. search,
  34. keyword,
  35. startAt,
  36. endAt,
  37. sort,
  38. isNotice,
  39. isSecret,
  40. isReply,
  41. isDeleted,
  42. page,
  43. perPage,
  44. memberID
  45. );
  46. return ApiResponse.Ok(await sender.Send(query, ct));
  47. })
  48. .WithTags("Forum")
  49. .AllowAnonymous();
  50. }
  51. }