Skip to content

Commit

Permalink
update classify crud
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyunchong committed May 26, 2024
1 parent 57533a1 commit 3386704
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,4 @@ docs/api/.manifest
/identityserver4/LinCms.IdentityServer4/appsettings.Production.json
/src/LinCms.Web/appsettings.Production.json
/src/LinCms.Web/prod.bash
/src/LinCms.Web/appsettings.Local_Production.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ namespace LinCms.Blog.Classifys;

public class ClassifySearchDto : PageDto
{
public long? UserId { get; set; }
public string ClassifyName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ namespace LinCms.Blog.Classifys;
/// </summary>
public interface IClassifyService : ICrudAppService<ClassifyDto, ClassifyDto, Guid, ClassifySearchDto, CreateUpdateClassifyDto, CreateUpdateClassifyDto>
{
List<ClassifyDto> GetListByUserId(long? userId);
Task UpdateArticleCountAsync(Guid? id, int inCreaseCount);
}
23 changes: 2 additions & 21 deletions src/LinCms.Application/Blog/Classifies/ClassifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public class ClassifyService(IAuditBaseRepository<Classify, Guid> repository, IF
public override async Task<PagedResultDto<ClassifyDto>> GetListAsync(ClassifySearchDto input)
{
List<ClassifyDto> classify = (await Repository.Select
.WhereIf(input.UserId != null, r => r.CreateUserId == input.UserId)
.WhereIf(input.ClassifyName.IsNotNullOrEmpty(), r => r.ClassifyName.Contains(input.ClassifyName))
.OrderByDescending(r => r.CreateTime)
.OrderByDescending(r => r.SortCode)
.ToPagerListAsync(input, out long totalCount))
.Select(r =>
{
Expand All @@ -37,26 +38,6 @@ public override async Task<PagedResultDto<ClassifyDto>> GetListAsync(ClassifySea
return new PagedResultDto<ClassifyDto>(classify, totalCount);
}

public List<ClassifyDto> GetListByUserId(long? userId)
{
if (!userId.HasValue)
{
userId = CurrentUser.FindUserId();
}

List<ClassifyDto> classify = Repository.Select
.Where(r => r.CreateUserId == userId)
.OrderByDescending(r => r.SortCode)
.ToList()
.Select(r =>
{
ClassifyDto classifyDto = Mapper.Map<ClassifyDto>(r);
classifyDto.ThumbnailDisplay = _fileRepository.GetFileUrl(classifyDto.Thumbnail);
return classifyDto;
}).ToList();

return classify;
}

public override async Task<ClassifyDto> GetAsync(Guid id)
{
Expand Down
8 changes: 4 additions & 4 deletions src/LinCms.Application/Cms/Logs/SerilogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public async Task<LogDashboard> GetLogDashboard()

return new LogDashboard()
{
AllCount = await serilogBaseRepository.Select.CountAsync(),
TodayCount = await serilogBaseRepository.Select.Where(x => x.Timestamp >= now.Date && x.Timestamp <= now.Date.AddHours(23).AddMinutes(59).AddSeconds(59)).CountAsync(),
HourCount = await serilogBaseRepository.Select.Where(x => x.Timestamp >= now.AddHours(-1) && x.Timestamp <= now).CountAsync(),
UniqueCount = await serilogBaseRepository.Select.WithSql(@"select count(*) AS TOTAL from app_serilog group by message").CountAsync(),
AllCount = await serilogBaseRepository.Select.CommandTimeout(20).CountAsync(),
TodayCount = await serilogBaseRepository.Select.CommandTimeout(20).Where(x => x.Timestamp >= now.Date && x.Timestamp <= now.Date.AddHours(23).AddMinutes(59).AddSeconds(59)).CountAsync(),
HourCount = await serilogBaseRepository.Select.CommandTimeout(20).Where(x => x.Timestamp >= now.AddHours(-1) && x.Timestamp <= now).CountAsync(),
UniqueCount = await serilogBaseRepository.Select.CommandTimeout(20).WithSql(@"select count(*) AS TOTAL from app_serilog group by message").CountAsync(),
};
}
}
32 changes: 9 additions & 23 deletions src/LinCms.Web/Controllers/Blog/ClassifyController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,8 @@ namespace LinCms.Controllers.Blog;
[ApiController]
public class ClassifyController(IClassifyService classifyService) : ControllerBase
{
[HttpDelete("{id}")]
public async Task<UnifyResponseDto> DeleteClassify(Guid id)
{
await classifyService.DeleteAsync(id);
return UnifyResponseDto.Success();
}

[HttpGet]
public List<ClassifyDto> GetListByUserId(long? userId)
{
return classifyService.GetListByUserId(userId);
}

[LinCmsAuthorize("删除", "分类专栏")]
[HttpDelete("cms/{id}")]
public async Task<UnifyResponseDto> Delete(Guid id)
{
await classifyService.DeleteAsync(id);
return UnifyResponseDto.Success();
}

[LinCmsAuthorize("分类专栏列表", "分类专栏")]
[HttpGet("cms")]


public Task<PagedResultDto<ClassifyDto>> GetListAsync([FromQuery] ClassifySearchDto pageDto)
{
return classifyService.GetListAsync(pageDto);
Expand All @@ -66,4 +45,11 @@ public async Task<UnifyResponseDto> UpdateAsync(Guid id, [FromBody] CreateUpdate
await classifyService.UpdateAsync(id, updateClassify);
return UnifyResponseDto.Success("更新分类专栏成功");
}

[HttpDelete("{id}")]
public async Task<UnifyResponseDto> Delete(Guid id)
{
await classifyService.DeleteAsync(id);
return UnifyResponseDto.Success();
}
}
9 changes: 9 additions & 0 deletions src/LinCms.Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"LinCms.Web.Local_Production": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger/index.html",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Local_Production"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
},
"LinCms.Web.Nacos": {
"commandName": "Project",
"launchBrowser": true,
Expand Down

0 comments on commit 3386704

Please sign in to comment.