|
@@ -54,7 +54,8 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
|
- string debateCode = $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}";
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement _scope)) { return BadRequest(); }
|
|
|
+ string debateCode = $"{_scope}".Equals("school") ? $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}" : "Debate";
|
|
|
List<dynamic> debates = new List<dynamic>();
|
|
|
Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
return Ok(new { debate = debate , replyCount = debate.replies!=null ?debate.replies.Count:0});
|
|
@@ -85,7 +86,8 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
|
- string debateCode = $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}";
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement _scope)) { return BadRequest(); }
|
|
|
+ string debateCode =$"{_scope}".Equals("school")? $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}": "Debate";
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
return Ok(new { status=200});
|
|
|
}
|
|
@@ -112,37 +114,43 @@ namespace TEAMModelOS.Controllers
|
|
|
public async Task<IActionResult> Find(JsonElement request) {
|
|
|
try
|
|
|
{
|
|
|
+
|
|
|
List<dynamic> debates = new List<dynamic>();
|
|
|
request.TryGetProperty("source", out JsonElement _source);
|
|
|
request.TryGetProperty("tmdid", out JsonElement _tmdid);
|
|
|
request.TryGetProperty("userType", out JsonElement _userType);
|
|
|
request.TryGetProperty("keyWord", out JsonElement _keyWord);
|
|
|
request.TryGetProperty("comid", out JsonElement _comid);
|
|
|
- if (request.TryGetProperty("code", out JsonElement code))
|
|
|
+ string debateCode = "Debate";
|
|
|
+ if (request.TryGetProperty("code", out JsonElement _code) && !string.IsNullOrWhiteSpace($"{_code}"))
|
|
|
{
|
|
|
- StringBuilder stringBuilder = new StringBuilder($"select c.id,c.code,c.tmdid,c.userType,c.tmdname,c.title,c.comment,c.time,c.comid,c.likeCount,c.school,c.wordCount,c.timeoutReply,c.expire,c.source,c.pk, ARRAY_LENGTH( c.replies ) as replyCount from c where c.pk='Debate' ");
|
|
|
- if (!string.IsNullOrEmpty($"{_source}")) {
|
|
|
- stringBuilder.Append($" and c.source='{_source}'");
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty($"{_tmdid}") && !string.IsNullOrWhiteSpace($"{_userType}"))
|
|
|
- {
|
|
|
- stringBuilder.Append($" and c.tmdid='{_tmdid}' and c.userType='{_userType}'");
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty($"{_keyWord}"))
|
|
|
- {
|
|
|
- stringBuilder.Append($" and contains(c.title,'{_keyWord}') ");
|
|
|
- }
|
|
|
- if (!string.IsNullOrEmpty($"{_comid}"))
|
|
|
- {
|
|
|
- stringBuilder.Append($" and c.comid='{_comid}'");
|
|
|
- }
|
|
|
- stringBuilder.Append("order by c.time desc ");
|
|
|
- await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
|
|
|
- .GetItemQueryIterator<dynamic>(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{code}") }))
|
|
|
- {
|
|
|
- debates.Add(item);
|
|
|
- }
|
|
|
+ debateCode= $"{_code}".StartsWith("Debate-") ? $"{_code}" : $"Debate-{_code}";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ StringBuilder stringBuilder = new StringBuilder($"select c.id,c.code,c.tmdid,c.userType,c.tmdname,c.title,c.comment,c.time,c.comid,c.likeCount,c.school,c.wordCount,c.timeoutReply,c.expire,c.source,c.pk, ARRAY_LENGTH( c.replies ) as replyCount from c where c.pk='Debate' ");
|
|
|
+ if (!string.IsNullOrEmpty($"{_source}")) {
|
|
|
+ stringBuilder.Append($" and c.source='{_source}'");
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty($"{_tmdid}") && !string.IsNullOrWhiteSpace($"{_userType}"))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.tmdid='{_tmdid}' and c.userType='{_userType}'");
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty($"{_keyWord}"))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and contains(c.title,'{_keyWord}') ");
|
|
|
}
|
|
|
+ if (!string.IsNullOrEmpty($"{_comid}"))
|
|
|
+ {
|
|
|
+ stringBuilder.Append($" and c.comid='{_comid}'");
|
|
|
+ }
|
|
|
+ stringBuilder.Append("order by c.time desc ");
|
|
|
+ await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
|
|
|
+ .GetItemQueryIterator<dynamic>(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(debateCode) }))
|
|
|
+ {
|
|
|
+ debates.Add(item);
|
|
|
+ }
|
|
|
+
|
|
|
return Ok(debates);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -191,10 +199,14 @@ namespace TEAMModelOS.Controllers
|
|
|
if (!request.TryGetProperty("opt", out JsonElement _opt)) { return BadRequest(); }
|
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
|
-
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement _scope )) { return BadRequest(); }
|
|
|
DebateReply reply = null;
|
|
|
+
|
|
|
string debateCode = $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}";
|
|
|
- if (!string.IsNullOrEmpty($"{_debateId}") && !string.IsNullOrEmpty($"{_debateCode}") && !string.IsNullOrEmpty($"{_opt}"))
|
|
|
+ if (_scope.Equals("private")) {
|
|
|
+ debateCode="Debate";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrEmpty($"{_debateId}") && !string.IsNullOrEmpty($"{debateCode}") && !string.IsNullOrEmpty($"{_opt}"))
|
|
|
{
|
|
|
switch ($"{_opt}")
|
|
|
{
|
|
@@ -331,7 +343,6 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "teacher")]
|
|
|
[HttpPost("upsert")]
|
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
|
|
|
@@ -339,6 +350,8 @@ namespace TEAMModelOS.Controllers
|
|
|
[Authorize(Roles = "IES")]
|
|
|
#endif
|
|
|
public async Task<IActionResult> upsert(JsonElement request) {
|
|
|
+
|
|
|
+ var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
|
|
|
/// 评论/话题的统一id,用于被关联
|
|
|
request.TryGetProperty("comid", out JsonElement _comid);
|
|
|
/// 创建来源
|
|
@@ -364,6 +377,15 @@ namespace TEAMModelOS.Controllers
|
|
|
else {
|
|
|
debate.code = debate.code.StartsWith("Debate-") ? debate.code : $"Debate-{debate.code}";
|
|
|
}
|
|
|
+ ///个人的不建立分区键
|
|
|
+ if (debate.code.Contains(tid)) {
|
|
|
+ debate.scope="private";
|
|
|
+ debate.code="Debate";
|
|
|
+ }
|
|
|
+ if (!string.IsNullOrWhiteSpace(tschool) && debate.code.Contains(tschool))
|
|
|
+ {
|
|
|
+ debate.scope="school";
|
|
|
+ }
|
|
|
if (string.IsNullOrEmpty(debate.id)) {
|
|
|
debate.id = Guid.NewGuid().ToString();
|
|
|
debate.time= DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|