瀏覽代碼

新增作品记录

zj 2 年之前
父節點
當前提交
bad3ca4913
共有 2 個文件被更改,包括 57 次插入0 次删除
  1. 22 0
      TEAMModelOS.SDK/Models/Cosmos/Common/ArtRecord.cs
  2. 35 0
      TEAMModelOS/Controllers/Common/ArtController.cs

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

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace TEAMModelOS.SDK.Models.Cosmos.Common
+{
+    public class ArtRecord : CosmosEntity
+    {
+        public ArtRecord()
+        {
+            pk = "ArtRecord";
+        }
+        public string acId { get; set; }
+        public string subject { get; set; }
+        public string stuId { get; set; }
+        public string school { get; set; }
+        public long createTime { get; set; }
+        public List<Attachment> attachments { get; set; } = new List<Attachment>();
+    }
+}

+ 35 - 0
TEAMModelOS/Controllers/Common/ArtController.cs

@@ -104,6 +104,41 @@ namespace TEAMModelOS.Controllers.Common
 
         }
 
+        [ProducesDefaultResponseType]
+        [AuthToken(Roles = "teacher,admin,student")]
+        [HttpPost("upload")]
+        [Authorize(Roles = "IES")]
+        public async Task<IActionResult> Upload(ArtRecord request)
+        {
+            try
+            {
+                var client = _azureCosmos.GetCosmosClient();
+                var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
+                request.school = school;
+                request.stuId = userid;
+                request.code = "ArtRecord";
+                long now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+                request.createTime = now;
+               
+                if (string.IsNullOrEmpty(request.id))
+                {
+                    request.id = Guid.NewGuid().ToString();
+                    await client.GetContainer("TEAMModelOS", "Student").CreateItemAsync(request, new PartitionKey($"{request.code}"));
+                }
+                else
+                {
+                    await client.GetContainer("TEAMModelOS", "Student").ReplaceItemAsync(request, request.id, new PartitionKey($"{request.code}"));
+                }
+                return Ok(new { request });
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"OS,{_option.Location},art/save()\n{ex.Message}\n{ex.StackTrace}\n", GroupNames.醍摩豆服務運維群組);
+                return Ok(new { code = 500, msg = ex.Message });
+            }
+
+        }
+
         [ProducesDefaultResponseType]
         [AuthToken(Roles = "teacher,admin")]
         [HttpPost("delete")]