73 lines
2.3 KiB
C#
73 lines
2.3 KiB
C#
using LMS.Repository.DB;
|
||
using LMS.Repository.DTO;
|
||
using LMS.Repository.Options;
|
||
using LMS.service.Service;
|
||
using LMS.Tools.Extensions;
|
||
using Microsoft.AspNetCore.Authorization;
|
||
using Microsoft.AspNetCore.Mvc;
|
||
using static LMS.Common.Enums.ResponseCodeEnum;
|
||
|
||
namespace LMS.service.Controllers
|
||
{
|
||
/// <summary>
|
||
/// Laitool 的配置项控制器
|
||
/// </summary>
|
||
/// <param name="optionsService"></param>
|
||
[Route("lms/[controller]/[action]")]
|
||
[ApiController]
|
||
public class LaitoolOptionsController(OptionsService optionsService) : ControllerBase
|
||
{
|
||
private readonly OptionsService _optionsService = optionsService;
|
||
|
||
#region 获取简单的配置项,无需权限
|
||
/// <summary>
|
||
/// 获取简单的配置项,无需权限
|
||
/// </summary>
|
||
/// <param name="request"></param>
|
||
/// <returns></returns>
|
||
[HttpGet("{optionsKey}")]
|
||
public async Task<ActionResult<APIResponseModel<List<OptionsDto>>>> GetSimpleOptions(string optionsKey)
|
||
{
|
||
return await _optionsService.GetSimpleOptions(optionsKey);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 获取指定的操作,需要管理员权限
|
||
|
||
[HttpGet("{optionsKey}")]
|
||
[Authorize]
|
||
public async Task<ActionResult<APIResponseModel<List<OptionsDto>>>> GetAllOptions(string optionsKey)
|
||
{
|
||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||
return await _optionsService.GetAllOptions(optionsKey, userId);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 修改配置项
|
||
|
||
[HttpPost]
|
||
[Authorize]
|
||
public async Task<ActionResult<APIResponseModel<string>>> ModifyOptions([FromBody] List<ModofyOptionsModel> model)
|
||
{
|
||
if (!ModelState.IsValid)
|
||
{
|
||
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
||
}
|
||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||
return await _optionsService.ModifyOptions(model, userId);
|
||
}
|
||
|
||
#endregion
|
||
|
||
//[HttpPost]
|
||
//[Authorize]
|
||
//public async Task<ActionResult<APIResponseModel<Options>>> GetOptions([FromBody] OptionsRequestModel request)
|
||
//{
|
||
// return await _optionsService.GetOptions(request);
|
||
//}
|
||
|
||
}
|
||
}
|