添加项目文件。
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
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<PageResponse<NoticeDto>> GetNoticeList(GetNoticeListParam param)
|
||||
{
|
||||
var result = await _noticeService.GetList(param);
|
||||
var list = result.list ?? new List<Notice>();
|
||||
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);
|
||||
}
|
||||
|
||||
[HttpGet("get")]
|
||||
[AllowAnonymous]
|
||||
public async Task<BaseResponse<NoticeDto>> GetNotice(string id)
|
||||
{
|
||||
var result = await _noticeService.Get(id);
|
||||
if (result == null)
|
||||
{
|
||||
return this.ToFailResult<NoticeDto>("公告不存在");
|
||||
}
|
||||
|
||||
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<BaseResponse<NoticeDto>> GetNewOne()
|
||||
{
|
||||
var result = await _noticeService.GetNewOne();
|
||||
if (result == null)
|
||||
{
|
||||
return this.ToFailResult<NoticeDto>("暂无公告");
|
||||
}
|
||||
|
||||
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<string> ContentImages { get; set; }
|
||||
|
||||
public long CreateTime { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user