|
@@ -141,23 +141,30 @@ namespace TEAMModelOS.Controllers.Common
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
[HttpPost("update-state")]
|
|
[HttpPost("update-state")]
|
|
[Authorize(Roles = "IES")]
|
|
[Authorize(Roles = "IES")]
|
|
- public async Task<IActionResult> UpdateState(JsonElement request)
|
|
|
|
|
|
+ public async Task<IActionResult> UpdateState(ArtRecord request)
|
|
{
|
|
{
|
|
- if (!request.TryGetProperty("isAnswer", out JsonElement isAnswer)) return BadRequest();
|
|
|
|
- if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- ArtMusic music = new();
|
|
|
|
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.GetString(), new PartitionKey("ArtMusic"));
|
|
|
|
- if (response.Status == 200)
|
|
|
|
|
|
+ var (userid, name, picture, school) = HttpContext.GetAuthTokenInfo();
|
|
|
|
+ HttpContext.Items.TryGetValue("Scope", out object scope);
|
|
|
|
+ int userType = $"{scope}".Equals(Constant.ScopeStudent) ? 2 : 1;
|
|
|
|
+ request.school = school;
|
|
|
|
+ request.stuId = userid;
|
|
|
|
+ request.code = "ArtRecord";
|
|
|
|
+ long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
|
|
+ request.createTime = now;
|
|
|
|
+ ArtRecord record;
|
|
|
|
+ if (string.IsNullOrEmpty(request.id))
|
|
|
|
+ {
|
|
|
|
+ request.id = Guid.NewGuid().ToString();
|
|
|
|
+ record = await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(request, new PartitionKey($"{request.code}"));
|
|
|
|
+ }
|
|
|
|
+ else
|
|
{
|
|
{
|
|
- using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
|
|
- music = json.ToObject<ArtMusic>();
|
|
|
|
- music.isAnswer = isAnswer.GetInt32();
|
|
|
|
- await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(music, music.id, new PartitionKey($"{music.code}"));
|
|
|
|
|
|
+ record = await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
|
|
}
|
|
}
|
|
- return Ok(music);
|
|
|
|
|
|
+ return Ok(record);
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
catch (Exception e)
|
|
{
|
|
{
|