LMS.service/LMS.service/Controllers/OptionsController.cs
lq1405 aaebbb9104 V 1.1.0
新增数据信息 完善数据信息得权限问题
2025-05-21 21:28:18 +08:00

189 lines
6.6 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.Common.Extensions;
using LMS.Repository.DB;
using LMS.Repository.DTO;
using LMS.Repository.DTO.OptionDto;
using LMS.Repository.Models.DB;
using LMS.Repository.Options;
using LMS.service.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
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)
{
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
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
#region
[HttpPost]
[Authorize]
public async Task<ActionResult<APIResponseModel<string>>> TestSendMail()
{
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
return await _optionsService.TestSendMail(userId);
}
#endregion
}
/// <summary>
/// Laitool 的配置项控制器
/// </summary>
/// <param name="optionsService"></param>
[Route("lms/[controller]/[action]")]
[ApiController]
public class OptionsController(OptionsService optionsService) : ControllerBase
{
private readonly OptionsService _optionsService = optionsService;
#region
/// <summary>
/// 获取简单的配置项,无需权限
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("{userId}/{category}/{optionsKey}")]
public async Task<ActionResult<APIResponseModel<OptionsDto>>> GetOptionsByKey(long userId, int category, string optionsKey)
{
return await _optionsService.GetOptionsByKey(userId, category, optionsKey);
}
#endregion
#region
/// <summary>
/// 获取简单的配置项,无需权限
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("{category}/{optionsKey}")]
[Authorize]
public async Task<ActionResult<APIResponseModel<OptionSimpleDto>>> GetAllMessageOptionsByKey(int category, string optionsKey)
{
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
return await _optionsService.GetAllMessageOptionsByKey(category, optionsKey, userId);
}
#endregion
#region
/// <summary>
/// 获取简单的配置项,无需权限
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet]
[Authorize]
public async Task<ActionResult<APIResponseModel<CollectionResponse<OptionSimpleDto>>>> QueryOptionCollection([Required] int page, [Required] int pageSize, string? key, int? type, int? category, [FromQuery] string[]? roleNames)
{
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
return await _optionsService.QueryOptionCollection(page, pageSize, key, type, category, roleNames, userId);
}
#endregion
#region
[HttpPost("{key}")]
[Authorize]
public async Task<ActionResult<APIResponseModel<string>>> ModifyOptionsByKey(string key, [FromBody] ModifyOptionByKeyModel model)
{
if (!ModelState.IsValid)
{
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
}
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
return await _optionsService.ModifyOptionsByKey(key, model, userId);
}
#endregion
#region
[HttpPost]
[Authorize]
public async Task<ActionResult<APIResponseModel<string>>> AddOptions([FromBody] AddOptionModel option)
{
if (!ModelState.IsValid)
{
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
}
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
return await _optionsService.AddOptions(option, userId);
}
#endregion
#region key的数据
[HttpDelete("{category}/{key}")]
[Authorize]
public async Task<ActionResult<APIResponseModel<string>>> DeleteOptionsByKey(int category, string key)
{
if (!ModelState.IsValid)
{
return APIResponseModel<string>.CreateErrorResponseModel(ResponseCode.ParameterError);
}
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
return await _optionsService.DeleteOptionsByKey(category, key, userId);
}
#endregion
}
}