|
11 | 11 | using System.Threading.Tasks; |
12 | 12 | namespace Gordon360.Controllers; |
13 | 13 |
|
14 | | - [Route("api/[controller]")] |
15 | | - public class ScheduleController(IScheduleService scheduleService) : GordonControllerBase |
| 14 | +[Route("api/[controller]")] |
| 15 | +public class ScheduleController(IScheduleService scheduleService) : GordonControllerBase |
| 16 | +{ |
| 17 | + /// <summary> |
| 18 | + /// Gets all session objects for a user |
| 19 | + /// </summary> |
| 20 | + /// <returns>A IEnumerable of session objects as well as the schedules</returns> |
| 21 | + [HttpGet] |
| 22 | + [Route("{username}/allcourses")] |
| 23 | + [Obsolete("This method is deprecated. Use '/{username}/allcourses-by-term' which is grouped by term.")] |
| 24 | + public async Task<ActionResult<CoursesBySessionViewModel>> GetAllCourses(string username) |
16 | 25 | { |
17 | | - /// <summary> |
18 | | - /// Gets all session objects for a user |
19 | | - /// </summary> |
20 | | - /// <returns>A IEnumerable of session objects as well as the schedules</returns> |
21 | | - [HttpGet] |
22 | | - [Route("{username}/allcourses")] |
23 | | - [Obsolete("This method is deprecated. Use '/{username}/allcourses-by-term' which is grouped by term.")] |
24 | | - public async Task<ActionResult<CoursesBySessionViewModel>> GetAllCourses(string username) |
25 | | - { |
26 | | - var groups = AuthUtils.GetGroups(User); |
27 | | - var authenticatedUsername = AuthUtils.GetUsername(User); |
28 | | - |
29 | | - IEnumerable<CoursesBySessionViewModel> result; |
30 | | - if (authenticatedUsername.EqualsIgnoreCase(username) || groups.Contains(AuthGroup.FacStaff)) |
31 | | - { |
32 | | - result = await scheduleService.GetAllCoursesAsync(username); |
33 | | - } |
34 | | - else |
35 | | - { |
36 | | - result = await scheduleService.GetAllInstructorCoursesAsync(username); |
37 | | - } |
| 26 | + var groups = AuthUtils.GetGroups(User); |
| 27 | + var authenticatedUsername = AuthUtils.GetUsername(User); |
38 | 28 |
|
39 | | - return Ok(result); |
| 29 | + IEnumerable<CoursesBySessionViewModel> result; |
| 30 | + if (authenticatedUsername.EqualsIgnoreCase(username) || groups.Contains(AuthGroup.FacStaff)) |
| 31 | + { |
| 32 | + result = await scheduleService.GetAllCoursesAsync(username); |
40 | 33 | } |
41 | | - |
42 | | - /// <summary> |
43 | | - /// Gets all term objects for a user — only includes published schedules |
44 | | - /// </summary> |
45 | | - /// <returns>A IEnumerable of term objects with their schedules</returns> |
46 | | - [HttpGet] |
47 | | - [Route("{username}/allcourses-by-term")] |
48 | | - [StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.STUDENT_SCHEDULE)] |
49 | | - public async Task<ActionResult<IEnumerable<CoursesByTermViewModel>>> GetAllCoursesByTerm(string username) |
| 34 | + else |
50 | 35 | { |
51 | | - var groups = AuthUtils.GetGroups(User); |
52 | | - var authenticatedUsername = AuthUtils.GetUsername(User); |
| 36 | + result = await scheduleService.GetAllInstructorCoursesAsync(username); |
| 37 | + } |
53 | 38 |
|
54 | | - IEnumerable<CoursesByTermViewModel> result; |
55 | | - if (authenticatedUsername.EqualsIgnoreCase(username) || groups.Contains(AuthGroup.FacStaff)) |
56 | | - { |
57 | | - result = await scheduleService.GetAllCoursesByTermAsync(username); |
58 | | - } |
59 | | - else |
60 | | - { |
61 | | - result = await scheduleService.GetAllInstructorCoursesByTermAsync(username); |
62 | | - } |
| 39 | + return Ok(result); |
| 40 | + } |
63 | 41 |
|
64 | | - // Filter only published terms |
65 | | - var publishedResult = result |
66 | | - .Where(r => r.ShowOnWeb?.Equals("Y", StringComparison.OrdinalIgnoreCase) == true) |
67 | | - .ToList(); |
68 | | - return Ok(publishedResult); |
69 | | - } |
| 42 | + /// <summary> |
| 43 | + /// Gets all term objects for a user — only includes published schedules |
| 44 | + /// </summary> |
| 45 | + /// <returns>A IEnumerable of term objects with their schedules</returns> |
| 46 | + [HttpGet] |
| 47 | + [Route("{username}/allcourses-by-term")] |
| 48 | + [StateYourBusiness(operation = Operation.READ_ONE, resource = Resource.STUDENT_SCHEDULE)] |
| 49 | + public async Task<ActionResult<IEnumerable<CoursesByTermViewModel>>> GetAllCoursesByTerm(string username) |
| 50 | + { |
| 51 | + var groups = AuthUtils.GetGroups(User); |
| 52 | + var authenticatedUsername = AuthUtils.GetUsername(User); |
70 | 53 |
|
71 | | - /// <summary> |
72 | | - /// Get whether the currently logged-in user can read student schedules |
73 | | - /// </summary> |
74 | | - /// <returns>Whether they can read student schedules</returns> |
75 | | - [HttpGet] |
76 | | - [Route("canreadstudent")] |
77 | | - public async Task<ActionResult<bool>> GetCanReadStudentSchedules() |
| 54 | + IEnumerable<CoursesByTermViewModel> result; |
| 55 | + if (authenticatedUsername.EqualsIgnoreCase(username) || groups.Contains(AuthGroup.FacStaff)) |
| 56 | + { |
| 57 | + result = await scheduleService.GetAllCoursesByTermAsync(username); |
| 58 | + } |
| 59 | + else |
78 | 60 | { |
79 | | - var groups = AuthUtils.GetGroups(User); |
80 | | - return groups.Contains(AuthGroup.Advisors); |
| 61 | + result = await scheduleService.GetAllInstructorCoursesByTermAsync(username); |
81 | 62 | } |
| 63 | + |
| 64 | + // Filter only published terms |
| 65 | + var publishedResult = result |
| 66 | + .Where(r => r.ShowOnWeb?.Equals("Y", StringComparison.OrdinalIgnoreCase) == true) |
| 67 | + .ToList(); |
| 68 | + return Ok(publishedResult); |
| 69 | + } |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Get whether the currently logged-in user can read student schedules |
| 73 | + /// </summary> |
| 74 | + /// <returns>Whether they can read student schedules</returns> |
| 75 | + [HttpGet] |
| 76 | + [Route("canreadstudent")] |
| 77 | + public async Task<ActionResult<bool>> GetCanReadStudentSchedules() |
| 78 | + { |
| 79 | + var groups = AuthUtils.GetGroups(User); |
| 80 | + return groups.Contains(AuthGroup.Advisors); |
82 | 81 | } |
| 82 | +} |
0 commit comments