using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Common; using CommonInfrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using UserDomain.Entity; using UserService.Notices; using UserService.Notices.Param; namespace UserApi.Notices { [ApiController, Route("api/[controller]")] [Authorize] public class NoticeController : BaseController { private readonly INoticeService _noticeService; public NoticeController(INoticeService noticeService) { _noticeService = noticeService; } /// /// 获取系统公告列表(分页) /// [HttpPost("list")] public async Task> GetNoticeList(GetNoticeListParam param) { var result = await _noticeService.GetList(param); var list = result.list ?? new List(); var dtos = list.Select(n => new NoticeDto { Id = n.Id, Title = n.Title, Content = n.Content, Recommend = n.Recommend, TopImage = n.TopImage, ContentImages = n.ContentImages, CreateTime = n.CreateTime }); return this.ToPageResult(dtos, (int)result.count); } /// /// 根据ID获取公告详情 /// [HttpGet("get")] [AllowAnonymous] public async Task> GetNotice(string id) { var result = await _noticeService.Get(id); if (result == null) { return this.ToFailResult("公告不存在"); } var dto = new NoticeDto { Id = result.Id, Title = result.Title, Content = result.Content, Recommend = result.Recommend, TopImage = result.TopImage, ContentImages = result.ContentImages, CreateTime = result.CreateTime }; return this.ToResult(dto); } /// /// 获取一个最新的公告 /// [HttpGet("get/newone")] [AllowAnonymous] public async Task> GetNewOne() { var result = await _noticeService.GetNewOne(); if (result == null) { return this.ToFailResult("暂无公告"); } var dto = new NoticeDto { Id = result.Id, Title = result.Title, Content = result.Content, Recommend = result.Recommend, TopImage = result.TopImage, ContentImages = result.ContentImages, CreateTime = result.CreateTime }; return this.ToResult(dto); } } public class NoticeDto { public string Id { get; set; } public string Title { get; set; } public string Content { get; set; } public string Recommend { get; set; } public string TopImage { get; set; } public List ContentImages { get; set; } public long CreateTime { get; set; } } }