1
This commit is contained in:
32
Yes.Application/Admins/Themes/GetThemeFileQueryHandler.cs
Normal file
32
Yes.Application/Admins/Themes/GetThemeFileQueryHandler.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
namespace Yes.Application.Admins.Themes
|
||||
{
|
||||
|
||||
public record GetThemeFileQuery(string ThemeName, string FileName) : IRequest<GetThemeFileQueryResponse>;
|
||||
|
||||
public record GetThemeFileQueryResponse(
|
||||
string Content
|
||||
);
|
||||
|
||||
public class GetThemeFileQueryHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper, IWebHostEnvironment env) : IRequestHandler<GetThemeFileQuery, GetThemeFileQueryResponse>
|
||||
{
|
||||
private readonly BlogSettings _settings = options.CurrentValue;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
private readonly IWebHostEnvironment _env = env;
|
||||
|
||||
public async Task<GetThemeFileQueryResponse> Handle(GetThemeFileQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var themeName = request.ThemeName;
|
||||
var fileName = request.FileName;
|
||||
|
||||
var themes = new List<GetThemeFileQueryResponse>();
|
||||
var filePath = Path.Combine(_env.ContentRootPath, "files", "themes", themeName, fileName);
|
||||
var content = "";
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
content = File.ReadAllText(filePath);
|
||||
}
|
||||
|
||||
return new GetThemeFileQueryResponse(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Yes.Application/Admins/Themes/GetThemeFilesQueryHandler.cs
Normal file
30
Yes.Application/Admins/Themes/GetThemeFilesQueryHandler.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace Yes.Application.Admins.Themes
|
||||
{
|
||||
|
||||
public record GetThemeFilesQuery(string Name) : IRequest<List<GetThemeFilesQueryResponse>>;
|
||||
|
||||
public record GetThemeFilesQueryResponse(
|
||||
string FileName
|
||||
);
|
||||
|
||||
public class GetThemeFilesQueryHandler(IOptionsMonitor<BlogSettings> options, IMapper mapper, IWebHostEnvironment env) : IRequestHandler<GetThemeFilesQuery, List<GetThemeFilesQueryResponse>>
|
||||
{
|
||||
private readonly BlogSettings _settings = options.CurrentValue;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
private readonly IWebHostEnvironment _env = env;
|
||||
|
||||
public async Task<List<GetThemeFilesQueryResponse>> Handle(GetThemeFilesQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var themeName = request.Name;
|
||||
var themes = new List<GetThemeFilesQueryResponse>();
|
||||
var themePath = Path.Combine(_env.ContentRootPath, "files", "themes", themeName);
|
||||
var files = Directory.GetFiles(themePath).Where(x=>x.EndsWith(".liquid") || x.EndsWith(".css") || x.EndsWith(".js"));
|
||||
|
||||
|
||||
|
||||
themes = files.Select(x=>new GetThemeFilesQueryResponse(Path.GetFileName(x))).ToList();
|
||||
|
||||
return themes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace Yes.Application.Admins.Themes
|
||||
{
|
||||
public record UpdateThemeFileCommand(
|
||||
string ThemeName,
|
||||
string FileName,
|
||||
string Content
|
||||
) : IRequest<Unit>;
|
||||
|
||||
|
||||
public class UpdateThemeFileCommandHandler(
|
||||
IThemeService themeService,
|
||||
IWebHostEnvironment env
|
||||
) : IRequestHandler<UpdateThemeFileCommand, Unit>
|
||||
{
|
||||
private readonly IThemeService _themeService = themeService;
|
||||
private readonly IWebHostEnvironment _env = env;
|
||||
public async Task<Unit> Handle(UpdateThemeFileCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var themeName = request.ThemeName;
|
||||
var fileName = request.FileName;
|
||||
var content = request.Content;
|
||||
_themeService.CheckThemeExists(themeName);
|
||||
var filePath = Path.Combine(_env.ContentRootPath, "files", "themes", themeName, fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
File.WriteAllText(filePath, content);
|
||||
}
|
||||
return new Unit();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user