|
@@ -843,6 +843,49 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
return Ok(new { courses });
|
|
|
}
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ //[AuthToken(Roles = "Teacher")]
|
|
|
+ [HttpPost("find-course-by-classId")]
|
|
|
+ public async Task<IActionResult> FindCourseByClassId(JsonElement requert)
|
|
|
+ {
|
|
|
+ if (!requert.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("code", out JsonElement code)) return BadRequest();
|
|
|
+ if (!requert.TryGetProperty("scope", out JsonElement scope)) return BadRequest();
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ List<object> courses = new List<object>();
|
|
|
+ //var query = $"select c.code,c.id,c.name from c join A0 in c.schedule where A0.classId = '{id}'";
|
|
|
+ if (scope.ToString().Equals("school", StringComparison.OrdinalIgnoreCase))
|
|
|
+ {
|
|
|
+ var query = $"select c.code,c.id,c.name from c join A0 in c.schedule where A0.classId = '{id}'";
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "School").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ courses.Add(obj.ToObject<object>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ var query = $"select c.code,c.id,c.name from c join A0 in c.schedule where A0.stulist = '{id}'";
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Teacher").GetItemQueryStreamIterator(queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Course-{code}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ courses.Add(obj.ToObject<object>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Ok(new { courses });
|
|
|
+ }
|
|
|
|
|
|
[ProducesDefaultResponseType]
|
|
|
//[AuthToken(Roles = "Teacher")]
|