hopefully not a horribly foolish refactoring
This commit is contained in:
parent
59d660165f
commit
1ecaf64dea
82 changed files with 782 additions and 398 deletions
|
@ -1,6 +1,8 @@
|
|||
using Femto.Api.Controllers.Posts.Dto;
|
||||
using Femto.Modules.Blog.Domain.Posts.Commands.CreatePost;
|
||||
using Femto.Modules.Blog.Domain.Posts.Commands.GetPosts;
|
||||
using Femto.Modules.Blog;
|
||||
using Femto.Modules.Blog.Application;
|
||||
using Femto.Modules.Blog.Application.Commands.CreatePost;
|
||||
using Femto.Modules.Blog.Application.Queries.GetPosts;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -8,7 +10,7 @@ namespace Femto.Api.Controllers.Posts;
|
|||
|
||||
[ApiController]
|
||||
[Route("posts")]
|
||||
public class PostsController(IMediator mediator) : ControllerBase
|
||||
public class PostsController(IBlogModule blogModule) : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<GetAllPublicPostsResponse>> GetAllPublicPosts(
|
||||
|
@ -16,11 +18,13 @@ public class PostsController(IMediator mediator) : ControllerBase
|
|||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var res = await mediator.Send(
|
||||
var res = await blogModule.PostQuery(
|
||||
new GetPostsQuery
|
||||
{
|
||||
From = searchParams.From,
|
||||
Amount = searchParams.Amount ?? 20
|
||||
Amount = searchParams.Amount ?? 20,
|
||||
AuthorId = searchParams.AuthorId,
|
||||
Author = searchParams.Author,
|
||||
},
|
||||
cancellationToken
|
||||
);
|
||||
|
@ -30,7 +34,7 @@ public class PostsController(IMediator mediator) : ControllerBase
|
|||
new PublicPostAuthorDto(p.Author.AuthorId, p.Author.Username),
|
||||
p.PostId,
|
||||
p.Text,
|
||||
p.Media.Select(m => m.Url),
|
||||
p.Media.Select(m => new PublicPostMediaDto(m.Url, m.Width, m.Height)),
|
||||
p.CreatedAt
|
||||
)),
|
||||
res.Next
|
||||
|
@ -43,8 +47,22 @@ public class PostsController(IMediator mediator) : ControllerBase
|
|||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
var guid = await mediator.Send(
|
||||
new CreatePostCommand(req.AuthorId, req.Content, req.Media),
|
||||
var guid = await blogModule.PostCommand(
|
||||
new CreatePostCommand(
|
||||
req.AuthorId,
|
||||
req.Content,
|
||||
req.Media.Select(
|
||||
(media, idx) =>
|
||||
new CreatePostMedia(
|
||||
media.MediaId,
|
||||
media.Url,
|
||||
media.Type,
|
||||
idx,
|
||||
media.Width,
|
||||
media.Height
|
||||
)
|
||||
)
|
||||
),
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue