LMS.service/LMS.service/Controllers/OptionsController.cs

73 lines
2.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
//}
}
}