Skip to content

Commit

Permalink
Merge pull request #977 from gordon-cs/s23-add-new-route-for-term-sel…
Browse files Browse the repository at this point in the history
…ector

Create new route for getting all sessions and schedules
  • Loading branch information
mla04762 authored Jul 20, 2023
2 parents d55408b + e6f0e9a commit 4f6b2e8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Gordon360/Controllers/ScheduleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Gordon360.Models.CCT.Context;
using Gordon360.Models.ViewModels;
using Gordon360.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
Expand Down Expand Up @@ -116,6 +117,23 @@ public async Task<ActionResult<JArray>> GetAsync(string username, [FromQuery] st
return Ok(result);
}

/// <summary>
/// Gets all session objects for a user
/// </summary>
/// <returns>A IEnumerable of session objects as well as the schedules</returns>
[HttpGet]
[Route("{username}/allcourses")]
public async Task<ActionResult<SessionCoursesViewModel>> GetAllCourses(string username)
{
var result = await _scheduleService.GetAllCourses(username);
if (result == null)
{
return NotFound();
}
return Ok(result);

}

/// <summary>
/// Get whether the currently logged-in user can read student schedules
/// </summary>
Expand Down
19 changes: 19 additions & 0 deletions Gordon360/Models/ViewModels/SessionCoursesViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Gordon360.Models.CCT;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Gordon360.Models.ViewModels
{
public class SessionCoursesViewModel
{
public string SessionCode { get; set; }
public string SessionDescription { get; set; }
public Nullable<System.DateTime> SessionBeginDate { get; set; }
public Nullable<System.DateTime> SessionEndDate { get; set; }
public IEnumerable <ScheduleViewModel> AllCourses { get; set; }
}


}
41 changes: 41 additions & 0 deletions Gordon360/Services/ScheduleService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Gordon360.Exceptions;
using Gordon360.Models.CCT;
using Gordon360.Models.CCT.Context;
using Gordon360.Models.ViewModels;
using Gordon360.Static.Methods;
using Microsoft.Graph.CallRecords;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -14,10 +16,12 @@ namespace Gordon360.Services
public class ScheduleService : IScheduleService
{
private readonly CCTContext _context;
private readonly ISessionService _sessionService;

public ScheduleService(CCTContext context)
{
_context = context;
_sessionService = new SessionService(context);
}

/// <summary>
Expand Down Expand Up @@ -89,5 +93,42 @@ public async Task<IEnumerable<ScheduleViewModel>> GetScheduleFacultyAsync(string
END_TIME = x.END_TIME
});
}

/// <summary>
/// Fetch the session item whose id specified by the parameter
/// </summary>
/// <param name="username">The AD Username of the user</param>
/// <returns>SessionCoursesViewModel if found, null if not found</returns>
public async Task<IEnumerable<SessionCoursesViewModel>> GetAllCourses(string username)
{
var account = _context.ACCOUNT.FirstOrDefault(x => x.AD_Username == username);
var allSessions = _sessionService.GetAll();
var result = Enumerable.Empty<SessionCoursesViewModel>();

if (account == null)
{
throw new ResourceNotFoundException() { ExceptionMessage = "The account was not found." };
}


foreach (SessionViewModel vm in allSessions)
{
result = result.Append(
new SessionCoursesViewModel
{
SessionCode = vm.SessionCode,
SessionDescription = vm.SessionDescription,
SessionBeginDate = vm.SessionBeginDate,
SessionEndDate = vm.SessionEndDate,
//The case for "ALUMNI" does not work at the moment currently, but it doesn't affect the code,
//and might be used in the future, so we decided to leave it in.
AllCourses = account.account_type == "STUDENT" || account.account_type == "ALUMNI"
? await GetScheduleStudentAsync(username, vm.SessionCode)
: await GetScheduleFacultyAsync(username, vm.SessionCode),
});
}
return result;

}
}
}
1 change: 1 addition & 0 deletions Gordon360/Services/ServiceInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public interface IScheduleService
{
Task<IEnumerable<ScheduleViewModel>> GetScheduleStudentAsync(string username, string? sessionID = null);
Task<IEnumerable<ScheduleViewModel>> GetScheduleFacultyAsync(string username, string? sessionID = null);
Task<IEnumerable<SessionCoursesViewModel>> GetAllCourses(string username);
}

public interface IScheduleControlService
Expand Down

0 comments on commit 4f6b2e8

Please sign in to comment.