Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
李博修 committed Jan 25, 2021
2 parents 2db0b8c + 159f89f commit 547eaf7
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 33 deletions.
17 changes: 5 additions & 12 deletions code/back/LoveCraft.Kshub/Controllers/CourseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public async ValueTask AddStudentAsync(Guid CourseId,List<Guid> StuIds)
{
await _kshubService.KshubUserServices.CheckAuth(HttpContext, KshubRoles.Teacher);
var filter = Builders<Course>.Filter.Eq(t => t.Id, courseId);
var teacherIds = await _kshubService.CourseServices.FindFirstAsync(t=>t.Id==courseId,t=>t.TeachersIds);
var teacherIds = await _kshubService.CourseServices.FindFirstAsync(t=>t.Id==courseId,t=>t.TeachersId);
if (!teacherIds.Contains(Guid.Parse(User.Identity.Name))){
throw new _403Exception("You can't set ScoreRating");
}
Expand Down Expand Up @@ -169,23 +169,16 @@ public async ValueTask GetStudentsAsync()
}
[HttpGet]
[Route("GetTeachers")]
public async ValueTask<IEnumerable<UserDetailDto>> GetTeachersAsync(GetTeacherDto getTeacherDto)
public async ValueTask GetTeachersAsync()
{
var teacherIds =await _kshubService.CourseServices.GetTeacherIdsAsync(getTeacherDto.CourseId);
List<UserDetailDto> lists = new List<UserDetailDto>();
foreach(var item in teacherIds)
{
var Dto = _mapper.Map<UserDetailDto>(await _kshubService.KshubUserServices.GetUserById(item));
lists.Add(Dto);
}
return lists;
throw new NotImplementedException();
}
[HttpPost]
[Route("AddTeacher")]
//Add teacher in Update
public async ValueTask AddTeacherAsync(AddTeacherDto addTeacherDto)
public async ValueTask AddTeacherAsync()
{
await _kshubService.CourseServices.CreateTeacher(addTeacherDto.CourseId, addTeacherDto.TeacherId);
throw new NotImplementedException();
}
}
}
1 change: 0 additions & 1 deletion code/back/LoveCraft.Kshub/Controllers/KsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public async ValueTask AddKsAsync(AddKsDto addKsDto)
ks.Id = Guid.NewGuid();
var user = await _kshubService.KshubUserServices.FindUserAsync(User.Identity.Name);
ks.CollegeId= user.CollegeId;

await _kshubService.KsServices.AddAsync(ks);
}

Expand Down
2 changes: 1 addition & 1 deletion code/back/LoveCraft.Kshub/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async ValueTask<UserDetailDto> LogIn(LogInDto logInDto,bool rememberMe)
catch (Exception)
{
throw new _500Exception();
}
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion code/back/LoveCraft.Kshub/Dto/UserDetailDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace LoveCraft.Kshub.Dto
public class UserDetailDto
{
public string Name { get; set; }
public string Id { get; set; }
public string UserId { get; set; }
public string SchoolName { get; set; }
public string Introduction { get; set; }
public string Email { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion code/back/LoveCraft.Kshub/Models/Course.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Course : Entity, ISearchAble
//the following prosperies will be removed when Groups finished
public Guid BelongedCollegeId { get; set; }
//All a few teacher to manager the same course
public List<Guid> TeachersIds { get; set; }
public List<Guid> TeachersId { get; set; }
public List<Guid> StudentsID { get; set; }
//---------------------------------------------------
}
Expand Down
25 changes: 10 additions & 15 deletions code/back/LoveCraft.Kshub/Services/CourseServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class CourseServices:DbQueryServices<Course>
{
public CourseServices(IDatabaseSettings databaseSettings)
: base(databaseSettings, databaseSettings.CourseCollection) { }


/// <summary>
/// Add a course which not exist in current college
/// </summary>
/// <param name="course"></param>
/// <returns></returns>
public async ValueTask<Course> AddCourseWithoutCheckingAsync(Course course)
{
await collection.InsertOneAsync(course);
Expand All @@ -28,25 +35,13 @@ public async ValueTask DeleteCourseAsync(Guid guid)
}
public async ValueTask RemoveTeacherAsync(Guid courseId,Guid teacherId)
{
var course =await collection.Find(t => t.Id == courseId).FirstAsync();
if (!course.TeachersIds.Remove(teacherId))
var teachers =await collection.Find(t => t.Id == courseId).FirstAsync();
if (!teachers.TeachersId.Remove(teacherId))
{
throw new _401Exception("No such Teacher in this course");
}
var update = Builders<Course>.Update.Set(t => t,course);
var update = Builders<Course>.Update.Set(t => t,teachers);
await collection.UpdateOneAsync(t => t.Id == courseId,update);
}
public async ValueTask CreateTeacher(Guid courseId, Guid teacherId)
{
var course = await collection.Find(t => t.Id == courseId).FirstAsync();
course.TeachersIds.Add(teacherId);
var update = Builders<Course>.Update.Set(t => t, course);
await collection.UpdateOneAsync(t => t.Id == courseId, update);
}
public async ValueTask<List<Guid>> GetTeacherIdsAsync(Guid courseId)
{
var course = await collection.Find(t => t.Id == courseId).FirstAsync();
return course.TeachersIds;
}
}
}
3 changes: 1 addition & 2 deletions code/back/LoveCraft.Kshub/Services/UserServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public async ValueTask<KshubUser> FindUserAsync(string userId)
throw new _401Exception("Cannot find this User");
}
}
public async ValueTask<KshubUser> GetUserById(Guid id)
public async ValueTask<KshubUser> FindUserAsync(Guid id)
{
try
{
Expand Down Expand Up @@ -186,6 +186,5 @@ public async ValueTask CheckAuthAsync(string roles,Guid guid)
throw new _403Exception();
}
}

}
}

0 comments on commit 547eaf7

Please sign in to comment.