Skip to content

Commit

Permalink
code refact
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed May 3, 2024
1 parent e82d1fc commit 6bb4a38
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/Moonglade.Data/Specifications/BlogThemeForIdNameSpec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Moonglade.Data.Entities;

namespace Moonglade.Data.Specifications;

public class BlogThemeForIdNameSpec : Specification<BlogThemeEntity, ThemeSegment>
{
public BlogThemeForIdNameSpec()
{
Query.Select(p => new(p.Id, p.ThemeName));
}
}
3 changes: 3 additions & 0 deletions src/Moonglade.Data/ThemeSegment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Moonglade.Data;

public record ThemeSegment(int Id, string Name);
11 changes: 3 additions & 8 deletions src/Moonglade.Theme/GetAllThemeSegmentQuery.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
using MediatR;
using Moonglade.Data;
using Moonglade.Data.Entities;
using Moonglade.Data.Specifications;

namespace Moonglade.Theme;

public record GetAllThemeSegmentQuery : IRequest<List<ThemeSegment>>;

public class GetAllThemeSegmentQueryHandler(MoongladeRepository<BlogThemeEntity> repo) : IRequestHandler<GetAllThemeSegmentQuery, List<ThemeSegment>>
{
public Task<List<ThemeSegment>> Handle(GetAllThemeSegmentQuery request, CancellationToken ct)
{
return repo.SelectAsync(p => new ThemeSegment
{
Id = p.Id,
Name = p.ThemeName
}, ct);
}
public Task<List<ThemeSegment>> Handle(GetAllThemeSegmentQuery request, CancellationToken ct) =>
repo.ListAsync(new BlogThemeForIdNameSpec(), ct);
}
7 changes: 0 additions & 7 deletions src/Moonglade.Theme/ThemeSegment.cs

This file was deleted.

0 comments on commit 6bb4a38

Please sign in to comment.