|
@@ -75,11 +75,11 @@ namespace TEAMModelAPI.Controllers
|
|
|
return Ok(new { error = 1, msg = "学段不存在!" });
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("upsert-course-info")]
|
|
|
- [ApiToken(Auth = "1302", Name = "课程详细信息", RW = "R", Limit = false)]
|
|
|
+ [ApiToken(Auth = "1302", Name = "课程详细信息", RW = "W", Limit = false)]
|
|
|
public async Task<IActionResult> UpsertCourseInfo(JsonElement json)
|
|
|
{
|
|
|
var (id, school) = HttpContext.GetApiTokenInfo();
|
|
@@ -102,19 +102,53 @@ namespace TEAMModelAPI.Controllers
|
|
|
id = Guid.NewGuid().ToString(),
|
|
|
code = $"Course-{school}",
|
|
|
name = courseDto.name,
|
|
|
- subject = new SubjectSimple { id = subject.id, name = subject.name },
|
|
|
- period= new PeriodSimple { id = period.id, name = period.name },
|
|
|
-
|
|
|
+ subject = new SubjectSimple { id = subject.id, name = subject.name },
|
|
|
+ period = new PeriodSimple { id = period.id, name = period.name },
|
|
|
+ school = school,
|
|
|
+ desc = courseDto.desc,
|
|
|
+ scope = "school",
|
|
|
+ no = courseDto.no,
|
|
|
};
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
-
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{course.id}", new PartitionKey($"Course-{school}"));
|
|
|
+ if (response.Status == 200)
|
|
|
+ {
|
|
|
+ JsonDocument jsonDocument = JsonDocument.Parse(response.Content);
|
|
|
+ course = jsonDocument.RootElement.ToObject<Course>();
|
|
|
+ course.pk = "Course";
|
|
|
+ course.name = string.IsNullOrWhiteSpace(courseDto.name) ? course.name : courseDto.name;
|
|
|
+ course.subject = new SubjectSimple { id = subject.id, name = subject.name };
|
|
|
+ course.period = new PeriodSimple { id = period.id, name = period.name };
|
|
|
+ course.school = school;
|
|
|
+ course.desc = string.IsNullOrWhiteSpace(courseDto.desc) ? course.desc : courseDto.desc;
|
|
|
+ course.scope = "school";
|
|
|
+ course.no = string.IsNullOrWhiteSpace(courseDto.no) ? course.no : courseDto.no;
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ course = new Course
|
|
|
+ {
|
|
|
+ pk = "Course",
|
|
|
+ id = Guid.NewGuid().ToString(),
|
|
|
+ code = $"Course-{school}",
|
|
|
+ name = courseDto.name,
|
|
|
+ subject = new SubjectSimple { id = subject.id, name = subject.name },
|
|
|
+ period = new PeriodSimple { id = period.id, name = period.name },
|
|
|
+ school = school,
|
|
|
+ desc = courseDto.desc,
|
|
|
+ scope = "school",
|
|
|
+ no = courseDto.no,
|
|
|
+ };
|
|
|
+ await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, Constant.School).CreateItemAsync(course, new PartitionKey(course.code));
|
|
|
+ }
|
|
|
}
|
|
|
- return Ok(new { period.subjects, period.timetable, period.grades, period.majors });
|
|
|
+ return Ok(new { period.subjects, period.timetable, course = course });
|
|
|
}
|
|
|
else {
|
|
|
- return Ok(new { error = 2, msg = "科目不存在!" });
|
|
|
+ return Ok(new { error =4, msg = "科目不存在!" });
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -126,8 +160,20 @@ namespace TEAMModelAPI.Controllers
|
|
|
{
|
|
|
return Ok(new { error = 3, msg = courseDto.Valid() });
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
+ [ProducesDefaultResponseType]
|
|
|
+ [HttpPost("upsert-course-schedule")]
|
|
|
+ [ApiToken(Auth = "1302", Name = "更新课程的排课信息", RW = "W", Limit = false)]
|
|
|
+ public async Task<IActionResult> UpsertCourseSchedule(JsonElement json)
|
|
|
+ {
|
|
|
+ var (id, school) = HttpContext.GetApiTokenInfo();
|
|
|
+ if (!json.TryGetProperty("courseId", out JsonElement _courseId)) { return Ok(new { error = 1, msg = "课程参数错误" }); }
|
|
|
+ School data = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemAsync<School>(school, new PartitionKey("Base"));
|
|
|
+ Azure.Response response = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "School").ReadItemStreamAsync($"{_courseId}", new PartitionKey($"Course-{school}"));
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("get-course-list")]
|
|
|
[ApiToken(Auth = "1303", Name = "获取课程列表信息", RW = "R", Limit = false)]
|