|
@@ -260,34 +260,7 @@ namespace TEAMModelOS.Controllers
|
|
|
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}"));
|
|
|
- Syllabus syllabus = null;
|
|
|
- if (share.scope == "school")
|
|
|
- {
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
- }
|
|
|
- else if (share.scope == "private")
|
|
|
- {
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
- }
|
|
|
- if (syllabus.auth.IsNotEmpty())
|
|
|
- {
|
|
|
- syllabus.auth.ForEach(x =>
|
|
|
- {
|
|
|
- if (x.tmdid == $"{code}" && x.type == $"{type}")
|
|
|
- {
|
|
|
- if ($"{opt}".Equals("ignore"))
|
|
|
- {
|
|
|
- x.agree = 0;
|
|
|
- }
|
|
|
- else if ($"{opt}".Equals("ignore")) {
|
|
|
- x.agree = 1;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if ($"{opt}".Equals("ignore"))
|
|
|
+ if ($"{opt}".Equals("agree"))
|
|
|
{
|
|
|
share.agree = 1;
|
|
|
await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Share>(share, $"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
@@ -296,13 +269,53 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
await client.GetContainer("TEAMModelOS", "Teacher").DeleteItemAsync<Share>($"{id}", new PartitionKey($"Share-{type}-{code}"));
|
|
|
}
|
|
|
+
|
|
|
+ Syllabus syllabus = null;
|
|
|
if (share.scope == "school")
|
|
|
{
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "School").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ } catch {
|
|
|
+ //仅处理差不到数据的情况
|
|
|
+ }
|
|
|
}
|
|
|
else if (share.scope == "private")
|
|
|
{
|
|
|
- syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ try
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Syllabus>($"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ } catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (syllabus != null) {
|
|
|
+ if (syllabus.auth.IsNotEmpty())
|
|
|
+ {
|
|
|
+ syllabus.auth.ForEach(x =>
|
|
|
+ {
|
|
|
+ if (x.tmdid == $"{code}" && x.type == $"{type}")
|
|
|
+ {
|
|
|
+ if ($"{opt}".Equals("ignore"))
|
|
|
+ {
|
|
|
+ x.agree = 0;
|
|
|
+ }
|
|
|
+ else if ($"{opt}".Equals("ignore"))
|
|
|
+ {
|
|
|
+ x.agree = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (share.scope == "school")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ }
|
|
|
+ else if (share.scope == "private")
|
|
|
+ {
|
|
|
+ syllabus = await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Syllabus>(syllabus, $"{id}", new PartitionKey($"Syllabus-{share.volumeId}"));
|
|
|
+ }
|
|
|
}
|
|
|
return Ok(new { status = 200 });
|
|
|
} catch (Exception ex) {
|
|
@@ -310,6 +323,12 @@ namespace TEAMModelOS.Controllers
|
|
|
return Ok(new { status = 500 });
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// 删除共享记录
|
|
|
+ /// {"id":"章节id","type:"coedit/share","code":"教师tmdid"}
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("del-share")]
|
|
|
public async Task<IActionResult> DelShare(JsonElement request) {
|