|
@@ -22,6 +22,7 @@ using System.Reflection;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using System.Xml.Linq;
|
|
using TEAMModelOS.Filter;
|
|
using TEAMModelOS.Filter;
|
|
using TEAMModelOS.Models;
|
|
using TEAMModelOS.Models;
|
|
using TEAMModelOS.SDK;
|
|
using TEAMModelOS.SDK;
|
|
@@ -78,18 +79,19 @@ namespace TEAMModelOS.Controllers.Common
|
|
try
|
|
try
|
|
{
|
|
{
|
|
if (!request.TryGetProperty("art", out JsonElement art)) return BadRequest();
|
|
if (!request.TryGetProperty("art", out JsonElement art)) return BadRequest();
|
|
-
|
|
|
|
|
|
+
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
ArtEvaluation ae = art.ToObject<ArtEvaluation>();
|
|
ArtEvaluation ae = art.ToObject<ArtEvaluation>();
|
|
bool flag = false;
|
|
bool flag = false;
|
|
ArtMusic music = new();
|
|
ArtMusic music = new();
|
|
- if (request.TryGetProperty("ArtMusic", out JsonElement am)) {
|
|
|
|
|
|
+ if (request.TryGetProperty("ArtMusic", out JsonElement am))
|
|
|
|
+ {
|
|
music = am.ToObject<ArtMusic>();
|
|
music = am.ToObject<ArtMusic>();
|
|
music.ttl = -1;
|
|
music.ttl = -1;
|
|
music.code = "ArtMusic";
|
|
music.code = "ArtMusic";
|
|
flag = true;
|
|
flag = true;
|
|
};
|
|
};
|
|
-
|
|
|
|
|
|
+
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
string code = ae.school;
|
|
string code = ae.school;
|
|
ae.ttl = -1;
|
|
ae.ttl = -1;
|
|
@@ -106,19 +108,20 @@ namespace TEAMModelOS.Controllers.Common
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(ae.id))
|
|
if (string.IsNullOrEmpty(ae.id))
|
|
{
|
|
{
|
|
-
|
|
|
|
- ae.id = Guid.NewGuid().ToString();
|
|
|
|
|
|
+
|
|
|
|
+ ae.id = Guid.NewGuid().ToString();
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(ae, new PartitionKey($"{ae.code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(ae, new PartitionKey($"{ae.code}"));
|
|
if (flag)
|
|
if (flag)
|
|
{
|
|
{
|
|
music.id = ae.id;
|
|
music.id = ae.id;
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(music, new PartitionKey("ArtMusic"));
|
|
await client.GetContainer("TEAMModelOS", "Common").CreateItemAsync(music, new PartitionKey("ArtMusic"));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- if (flag) {
|
|
|
|
|
|
+ if (flag)
|
|
|
|
+ {
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(music, music.id, new PartitionKey("ArtMusic"));
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(music, music.id, new PartitionKey("ArtMusic"));
|
|
}
|
|
}
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(ae, ae.id, new PartitionKey($"{ae.code}"));
|
|
await client.GetContainer("TEAMModelOS", "Common").ReplaceItemAsync(ae, ae.id, new PartitionKey($"{ae.code}"));
|
|
@@ -134,6 +137,34 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
|
+ [AuthToken(Roles = "teacher,admin,student")]
|
|
|
|
+ [HttpPost("update-state")]
|
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
|
+ public async Task<IActionResult> UpdateState(JsonElement request)
|
|
|
|
+ {
|
|
|
|
+ if (!request.TryGetProperty("isAnswer", out JsonElement isAnswer)) return BadRequest();
|
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ ArtMusic music = new();
|
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(id.GetString(), new PartitionKey("ArtMusic"));
|
|
|
|
+ if (response.Status == 200)
|
|
|
|
+ {
|
|
|
|
+ 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}"));
|
|
|
|
+ }
|
|
|
|
+ return Ok(music);
|
|
|
|
+ }
|
|
|
|
+ catch (Exception e)
|
|
|
|
+ {
|
|
|
|
+ return BadRequest(new { msg = e.Message });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
[HttpPost("upload")]
|
|
[HttpPost("upload")]
|
|
@@ -710,18 +741,20 @@ namespace TEAMModelOS.Controllers.Common
|
|
{
|
|
{
|
|
responses.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(z, new PartitionKey(z.code)));
|
|
responses.Add(client.GetContainer(Constant.TEAMModelOS, Constant.Student).CreateItemAsync(z, new PartitionKey(z.code)));
|
|
});
|
|
});
|
|
- if (responses.Count > 0) {
|
|
|
|
|
|
+ if (responses.Count > 0)
|
|
|
|
+ {
|
|
await responses.TaskPage(10);
|
|
await responses.TaskPage(10);
|
|
- }
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
if (!string.IsNullOrWhiteSpace(ae.id))
|
|
if (!string.IsNullOrWhiteSpace(ae.id))
|
|
{
|
|
{
|
|
return Ok(new { art, classes, ae, music, code = 200 });
|
|
return Ok(new { art, classes, ae, music, code = 200 });
|
|
}
|
|
}
|
|
- else {
|
|
|
|
|
|
+ else
|
|
|
|
+ {
|
|
return Ok(new { art, classes, music, code = 200 });
|
|
return Ok(new { art, classes, music, code = 200 });
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -764,7 +797,7 @@ namespace TEAMModelOS.Controllers.Common
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(art.pId))
|
|
if (!string.IsNullOrWhiteSpace(art.pId))
|
|
{
|
|
{
|
|
- var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtMusic"));
|
|
|
|
|
|
+ var response = await client.GetContainer("TEAMModelOS", "Common").ReadItemStreamAsync(art.pId, new PartitionKey("ArtMusic"));
|
|
if (response.Status == 200)
|
|
if (response.Status == 200)
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(response.ContentStream);
|