CrazyIter_Bin 9 달 전
부모
커밋
8a4c2e832d
1개의 변경된 파일32개의 추가작업 그리고 7개의 파일을 삭제
  1. 32 7
      TEAMModelOS/Controllers/School/KnowledgesController.cs

+ 32 - 7
TEAMModelOS/Controllers/School/KnowledgesController.cs

@@ -21,6 +21,9 @@ using Microsoft.AspNetCore.Authorization;
 using TEAMModelOS.SDK;
 using static TEAMModelOS.SDK.ValidatorHelper;
 using System.ComponentModel.DataAnnotations;
+using static SKIT.FlurlHttpClient.Wechat.TenpayV3.Models.CreateApplyForSubjectApplymentRequest.Types;
+using TEAMModelOS.SDK.Models.Service;
+using DocumentFormat.OpenXml.Drawing.Charts;
 
 namespace TEAMModelOS.Controllers
 {
@@ -326,18 +329,40 @@ namespace TEAMModelOS.Controllers
         public async Task<IActionResult> Find(JsonElement request)
         {
             var client = _azureCosmos.GetCosmosClient();
-            request.TryGetProperty("periodId", out JsonElement periodId);
-            if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
-            if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
-            string code = $"Knowledge-{school_code}-{subjectId}";
+            request.TryGetProperty("scope", out JsonElement _scope);
+           
+           
+            string scope = "school";
+            if (_scope.ValueKind.Equals(JsonValueKind.String)) 
+            {
+                scope =$"{_scope}";
+            }
             StringBuilder sql = new StringBuilder($"select value(c) from c");
-            if (periodId.ValueKind.Equals(JsonValueKind.String))
+            string code = "";
+            if (scope.Equals("school"))
             {
-                sql.Append($" where c.periodId = '{periodId}'");
+                request.TryGetProperty("periodId", out JsonElement periodId);
+                if (!request.TryGetProperty("subjectId", out JsonElement subjectId)) return BadRequest();
+                if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
+                code = $"Knowledge-{school_code}-{subjectId}";
+                if (periodId.ValueKind.Equals(JsonValueKind.String))
+                {
+                    sql.Append($" where c.periodId = '{periodId}'");
+                }
             }
+            else {
+                if (!request.TryGetProperty("owner", out JsonElement owner)) return BadRequest();
+                request.TryGetProperty("kid", out JsonElement kid);
+                code = $"Knowledge-{owner}";
+                if (kid.ValueKind.Equals(JsonValueKind.String))
+                {
+                    sql.Append($" where c.id = '{kid}'");
+                }
+            }
+           
             List<Knowledge> knowledges = new List<Knowledge>();
             List<string> keywords = new List<string>();
-            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, "School").GetItemQueryIteratorSql<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
+            await foreach (var item in client.GetContainer(Constant.TEAMModelOS, scope.Equals("school")?Constant.School:Constant.Teacher).GetItemQueryIteratorSql<Knowledge>(queryText: sql.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"{code}") }))
             {
                 item.blocks.ForEach(x =>
                 {