|
@@ -36,7 +36,7 @@ namespace TEAMModelOS.Controllers
|
|
_option = option?.Value; ;
|
|
_option = option?.Value; ;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 查询所有话题
|
|
|
|
|
|
+ /// 查询话题
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
@@ -54,8 +54,9 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
|
|
+ string debateCode = $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}";
|
|
List<dynamic> debates = new List<dynamic>();
|
|
List<dynamic> debates = new List<dynamic>();
|
|
- Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{_debateCode}"));
|
|
|
|
|
|
+ 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});
|
|
return Ok(new { debate = debate , replyCount = debate.replies!=null ?debate.replies.Count:0});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -72,9 +73,10 @@ namespace TEAMModelOS.Controllers
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
//[AuthToken(Roles = "teacher")]
|
|
//[AuthToken(Roles = "teacher")]
|
|
[HttpPost("delete")]
|
|
[HttpPost("delete")]
|
|
|
|
+#if !DEBUG
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
[AuthToken(Roles = "teacher,admin,student")]
|
|
|
|
|
|
-#if !DEBUG
|
|
|
|
|
|
+
|
|
[Authorize(Roles = "IES")]
|
|
[Authorize(Roles = "IES")]
|
|
#endif
|
|
#endif
|
|
public async Task<IActionResult> Delete(JsonElement request)
|
|
public async Task<IActionResult> Delete(JsonElement request)
|
|
@@ -83,13 +85,13 @@ namespace TEAMModelOS.Controllers
|
|
{
|
|
{
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
- List<dynamic> debates = new List<dynamic>();
|
|
|
|
- await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").DeleteItemAsync<Debate>($"{_debateId}", new PartitionKey($"{_debateCode}"));
|
|
|
|
|
|
+ string debateCode = $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}";
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
return Ok(new { status=200});
|
|
return Ok(new { status=200});
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
- await _dingDing.SendBotMsg($"OS,{_option.Location},DebateController,school/debate/delete\n{ex.Message}\n{ex.StackTrace}", GroupNames.醍摩豆服務運維群組);
|
|
|
|
|
|
+ await _dingDing.SendBotMsg($"OS,{_option.Location},DebateController,school/debate/delete\n{ex.Message}\n{ex.StackTrace}{request.ToJsonString()}", GroupNames.醍摩豆服務運維群組);
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -113,21 +115,28 @@ namespace TEAMModelOS.Controllers
|
|
List<dynamic> debates = new List<dynamic>();
|
|
List<dynamic> debates = new List<dynamic>();
|
|
request.TryGetProperty("source", out JsonElement _source);
|
|
request.TryGetProperty("source", out JsonElement _source);
|
|
request.TryGetProperty("tmdid", out JsonElement _tmdid);
|
|
request.TryGetProperty("tmdid", out JsonElement _tmdid);
|
|
|
|
+ request.TryGetProperty("userType", out JsonElement _userType);
|
|
|
|
+ request.TryGetProperty("keyWord", out JsonElement _keyWord);
|
|
request.TryGetProperty("comid", out JsonElement _comid);
|
|
request.TryGetProperty("comid", out JsonElement _comid);
|
|
if (request.TryGetProperty("code", out JsonElement code))
|
|
if (request.TryGetProperty("code", out JsonElement code))
|
|
{
|
|
{
|
|
- StringBuilder stringBuilder = new StringBuilder($"select c.id,c.code,c.tmdid,c.tmdname,c.title,c.comment,c.time,c.comid,c.likeCount,c.school,c.likes,c.wordCount,c.timeoutReply,c.expire,c.source,c.pk, ARRAY_LENGTH( c.replies ) as replyCount from c where c.pk='Debate' ");
|
|
|
|
|
|
+ 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}")) {
|
|
if (!string.IsNullOrEmpty($"{_source}")) {
|
|
stringBuilder.Append($" and c.source='{_source}'");
|
|
stringBuilder.Append($" and c.source='{_source}'");
|
|
}
|
|
}
|
|
- if (!string.IsNullOrEmpty($"{_tmdid}"))
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty($"{_tmdid}") && !string.IsNullOrWhiteSpace($"{_userType}"))
|
|
|
|
+ {
|
|
|
|
+ stringBuilder.Append($" and c.tmdid='{_tmdid}' and c.userType='{_userType}'");
|
|
|
|
+ }
|
|
|
|
+ if (!string.IsNullOrEmpty($"{_keyWord}"))
|
|
{
|
|
{
|
|
- stringBuilder.Append($" and c.tmdid='{_tmdid}'");
|
|
|
|
|
|
+ stringBuilder.Append($" and contains(c.title,'{_keyWord}') ");
|
|
}
|
|
}
|
|
if (!string.IsNullOrEmpty($"{_comid}"))
|
|
if (!string.IsNullOrEmpty($"{_comid}"))
|
|
{
|
|
{
|
|
stringBuilder.Append($" and c.comid='{_comid}'");
|
|
stringBuilder.Append($" and c.comid='{_comid}'");
|
|
}
|
|
}
|
|
|
|
+ stringBuilder.Append("order by c.time desc ");
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School")
|
|
.GetItemQueryIterator<dynamic>(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{code}") }))
|
|
.GetItemQueryIterator<dynamic>(queryText: stringBuilder.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Debate-{code}") }))
|
|
{
|
|
{
|
|
@@ -176,14 +185,15 @@ namespace TEAMModelOS.Controllers
|
|
[ProducesDefaultResponseType]
|
|
[ProducesDefaultResponseType]
|
|
[HttpPost("reply")]
|
|
[HttpPost("reply")]
|
|
[Authorize(Roles = "IES")]
|
|
[Authorize(Roles = "IES")]
|
|
- [AuthToken(Roles = "admin,teacher")]
|
|
|
|
|
|
+ [AuthToken(Roles = "admin,teacher,student")]
|
|
public async Task<IActionResult> reply(JsonElement request) {
|
|
public async Task<IActionResult> reply(JsonElement request) {
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
var (userid, _, _, school) = HttpContext.GetAuthTokenInfo();
|
|
if (!request.TryGetProperty("opt", out JsonElement _opt)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("opt", out JsonElement _opt)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateId", out JsonElement _debateId)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
if (!request.TryGetProperty("debateCode", out JsonElement _debateCode)) { return BadRequest(); }
|
|
- if (!request.TryGetProperty("reply", out JsonElement _reply)) { return BadRequest(); }
|
|
|
|
|
|
+
|
|
DebateReply reply = null;
|
|
DebateReply reply = null;
|
|
|
|
+ string debateCode = $"{_debateCode}".StartsWith("Debate-") ? $"{_debateCode}" : $"Debate-{_debateCode}";
|
|
if (!string.IsNullOrEmpty($"{_debateId}") && !string.IsNullOrEmpty($"{_debateCode}") && !string.IsNullOrEmpty($"{_opt}"))
|
|
if (!string.IsNullOrEmpty($"{_debateId}") && !string.IsNullOrEmpty($"{_debateCode}") && !string.IsNullOrEmpty($"{_opt}"))
|
|
{
|
|
{
|
|
switch ($"{_opt}")
|
|
switch ($"{_opt}")
|
|
@@ -191,25 +201,76 @@ namespace TEAMModelOS.Controllers
|
|
case "add":
|
|
case "add":
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{_debateCode}"));
|
|
|
|
|
|
+ if (!request.TryGetProperty("reply", out JsonElement _reply)) { return BadRequest(); }
|
|
|
|
+ Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
reply = _reply.ToObject<DebateReply>();
|
|
reply = _reply.ToObject<DebateReply>();
|
|
reply.pid = string.IsNullOrEmpty(reply.pid) ? $"{_debateId}" : reply.pid;
|
|
reply.pid = string.IsNullOrEmpty(reply.pid) ? $"{_debateId}" : reply.pid;
|
|
reply.id = string.IsNullOrEmpty(reply.id) ? Guid.NewGuid().ToString() : reply.id;
|
|
reply.id = string.IsNullOrEmpty(reply.id) ? Guid.NewGuid().ToString() : reply.id;
|
|
reply.time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
reply.time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
debate.replies.Add(reply);
|
|
debate.replies.Add(reply);
|
|
- await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, $"{_debateId}", new PartitionKey($"{_debateCode}"));
|
|
|
|
|
|
+ debate.likeCount = debate.replies.SelectMany(z => z.likes).Count();
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, $"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
return Ok(new { reply , replyCount = debate.replies.Count });
|
|
return Ok(new { reply , replyCount = debate.replies.Count });
|
|
}
|
|
}
|
|
catch (CosmosException ex)
|
|
catch (CosmosException ex)
|
|
{
|
|
{
|
|
return BadRequest();
|
|
return BadRequest();
|
|
}
|
|
}
|
|
|
|
+ case "like":
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
|
+ if (!request.TryGetProperty("likeData", out JsonElement _likeData)) { return BadRequest(); }
|
|
|
|
+ LikeRcd likeRcd = _likeData.ToObject<LikeRcd>();
|
|
|
|
+ if (likeRcd != null && !string.IsNullOrWhiteSpace(likeRcd.replyId))
|
|
|
|
+ {
|
|
|
|
+ var replyData = debate.replies.Find(x => $"{likeRcd.replyId}".Equals(x.id));
|
|
|
|
+ var like = replyData.likes.FindAll(c => !string.IsNullOrWhiteSpace(c.tmdid) && c.tmdid.Equals(likeRcd.tmdid) && !string.IsNullOrWhiteSpace(c.userType) && c.userType.Equals(likeRcd.userType));
|
|
|
|
+ if (like.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ replyData.likes.Add(likeRcd);
|
|
|
|
+ }
|
|
|
|
+ debate.likeCount = debate.replies.SelectMany(z => z.likes).Count();
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, $"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
|
+ return Ok(new { reply, replyCount = debate.replies.Count });
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (CosmosException ex)
|
|
|
|
+ {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ case "unlike":
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
|
+ if (!request.TryGetProperty("likeData", out JsonElement _likeData)) { return BadRequest(); }
|
|
|
|
+ LikeRcd likeRcd = _likeData.ToObject<LikeRcd>();
|
|
|
|
+ if (likeRcd != null && !string.IsNullOrWhiteSpace(likeRcd.replyId))
|
|
|
|
+ {
|
|
|
|
+ var replyData = debate.replies.Find(x => $"{likeRcd.replyId}".Equals(x.id) );
|
|
|
|
+ replyData.likes.RemoveAll(c => !string.IsNullOrWhiteSpace(c.tmdid) && c.tmdid.Equals(likeRcd.tmdid) && !string.IsNullOrWhiteSpace(c.userType) && c.userType.Equals(likeRcd.userType));
|
|
|
|
+ debate.likeCount = debate.replies.SelectMany(z => z.likes).Count();
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, $"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
|
+ return Ok(new { reply, replyCount = debate.replies.Count });
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (CosmosException ex)
|
|
|
|
+ {
|
|
|
|
+ return BadRequest();
|
|
|
|
+ }
|
|
case "del":
|
|
case "del":
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{_debateCode}"));
|
|
|
|
- reply = _reply.ToObject<DebateReply>();
|
|
|
|
- var findall = debate.replies.FindAll(x => reply.id .Equals(x.id));
|
|
|
|
|
|
+ Debate debate = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReadItemAsync<Debate>($"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
|
|
+ if (!request.TryGetProperty("replyId", out JsonElement _replyId)) { return BadRequest(); }
|
|
|
|
+ var findall = debate.replies.FindAll(x => $"{_replyId}" .Equals(x.id));
|
|
if (findall.IsNotEmpty())
|
|
if (findall.IsNotEmpty())
|
|
{
|
|
{
|
|
foreach (var find in findall)
|
|
foreach (var find in findall)
|
|
@@ -223,7 +284,8 @@ namespace TEAMModelOS.Controllers
|
|
return Ok(new { status = 2, replyCount = debate.replies.Count });
|
|
return Ok(new { status = 2, replyCount = debate.replies.Count });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, $"{_debateId}", new PartitionKey($"{_debateCode}"));
|
|
|
|
|
|
+ debate.likeCount = debate.replies.SelectMany(z => z.likes).Count();
|
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync<Debate>(debate, $"{_debateId}", new PartitionKey($"{debateCode}"));
|
|
//删除成功
|
|
//删除成功
|
|
return Ok(new { status = 0 , replyCount = debate.replies.Count });
|
|
return Ok(new { status = 0 , replyCount = debate.replies.Count });
|
|
}
|
|
}
|
|
@@ -314,8 +376,6 @@ namespace TEAMModelOS.Controllers
|
|
///保证记录回复记录和点赞记录正常
|
|
///保证记录回复记录和点赞记录正常
|
|
debate.replies = _DBdebate.replies;
|
|
debate.replies = _DBdebate.replies;
|
|
debate.likeCount = _DBdebate.likeCount;
|
|
debate.likeCount = _DBdebate.likeCount;
|
|
- debate.likes = _DBdebate.likes;
|
|
|
|
- debate.replies = _DBdebate.replies;
|
|
|
|
await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(debate, debate.id, new PartitionKey(debate.code));
|
|
await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "School").ReplaceItemAsync(debate, debate.id, new PartitionKey(debate.code));
|
|
}
|
|
}
|
|
catch (CosmosException ex) {
|
|
catch (CosmosException ex) {
|