Skip to content

Commit

Permalink
modify api code based on new view
Browse files Browse the repository at this point in the history
  • Loading branch information
mla04762 committed Jul 21, 2023
1 parent ab1802b commit 51d566b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion Gordon360/Controllers/ScheduleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public async Task<ActionResult<JArray>> GetAsync(string username, [FromQuery] st
/// </summary>
/// <returns>A IEnumerable of session objects as well as the schedules</returns>
[HttpGet]
[AllowAnonymous]
[Route("{username}/allcourses")]
public async Task<ActionResult<SessionCoursesViewModel>> GetAllCourses(string username)
{
Expand Down
4 changes: 0 additions & 4 deletions Gordon360/Models/ViewModels/UserCoursesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Gordon360.Models.ViewModels
public class UserCoursesViewModel
{
public string UserID { get; set; }
public int STUDENT_ID { get; set; }
public int? INSTRUCTOR_ID { get; set; }
public string SessionCode { get; set; }
public string CRS_CDE { get; set; }
public string CRS_TITLE { get; set; }
Expand Down Expand Up @@ -42,8 +40,6 @@ public static implicit operator UserCoursesViewModel(UserCourses course)
UserCoursesViewModel vm = new UserCoursesViewModel
{
UserID =course.UserID,
STUDENT_ID = course.STUDENT_ID,
INSTRUCTOR_ID = course.INSTRUCTOR_ID,
SessionCode = code,
CRS_CDE = course.CRS_CDE,
CRS_TITLE = course.CRS_TITLE,
Expand Down
10 changes: 6 additions & 4 deletions Gordon360/Services/ScheduleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ public async Task<IEnumerable<SessionCoursesViewModel>> GetAllCourses(string use
{
throw new ResourceNotFoundException() { ExceptionMessage = "The account was not found." };
}

var allSessions = _sessionService.GetAll();
var result = Enumerable.Empty<SessionCoursesViewModel>();
var allSchedule = _context.UserCourses
.Where(s => s.UserID == account.gordon_id).OrderByDescending(s => s.YR_CDE);

.Where(s => s.UserID == account.gordon_id)
.Select(s => (UserCoursesViewModel)s)
.ToList()
.OrderByDescending(course => course.SessionCode)
.DistinctBy(s => s.CRS_CDE);

foreach (SessionViewModel vm in allSessions)
{
Expand All @@ -124,7 +126,7 @@ public async Task<IEnumerable<SessionCoursesViewModel>> GetAllCourses(string use
SessionDescription = vm.SessionDescription,
SessionBeginDate = vm.SessionBeginDate,
SessionEndDate = vm.SessionEndDate,
AllCourses = allSchedule.Select(s => (UserCoursesViewModel)s)
AllCourses = allSchedule.Where(s => s.SessionCode == vm.SessionCode)
});
}
return result;
Expand Down

0 comments on commit 51d566b

Please sign in to comment.