using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using GxPress.Auth;
using GxPress.Common.Page;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Request.Admin;
using GxPress.Request.AppVersion;
using GxPress.Request.Thesaurus;
using GxPress.Result.Admin;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
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")]
[AllowAnonymous]
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")]
[AllowAnonymous]
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);
}
///
/// 详情
///
///
///
[HttpGet("{id}")]
public async Task Get(int id)
{
return await _thesaurusRepository.GetDetailAsync(id);
}
///
/// 修改
///
///
///
///
[HttpPut("{id}")]
public async Task Update(int id, [FromBody] Thesaurus request)
{
if (!string.IsNullOrEmpty(request.ThesaurusName) && request.ThesaurusName.Length > 500)
{
throw new Exception("保存失败,字符数不能超出16字");
}
return await _thesaurusRepository.UpdateAsync(id, request);
}
}
}