|
@@ -64,6 +64,7 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("update-lesson-baseinfo")]
|
|
|
+ [AuthToken(Roles = "admin,teacher")]
|
|
|
public async Task<IActionResult> UpdateLessonBaseInfo(JsonElement request)
|
|
|
{
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -163,6 +164,7 @@ namespace TEAMModelOS.Controllers
|
|
|
// [AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("delete-lesson-record")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "admin,teacher")]
|
|
|
public async Task<IActionResult> DeleteLessonRecord(JsonElement request)
|
|
|
{
|
|
|
string lessonId;
|
|
@@ -228,9 +230,16 @@ namespace TEAMModelOS.Controllers
|
|
|
//[AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-lesson-record-count")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "admin,teacher,student")]
|
|
|
public async Task<IActionResult> GetLessonRecordCont(JsonElement request)
|
|
|
{
|
|
|
-
|
|
|
+ object _roles = null;
|
|
|
+ HttpContext?.Items.TryGetValue("Roles", out _roles);
|
|
|
+ List<string> roles = new List<string>();
|
|
|
+ if (_roles != null)
|
|
|
+ {
|
|
|
+ roles = _roles.ToJsonString().ToObject<List<string>>();
|
|
|
+ }
|
|
|
if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
sql.Append("select value(count(1)) from c ");
|
|
@@ -269,7 +278,13 @@ namespace TEAMModelOS.Controllers
|
|
|
return BadRequest();
|
|
|
}
|
|
|
int count=0;
|
|
|
- cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>404 or IS_DEFINED(c.status) = false ) and ");
|
|
|
+
|
|
|
+ string sqlShow = "";
|
|
|
+ if (roles.Count == 1 && roles.Contains("student"))
|
|
|
+ {
|
|
|
+ sqlShow = " and array_contains(c.show,'student') ";
|
|
|
+ }
|
|
|
+ cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and ");
|
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).GetItemQueryIterator<int>(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey(code) }))
|
|
|
{
|
|
|
count = item;
|
|
@@ -283,10 +298,69 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
// [AuthToken(Roles = "teacher,admin")]
|
|
|
+ [HttpPost("get-lesson-record-id")]
|
|
|
+ [Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "admin,teacher,student")]
|
|
|
+ public async Task<IActionResult> GetLessonRecordId(JsonElement request) {
|
|
|
+ if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("id", out JsonElement _id)) return BadRequest();
|
|
|
+ string tbname = "";
|
|
|
+ string code = "";
|
|
|
+ if (_scope.GetString().Equals("school"))
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("school", out JsonElement _school)) return BadRequest();
|
|
|
+ if (!string.IsNullOrEmpty($"{_school}"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{_school}";
|
|
|
+ tbname = "School";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if ($"{_scope}".Equals("private"))
|
|
|
+ {
|
|
|
+ if (!request.TryGetProperty("tmdid", out JsonElement _tmdid)) return BadRequest();
|
|
|
+ if (!string.IsNullOrEmpty($"{_tmdid}"))
|
|
|
+ {
|
|
|
+ code = $"LessonRecord-{_tmdid}";
|
|
|
+ tbname = "Teacher";
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ LessonRecord lessonRecord = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname).ReadItemAsync<LessonRecord>($"{_id}", new PartitionKey(code));
|
|
|
+ return Ok(new { lessonRecord });
|
|
|
+ } catch (CosmosException ex) when (ex.Status == 404) {
|
|
|
+ return Ok(new { status =404});
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取开课记录
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="request"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ // [AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-lesson-record")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles ="admin,teacher,student")]
|
|
|
public async Task<IActionResult> GetLessonRecord(JsonElement request)
|
|
|
{
|
|
|
+ object _roles = null;
|
|
|
+ HttpContext?.Items.TryGetValue("Roles", out _roles);
|
|
|
+ List<string> roles = new List<string>();
|
|
|
+ if (_roles != null) {
|
|
|
+ roles = _roles.ToJsonString().ToObject<List<string>>();
|
|
|
+ }
|
|
|
if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
sql.Append("select value(c) from c ");
|
|
@@ -354,7 +428,11 @@ namespace TEAMModelOS.Controllers
|
|
|
List<LessonRecord> lessonRecords = new List<LessonRecord>();
|
|
|
try
|
|
|
{
|
|
|
- cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", " where (c.status<>404 or IS_DEFINED(c.status) = false ) and ");
|
|
|
+ string sqlShow = "";
|
|
|
+ if (roles.Count == 1 && roles.Contains("student") ) {
|
|
|
+ sqlShow = " and array_contains(c.show,'student') ";
|
|
|
+ }
|
|
|
+ cosmosDbQuery.QueryText = cosmosDbQuery.QueryText.Replace("where", $" where (c.status<>404 or IS_DEFINED(c.status) = false ) {sqlShow} and ");
|
|
|
await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, tbname)
|
|
|
.GetItemQueryStreamIterator(queryDefinition: cosmosDbQuery.CosmosQueryDefinition, continuationToken: continuationToken,
|
|
|
requestOptions: new QueryRequestOptions() { MaxItemCount = pageCount, PartitionKey = new PartitionKey(code) }))
|
|
@@ -434,6 +512,7 @@ namespace TEAMModelOS.Controllers
|
|
|
// [AuthToken(Roles = "teacher,admin")]
|
|
|
[HttpPost("get-other-lesson-record")]
|
|
|
[Authorize(Roles = "IES")]
|
|
|
+ [AuthToken(Roles = "admin,teacher,student")]
|
|
|
public async Task<IActionResult> GetOtherLessonRecord(JsonElement request)
|
|
|
{
|
|
|
if (!request.TryGetProperty("scope", out JsonElement _scope)) return BadRequest();
|