zhouj1203@hotmail.com 2 年之前
父節點
當前提交
67bad3d49b
共有 2 個文件被更改,包括 20 次插入11 次删除
  1. 2 0
      TEAMModelOS.SDK/Models/Cosmos/Common/ArtRecord.cs
  2. 18 11
      TEAMModelOS/Controllers/Common/ArtController.cs

+ 2 - 0
TEAMModelOS.SDK/Models/Cosmos/Common/ArtRecord.cs

@@ -20,6 +20,8 @@ namespace TEAMModelOS.SDK.Models.Cosmos.Common
         public string stuId { get; set; }
         public string stuId { get; set; }
         public string school { get; set; }
         public string school { get; set; }
         public long createTime { get; set; }
         public long createTime { get; set; }
+        //0未作答 1已作答
+        public int isAnswer { get; set; } = 0;
         public List<Attachment> attachments { get; set; } = new List<Attachment>();
         public List<Attachment> attachments { get; set; } = new List<Attachment>();
     }
     }
 }
 }

+ 18 - 11
TEAMModelOS/Controllers/Common/ArtController.cs

@@ -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)
             {
             {