|
@@ -256,65 +256,74 @@ namespace TEAMModelOS.Controllers
|
|
|
try {
|
|
|
if (!request.TryGetProperty("type", out JsonElement type)) { return BadRequest(); }
|
|
|
if (!request.TryGetProperty("code", out JsonElement code)) { return BadRequest(); }
|
|
|
- if (!request.TryGetProperty("id", out JsonElement id)) { return BadRequest(); }
|
|
|
+ if (!request.TryGetProperty("ids", out JsonElement ids)) { return BadRequest(); }
|
|
|
if (!request.TryGetProperty("opt", out JsonElement opt)) { return BadRequest(); }
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
- Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
- if ($"{opt}".Equals("agree"))
|
|
|
- {
|
|
|
- share.agree = 1;
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
- }
|
|
|
- else if ($"{opt}".Equals("ignore"))
|
|
|
- {
|
|
|
- await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
- }
|
|
|
+ if (ids.ValueKind.Equals(JsonValueKind.Array)) {
|
|
|
+ List<string> idss = ids.ToObject<List<string>>();
|
|
|
+ foreach (var id in idss) {
|
|
|
+ Share share = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
+ if ($"{opt}".Equals("agree"))
|
|
|
+ {
|
|
|
+ share.agree = 1;
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
+ }
|
|
|
+ else if ($"{opt}".Equals("ignore"))
|
|
|
+ {
|
|
|
+ await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
+ }
|
|
|
|
|
|
- Syllabus syllabus = null;
|
|
|
- if (share.scope == "school")
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.school}"));
|
|
|
- } catch {
|
|
|
- //仅处理差不到数据的情况
|
|
|
- }
|
|
|
- }
|
|
|
- else if (share.scope == "private")
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.issuer}"));
|
|
|
- } catch
|
|
|
- {
|
|
|
- }
|
|
|
- }
|
|
|
- if (syllabus != null) {
|
|
|
- if (syllabus.auth.IsNotEmpty())
|
|
|
- {
|
|
|
- syllabus.auth.ForEach(x =>
|
|
|
+ Syllabus syllabus = null;
|
|
|
+ if (share.scope == "school")
|
|
|
{
|
|
|
- if (x.tmdid == $"{code}" && x.type == $"{type}")
|
|
|
+ try
|
|
|
{
|
|
|
- if ($"{opt}".Equals("ignore"))
|
|
|
- {
|
|
|
- x.agree = 0;
|
|
|
- }
|
|
|
- else if ($"{opt}".Equals("agree"))
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.school}"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ //仅处理差不到数据的情况
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (share.scope == "private")
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.issuer}"));
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (syllabus != null)
|
|
|
+ {
|
|
|
+ if (syllabus.auth.IsNotEmpty())
|
|
|
+ {
|
|
|
+ syllabus.auth.ForEach(x =>
|
|
|
{
|
|
|
- x.agree = 1;
|
|
|
- }
|
|
|
+ if (x.tmdid == $"{code}" && x.type == $"{type}")
|
|
|
+ {
|
|
|
+ if ($"{opt}".Equals("ignore"))
|
|
|
+ {
|
|
|
+ x.agree = 0;
|
|
|
+ }
|
|
|
+ else if ($"{opt}".Equals("agree"))
|
|
|
+ {
|
|
|
+ x.agree = 1;
|
|
|
+ }
|
|
|
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- if (share.scope == "school")
|
|
|
- {
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.school}"));
|
|
|
- }
|
|
|
- else if (share.scope == "private")
|
|
|
- {
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.issuer}"));
|
|
|
+ if (share.scope == "school")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.school}"));
|
|
|
+ }
|
|
|
+ else if (share.scope == "private")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.issuer}"));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return Ok(new { status = 200 });
|