Browse Source

取得特定TMID的BlobSas(read only)

jeff 9 months ago
parent
commit
6eba0c83a0
1 changed files with 48 additions and 2 deletions
  1. 48 2
      TEAMModelOS/Controllers/Teacher/JointEventController.cs

+ 48 - 2
TEAMModelOS/Controllers/Teacher/JointEventController.cs

@@ -562,7 +562,7 @@ namespace TEAMModelOS.Controllers.Common
             }
         }
         /// <summary>
-        /// 新建修改教師課程及組別
+        /// 新建修改教師報名課程及組別
         /// </summary>
         [ProducesDefaultResponseType]
         [Authorize(Roles = "IES,HTCommunity")]
@@ -586,7 +586,7 @@ namespace TEAMModelOS.Controllers.Common
                     return Ok(new { errCode = "1", err = "Invalid param." });
                 }
                 JointEventGroupDb jointCourse = new JointEventGroupDb();
-                StringBuilder stringBuilder = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.creatorId = '{creatorId}' ");
+                StringBuilder stringBuilder = new($"SELECT * FROM c WHERE c.jointEventId = '{jointEventId}' AND c.jointGroupId = '{jointGroupId}' AND c.creatorId = '{creatorId}' AND ( IS_DEFINED(c.type) = false OR c.type = 'regular' ) ");
                 await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIteratorSql(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("JointCourse") }))
                 {
                     using var json = await JsonDocument.ParseAsync(item.Content);
@@ -621,6 +621,7 @@ namespace TEAMModelOS.Controllers.Common
                         jointCourse.creatorEmail = creatorEmail;
                         jointCourse.schoolId = schoolId;
                         jointCourse.schoolName = schoolName;
+
                     }
                     //修改
                     jointCourse.courseLists = courseLists;
@@ -1109,6 +1110,51 @@ namespace TEAMModelOS.Controllers.Common
             }
         }
 
+        /// <summary>
+        /// 取得TMID的Blob access token
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [Authorize(Roles = "IES")]
+#if !DEBUG
+        [AuthToken(Roles = "teacher")]
+#endif
+        [HttpPost("tblobsas")]
+        public async Task<IActionResult> getTeacherBlobSas(JsonElement request)
+        {
+            List<string> tmids = (request.TryGetProperty("tmids", out JsonElement _tmids)) ? _tmids.ToObject<List<string>>() : new List<string> ();
+            var client = _azureCosmos.GetCosmosClient();
+            //取得老師ID
+            List<string> tmidsExist = new List<string>();
+            if (tmids.Count > 0)
+            {
+                StringBuilder stringBuilder = new($"SELECT c.id FROM c WHERE ARRAY_CONTAINS({JsonSerializer.Serialize(tmids)}, c.id) ");
+                await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryStreamIteratorSql(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Base") }))
+                {
+                    using var json = await JsonDocument.ParseAsync(item.Content);
+                    if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
+                    {
+                        foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
+                        {
+                            tmidsExist.Add(obj.GetProperty("id").ToString());
+                        }
+                    }
+                }
+            }
+            //取得SAS
+            List<object> sasList = new List<object>();
+            if (tmidsExist.Count > 0)
+            {
+                foreach (string tmid in tmidsExist)
+                {
+                    var (blob_uri, blob_sas) = _azureStorage.GetBlobContainerSAS(tmid, BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
+                    sasList.Add(new { id = tmid, sas = blob_sas });
+                }
+            }
+            return Ok(sasList);
+        }
+
         //判斷某groupId在某JointSchedule是否完成
         private async Task<string> GetGroupFinishJointSchedule(string jointEventId, string jointGroupId, string groupId, JointEventSchedule schedule)
         {