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> AddNotice([FromBody] AddNoticeParam param) { var result = await _noticeService.Add(param); return result.isok ? this.ToResult(result.msg) : this.ToFailResult(result.msg); } [HttpPost("update")] public async Task> UpdateNotice([FromBody] UpdateNoticeParam param) { var result = await _noticeService.Update(param); return result.isok ? this.ToResult(result.msg) : this.ToFailResult(result.msg); } [HttpGet("delete")] public async Task> DeleteNotice([FromQuery] string id) { var result = await _noticeService.Delete(id); return result.isok ? this.ToResult(result.msg) : this.ToFailResult(result.msg); } [HttpPost("list")] public async Task> GetNoticeList([FromBody] GetNoticeListParam param) { var (list, count) = await _noticeService.GetList(param); if (list == null) return this.ToPageResult(new List(), 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> GetNotice([FromQuery] string id) { var notice = await _noticeService.Get(id); if (notice == null) { return this.ToFailResult("公告不存在"); } 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); } }