Skip to content

Commit

Permalink
remove Post DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Apr 29, 2024
1 parent 54b84c3 commit 850810a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 116 deletions.
8 changes: 4 additions & 4 deletions src/Moonglade.Core/PostFeature/GetPostByIdQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

namespace Moonglade.Core.PostFeature;

public record GetPostByIdQuery(Guid Id) : IRequest<Post>;
public record GetPostByIdQuery(Guid Id) : IRequest<PostEntity>;

public class GetPostByIdQueryHandler(MoongladeRepository<PostEntity> repo) : IRequestHandler<GetPostByIdQuery, Post>
public class GetPostByIdQueryHandler(MoongladeRepository<PostEntity> repo) : IRequestHandler<GetPostByIdQuery, PostEntity>
{
public Task<Post> Handle(GetPostByIdQuery request, CancellationToken ct)
public Task<PostEntity> Handle(GetPostByIdQuery request, CancellationToken ct)
{
var spec = new PostSpec(request.Id);
var post = repo.FirstOrDefaultAsync(spec, Post.EntitySelector);
var post = repo.FirstOrDefaultAsync(spec, ct);
return post;
}
}
57 changes: 0 additions & 57 deletions src/Moonglade.Core/PostFeature/Post.cs

This file was deleted.

18 changes: 9 additions & 9 deletions src/Moonglade.Web/Pages/Admin/EditPost.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ public class EditPostModel(IMediator mediator, ITimeZoneResolver timeZoneResolve

public async Task<IActionResult> OnGetAsync(Guid? id)
{
var cats = await mediator.Send(new GetCategoriesQuery());

if (id is null)
{
var cats1 = await mediator.Send(new GetCategoriesQuery());
if (cats1.Count > 0)
if (cats.Count > 0)
{
var cbCatList = cats1.Select(p =>
var cbCatList = cats.Select(p =>
new CategoryCheckBox
{
Id = p.Id,
Expand All @@ -47,15 +48,15 @@ public async Task<IActionResult> OnGetAsync(Guid? id)
{
PostId = post.Id,
IsPublished = post.IsPublished,
EditorContent = post.RawPostContent,
EditorContent = post.PostContent,
Author = post.Author,
Slug = post.Slug,
Title = post.Title,
EnableComment = post.CommentEnabled,
FeedIncluded = post.IsFeedIncluded,
LanguageCode = post.ContentLanguageCode,
Abstract = post.ContentAbstract.Replace("\u00A0\u2026", string.Empty),
Featured = post.Featured,
Featured = post.IsFeatured,
OriginLink = post.OriginLink,
HeroImageUrl = post.HeroImageUrl,
IsOutdated = post.IsOutdated
Expand All @@ -73,15 +74,14 @@ public async Task<IActionResult> OnGetAsync(Guid? id)
tagStr = tagStr.TrimEnd(',');
ViewModel.Tags = tagStr;

var cats2 = await mediator.Send(new GetCategoriesQuery());
if (cats2.Count > 0)
if (cats.Count > 0)
{
var cbCatList = cats2.Select(p =>
var cbCatList = cats.Select(p =>
new CategoryCheckBox
{
Id = p.Id,
DisplayText = p.DisplayName,
IsChecked = post.Categories.Any(q => q.Id == p.Id)
IsChecked = post.PostCategory.Any(q => q.CategoryId == p.Id)
});
CategoryList = cbCatList.ToList();
}
Expand Down
46 changes: 0 additions & 46 deletions src/Moonglade.Web/Pages/_PostActions.cshtml

This file was deleted.

0 comments on commit 850810a

Please sign in to comment.