|
7 | 7 | using Microsoft.AspNetCore.Authorization; |
8 | 8 | using Microsoft.AspNetCore.Mvc; |
9 | 9 |
|
10 | | -namespace HwProj.APIGateway.API.Controllers |
| 10 | +namespace HwProj.APIGateway.API.Controllers; |
| 11 | + |
| 12 | +[Route("api/[controller]")] |
| 13 | +[ApiController] |
| 14 | +public class CourseGroupsController : AggregationController |
11 | 15 | { |
12 | | - [Route("api/[controller]")] |
13 | | - [ApiController] |
14 | | - public class CourseGroupsController : AggregationController |
15 | | - { |
16 | | - private readonly ICoursesServiceClient _coursesClient; |
| 16 | + private readonly ICoursesServiceClient _coursesClient; |
17 | 17 |
|
18 | | - public CourseGroupsController(ICoursesServiceClient coursesClient) : base(null) |
19 | | - { |
20 | | - _coursesClient = coursesClient; |
21 | | - } |
| 18 | + public CourseGroupsController(ICoursesServiceClient coursesClient) : base(null) |
| 19 | + { |
| 20 | + _coursesClient = coursesClient; |
| 21 | + } |
22 | 22 |
|
23 | | - [HttpGet("{courseId}/getAll")] |
24 | | - [ProducesResponseType(typeof(GroupViewModel[]), (int)HttpStatusCode.OK)] |
25 | | - public async Task<IActionResult> GetAllCourseGroups(long courseId) |
26 | | - { |
27 | | - var result = await _coursesClient.GetAllCourseGroups(courseId); |
28 | | - return result == null |
29 | | - ? NotFound() as IActionResult |
30 | | - : Ok(result); |
31 | | - } |
| 23 | + [HttpGet("{courseId}/getAll")] |
| 24 | + [ProducesResponseType(typeof(GroupViewModel[]), (int)HttpStatusCode.OK)] |
| 25 | + public async Task<IActionResult> GetAllCourseGroups(long courseId) |
| 26 | + { |
| 27 | + var result = await _coursesClient.GetAllCourseGroups(courseId); |
| 28 | + return result == null |
| 29 | + ? NotFound() |
| 30 | + : Ok(result); |
| 31 | + } |
32 | 32 |
|
33 | | - [HttpPost("{courseId}/create")] |
34 | | - [Authorize(Roles = Roles.LecturerRole)] |
35 | | - [ProducesResponseType(typeof(long), (int)HttpStatusCode.OK)] |
36 | | - public async Task<IActionResult> CreateCourseGroup(CreateGroupViewModel model, long courseId) |
37 | | - { |
38 | | - var result = await _coursesClient.CreateCourseGroup(model, courseId); |
39 | | - return Ok(result); |
40 | | - } |
| 33 | + [HttpPost("{courseId}/create")] |
| 34 | + [Authorize(Roles = Roles.LecturerRole)] |
| 35 | + [ProducesResponseType(typeof(long), (int)HttpStatusCode.OK)] |
| 36 | + public async Task<IActionResult> CreateCourseGroup(CreateGroupViewModel model, long courseId) |
| 37 | + { |
| 38 | + var result = await _coursesClient.CreateCourseGroup(model, courseId); |
| 39 | + return Ok(result); |
| 40 | + } |
41 | 41 |
|
42 | | - [HttpDelete("{courseId}/delete/{groupId}")] |
43 | | - [Authorize(Roles = Roles.LecturerRole)] |
44 | | - public async Task<IActionResult> DeleteCourseGroup(long courseId, long groupId) |
45 | | - { |
46 | | - await _coursesClient.DeleteCourseGroup(courseId, groupId); |
47 | | - return Ok(); |
48 | | - } |
| 42 | + [HttpDelete("{courseId}/delete/{groupId}")] |
| 43 | + [Authorize(Roles = Roles.LecturerRole)] |
| 44 | + public async Task<IActionResult> DeleteCourseGroup(long courseId, long groupId) |
| 45 | + { |
| 46 | + await _coursesClient.DeleteCourseGroup(courseId, groupId); |
| 47 | + return Ok(); |
| 48 | + } |
49 | 49 |
|
50 | | - [HttpPost("{courseId}/update/{groupId}")] |
51 | | - [Authorize(Roles = Roles.LecturerRole)] |
52 | | - public async Task<IActionResult> UpdateCourseGroup(UpdateGroupViewModel model, long courseId, long groupId) |
53 | | - { |
54 | | - await _coursesClient.UpdateCourseGroup(model, courseId, groupId); |
55 | | - return Ok(); |
56 | | - } |
| 50 | + [HttpPost("{courseId}/update/{groupId}")] |
| 51 | + [Authorize(Roles = Roles.LecturerRole)] |
| 52 | + public async Task<IActionResult> UpdateCourseGroup(UpdateGroupViewModel model, long courseId, long groupId) |
| 53 | + { |
| 54 | + await _coursesClient.UpdateCourseGroup(model, courseId, groupId); |
| 55 | + return Ok(); |
| 56 | + } |
57 | 57 |
|
58 | | - [HttpGet("{courseId}/get")] |
59 | | - [Authorize] |
60 | | - [ProducesResponseType(typeof(GroupViewModel), (int)HttpStatusCode.OK)] |
61 | | - public async Task<IActionResult> GetCourseGroupsById(long courseId) |
62 | | - { |
63 | | - var result = await _coursesClient.GetCourseGroupsById(courseId, UserId); |
64 | | - return result == null |
65 | | - ? NotFound() as IActionResult |
66 | | - : Ok(result); |
67 | | - } |
| 58 | + [HttpGet("{courseId}/get")] |
| 59 | + [Authorize] |
| 60 | + [ProducesResponseType(typeof(GroupViewModel), (int)HttpStatusCode.OK)] |
| 61 | + public async Task<IActionResult> GetCourseGroupsById(long courseId) |
| 62 | + { |
| 63 | + var result = await _coursesClient.GetCourseGroupsById(courseId, UserId); |
| 64 | + return result == null |
| 65 | + ? NotFound() |
| 66 | + : Ok(result); |
| 67 | + } |
68 | 68 |
|
69 | | - [HttpPost("{courseId}/addStudentInGroup/{groupId}")] |
70 | | - [Authorize(Roles = Roles.LecturerRole)] |
71 | | - public async Task<IActionResult> AddStudentInGroup(long courseId, long groupId, [FromQuery] string userId) |
72 | | - { |
73 | | - await _coursesClient.AddStudentInGroup(courseId, groupId, userId); |
74 | | - return Ok(); |
75 | | - } |
| 69 | + [HttpPost("{courseId}/addStudentInGroup/{groupId}")] |
| 70 | + [Authorize(Roles = Roles.LecturerRole)] |
| 71 | + public async Task<IActionResult> AddStudentInGroup(long courseId, long groupId, [FromQuery] string userId) |
| 72 | + { |
| 73 | + await _coursesClient.AddStudentInGroup(courseId, groupId, userId); |
| 74 | + return Ok(); |
| 75 | + } |
76 | 76 |
|
77 | | - [HttpPost("{courseId}/removeStudentFromGroup/{groupId}")] |
78 | | - [Authorize(Roles = Roles.LecturerRole)] |
79 | | - public async Task<IActionResult> RemoveStudentFromGroup(long courseId, long groupId, [FromQuery] string userId) |
80 | | - { |
81 | | - await _coursesClient.RemoveStudentFromGroup(courseId, groupId, userId); |
82 | | - return Ok(); |
83 | | - } |
| 77 | + [HttpPost("{courseId}/removeStudentFromGroup/{groupId}")] |
| 78 | + [Authorize(Roles = Roles.LecturerRole)] |
| 79 | + public async Task<IActionResult> RemoveStudentFromGroup(long courseId, long groupId, [FromQuery] string userId) |
| 80 | + { |
| 81 | + await _coursesClient.RemoveStudentFromGroup(courseId, groupId, userId); |
| 82 | + return Ok(); |
| 83 | + } |
84 | 84 |
|
85 | | - [HttpGet("get/{groupId}")] |
86 | | - [ProducesResponseType(typeof(GroupViewModel), (int)HttpStatusCode.OK)] |
87 | | - public async Task<IActionResult> GetGroup(long groupId) |
88 | | - { |
89 | | - var result = (await _coursesClient.GetGroupsById(groupId)).FirstOrDefault(); |
90 | | - return result == null |
91 | | - ? NotFound() as IActionResult |
92 | | - : Ok(result); |
93 | | - } |
| 85 | + [HttpGet("get/{groupId}")] |
| 86 | + [ProducesResponseType(typeof(GroupViewModel), (int)HttpStatusCode.OK)] |
| 87 | + public async Task<IActionResult> GetGroup(long groupId) |
| 88 | + { |
| 89 | + var result = (await _coursesClient.GetGroupsById(groupId)).FirstOrDefault(); |
| 90 | + return result == null |
| 91 | + ? NotFound() |
| 92 | + : Ok(result); |
| 93 | + } |
94 | 94 |
|
95 | | - [HttpGet("getTasks/{groupId}")] |
96 | | - [ProducesResponseType(typeof(long[]), (int)HttpStatusCode.OK)] |
97 | | - public async Task<IActionResult> GetGroupTasks(long groupId) |
98 | | - { |
99 | | - var result = await _coursesClient.GetGroupTasks(groupId); |
100 | | - return Ok(result); |
101 | | - } |
| 95 | + [HttpGet("getTasks/{groupId}")] |
| 96 | + [ProducesResponseType(typeof(long[]), (int)HttpStatusCode.OK)] |
| 97 | + public async Task<IActionResult> GetGroupTasks(long groupId) |
| 98 | + { |
| 99 | + var result = await _coursesClient.GetGroupTasks(groupId); |
| 100 | + return Ok(result); |
102 | 101 | } |
103 | 102 | } |
0 commit comments