|
@@ -0,0 +1,103 @@
|
|
|
+using Azure.Cosmos;
|
|
|
+using Azure.Storage.Sas;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Net;
|
|
|
+using System.Text;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.SDK.DI.AzureCosmos.Inner;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Common;
|
|
|
+using TEAMModelOS.SDK.Models.Cosmos.Normal;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers
|
|
|
+{
|
|
|
+ [ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
+ [ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
+ [Route("area/art-setting")]
|
|
|
+ [ApiController]
|
|
|
+ public class ArtSettingController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly SnowflakeId _snowflakeId;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ public IConfiguration _configuration { get; set; }
|
|
|
+ public ArtSettingController(AzureCosmosFactory azureCosmos, AzureServiceBusFactory serviceBus, SnowflakeId snowflakeId, DingDing dingDing,
|
|
|
+ IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage, AzureRedisFactory azureRedis, IConfiguration configuration)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _snowflakeId = snowflakeId;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ _configuration = configuration;
|
|
|
+ }
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ //[AuthToken(Roles = "teacher")]
|
|
|
+ [HttpPost("find-id")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "teacher,student,admin,area")]
|
|
|
+ public async Task<IActionResult> FindId(JsonElement request)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ if (!request.TryGetProperty("areaId", out JsonElement _areaId)) return BadRequest();
|
|
|
+ ArtSetting setting = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").ReadItemAsync<ArtSetting>($"{_areaId}", partitionKey: new Azure.Cosmos.PartitionKey("ArtSetting"));
|
|
|
+ return Ok(new { setting });
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ return Ok(new { setting, error = ex.Status });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 保存
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("upsert")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "teacher,student,admin,area")]
|
|
|
+ public async Task<IActionResult> upsert(ArtSetting setting)
|
|
|
+ {
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ setting.pk = "ArtSetting";
|
|
|
+ setting.code = "ArtSetting";
|
|
|
+ setting.ttl = -1;
|
|
|
+ setting = await client.GetContainer(Constant.TEAMModelOS, "Normal").UpsertItemAsync<ArtSetting>(setting, partitionKey: new Azure.Cosmos.PartitionKey("ArtSetting"));
|
|
|
+ return Ok(new { setting, });
|
|
|
+ }
|
|
|
+ catch (CosmosException ex)
|
|
|
+ {
|
|
|
+ return Ok(new { error = ex.Status });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|