using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using GxPress.Common.Page;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.Thesaurus;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace GxPress.Api.AdminControllers
{
///
/// 词库 热词 冷词
///
[Route("api/admin/thesaurus")]
[ApiController]
[Authorize]
public class AdminThesaurusController : ControllerBase
{
private readonly IThesaurusRepository _thesaurusRepository;
public AdminThesaurusController(IThesaurusRepository thesaurusRepository)
{
_thesaurusRepository = thesaurusRepository;
}
///
/// 添加
///
/// 参数
///
[HttpPut("add")]
public async Task InThesaurus([FromBody] ThesaurusInRequest request)
{
if (!string.IsNullOrEmpty(request.ThesaurusName) && request.ThesaurusName.Length > 500)
{
throw new Exception("保存失败,字符数不能超出16字");
}
var appVersion = new Thesaurus { ThesaurusType = request.ThesaurusType, ThesaurusName = request.ThesaurusName };
return await _thesaurusRepository.InsertAsync(appVersion);
}
///
/// 分页查询列表
///
///
///
[HttpPost("page")]
public async Task> GetPagedList([FromBody] ThesaurusPageSearchRequest request)
{
return await _thesaurusRepository.GetPageList(request);
}
///
/// 删除
///
///
///
[HttpDelete("{id}")]
public async Task Delete(int id)
{
return await _thesaurusRepository.DeleteAsync(id);
}
///
/// 删除
///
///
///
[HttpDelete("delete")]
public async Task Deletes(List ids)
{
return await _thesaurusRepository.DeleteAsync(ids);
}
///
/// 详情
///
///
///
[HttpGet("{id}")]
public async Task Get(int id)
{
return await _thesaurusRepository.GetDetailAsync(id);
}
///
/// 修改
///
///
///
///
[HttpPut("{id}")]
public async Task Update(int id, [FromBody] ThesaurusUpdateRequest request)
{
if (!string.IsNullOrEmpty(request.ThesaurusName) && request.ThesaurusName.Length > 500)
{
throw new Exception("保存失败,字符数不能超出16字");
}
return await _thesaurusRepository.UpdateAsync(id, request);
}
}
}