namespace Tiobon.Core.Controllers { /// /// Tibug 管理 /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name), ApiExplorerSettings(GroupName = Grouping.GroupName_Other)] public class TopicDetailController : ControllerBase { readonly ITopicServices _topicServices; readonly ITopicDetailServices _topicDetailServices; /// /// 构造函数 /// /// /// public TopicDetailController(ITopicServices topicServices, ITopicDetailServices topicDetailServices) { _topicServices = topicServices; _topicDetailServices = topicDetailServices; } /// /// 获取Bug数据列表(带分页) /// 【无权限】 /// /// 页数 /// 专题类型 /// 关键字 /// /// [HttpGet] [AllowAnonymous] public async Task>> Get(int page = 1, string tname = "", string key = "", int intPageSize = 12) { long tid = 0; if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key)) { key = ""; } if (string.IsNullOrEmpty(tname) || string.IsNullOrWhiteSpace(tname)) { tname = ""; } tname = UnicodeHelper.UnicodeToString(tname); if (!string.IsNullOrEmpty(tname)) { tid = ((await _topicServices.Query(ts => ts.tName == tname)).FirstOrDefault()?.Id).ObjToLong(); } var data = await _topicDetailServices.QueryPage(a => !a.tdIsDelete && a.tdSectendDetail == "tbug" && ((tid == 0 && true) || (tid > 0 && a.TopicId == tid)) && ((a.tdName != null && a.tdName.Contains(key)) || (a.tdDetail != null && a.tdDetail.Contains(key))), page, intPageSize, " Id desc "); return new ServiceResult>() { Message = "获取成功", Success = data.dataCount >= 0, Data = data }; } /// /// 获取详情【无权限】 /// /// /// // GET: api/TopicDetail/5 [HttpGet("{id}")] [AllowAnonymous] public async Task> Get(long id) { var data = new ServiceResult(); var response = id > 0 ? await _topicDetailServices.QueryById(id) : new TopicDetail(); data.Data = (response?.tdIsDelete).ObjToBool() ? new TopicDetail() : response; if (data.Data != null) { data.Success = true; data.Message = ""; } return data; } /// /// 添加一个 BUG 【无权限】 /// /// /// // POST: api/TopicDetail [HttpPost] [AllowAnonymous] public async Task> Post([FromBody] TopicDetail topicDetail) { var data = new ServiceResult(); topicDetail.tdCreatetime = DateTime.Now; topicDetail.tdRead = 0; topicDetail.tdCommend = 0; topicDetail.tdGood = 0; topicDetail.tdTop = 0; var id = (await _topicDetailServices.Add(topicDetail)); data.Success = id > 0; if (data.Success) { data.Data = id.ObjToString(); data.Message = "添加成功"; } return data; } /// /// 更新 bug /// /// /// // PUT: api/TopicDetail/5 [HttpPut] public async Task> Update([FromBody] TopicDetail topicDetail) { var data = new ServiceResult(); if (topicDetail != null && topicDetail.Id > 0) { data.Success = await _topicDetailServices.Update(topicDetail); if (data.Success) { data.Message = "更新成功"; data.Data = topicDetail?.Id.ObjToString(); } } return data; } /// /// 删除 bug /// /// /// // DELETE: api/ApiWithActions/5 [HttpDelete] public async Task> Delete(long id) { var data = new ServiceResult(); if (id > 0) { var topicDetail = await _topicDetailServices.QueryById(id); topicDetail.tdIsDelete = true; data.Success = await _topicDetailServices.Update(topicDetail); if (data.Success) { data.Message = "删除成功"; data.Data = topicDetail?.Id.ObjToString(); } } return data; } } }