添加项目文件。
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using Domain.Admin.Notices;
|
||||
using AdminService.Notices;
|
||||
using AdminService.Notices.Param;
|
||||
using Common;
|
||||
using CommonInfrastructure;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AdminApi.Notices;
|
||||
|
||||
[ApiController, Route("adminapi/[controller]")]
|
||||
[Authorize]
|
||||
public class NoticeController : BaseController
|
||||
{
|
||||
private readonly INoticeService _noticeService;
|
||||
|
||||
public NoticeController(INoticeService noticeService)
|
||||
{
|
||||
_noticeService = noticeService;
|
||||
}
|
||||
|
||||
[HttpPost("add")]
|
||||
public async Task<BaseResponse<string>> AddNotice([FromBody] AddNoticeParam param)
|
||||
{
|
||||
var result = await _noticeService.Add(param);
|
||||
return result.isok
|
||||
? this.ToResult(result.msg)
|
||||
: this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("update")]
|
||||
public async Task<BaseResponse<string>> UpdateNotice([FromBody] UpdateNoticeParam param)
|
||||
{
|
||||
var result = await _noticeService.Update(param);
|
||||
return result.isok
|
||||
? this.ToResult(result.msg)
|
||||
: this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpGet("delete")]
|
||||
public async Task<BaseResponse<string>> DeleteNotice([FromQuery] string id)
|
||||
{
|
||||
var result = await _noticeService.Delete(id);
|
||||
return result.isok
|
||||
? this.ToResult(result.msg)
|
||||
: this.ToFailResult<string>(result.msg);
|
||||
}
|
||||
|
||||
[HttpPost("list")]
|
||||
public async Task<PageResponse<NoticeListItemDto>> GetNoticeList([FromBody] GetNoticeListParam param)
|
||||
{
|
||||
var (list, count) = await _noticeService.GetList(param);
|
||||
if (list == null)
|
||||
return this.ToPageResult(new List<NoticeListItemDto>(), 0);
|
||||
var dtos = list.Select(n => new NoticeListItemDto
|
||||
{
|
||||
Id = n.Id,
|
||||
Title = n.Title,
|
||||
Recommend = n.Recommend,
|
||||
TopImage = n.TopImage,
|
||||
CreateTime = n.CreateTime
|
||||
});
|
||||
return this.ToPageResult(dtos, (int)count);
|
||||
}
|
||||
|
||||
[HttpGet("get")]
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<NoticeDto>> GetNotice([FromQuery] string id)
|
||||
{
|
||||
var notice = await _noticeService.Get(id);
|
||||
if (notice == null)
|
||||
{
|
||||
return this.ToFailResult<NoticeDto>("公告不存在");
|
||||
}
|
||||
|
||||
var dto = new NoticeDto
|
||||
{
|
||||
Id = notice.Id,
|
||||
Title = notice.Title,
|
||||
Content = notice.Content,
|
||||
Recommend = notice.Recommend,
|
||||
TopImage = notice.TopImage,
|
||||
ContentImages = notice.ContentImages,
|
||||
CreateTime = notice.CreateTime
|
||||
};
|
||||
return this.ToResult(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user