-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCourseGroupsController.cs
More file actions
102 lines (90 loc) · 3.46 KB
/
CourseGroupsController.cs
File metadata and controls
102 lines (90 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using HwProj.CoursesService.Client;
using HwProj.Models.CoursesService.ViewModels;
using HwProj.Models.Roles;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace HwProj.APIGateway.API.Controllers;
[Route("api/[controller]")]
[ApiController]
public class CourseGroupsController : AggregationController
{
private readonly ICoursesServiceClient _coursesClient;
public CourseGroupsController(ICoursesServiceClient coursesClient) : base(null)
{
_coursesClient = coursesClient;
}
[HttpGet("{courseId}/getAll")]
[ProducesResponseType(typeof(GroupViewModel[]), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetAllCourseGroups(long courseId)
{
var result = await _coursesClient.GetAllCourseGroups(courseId);
return result == null
? NotFound()
: Ok(result);
}
[HttpPost("{courseId}/create")]
[Authorize(Roles = Roles.LecturerRole)]
[ProducesResponseType(typeof(long), (int)HttpStatusCode.OK)]
public async Task<IActionResult> CreateCourseGroup(CreateGroupViewModel model, long courseId)
{
var result = await _coursesClient.CreateCourseGroup(model, courseId);
return Ok(result);
}
[HttpDelete("{courseId}/delete/{groupId}")]
[Authorize(Roles = Roles.LecturerRole)]
public async Task<IActionResult> DeleteCourseGroup(long courseId, long groupId)
{
await _coursesClient.DeleteCourseGroup(courseId, groupId);
return Ok();
}
[HttpPost("{courseId}/update/{groupId}")]
[Authorize(Roles = Roles.LecturerRole)]
public async Task<IActionResult> UpdateCourseGroup(UpdateGroupViewModel model, long courseId, long groupId)
{
await _coursesClient.UpdateCourseGroup(model, courseId, groupId);
return Ok();
}
[HttpGet("{courseId}/get")]
[Authorize]
[ProducesResponseType(typeof(GroupViewModel), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetCourseGroupsById(long courseId)
{
var result = await _coursesClient.GetCourseGroupsById(courseId, UserId);
return result == null
? NotFound()
: Ok(result);
}
[HttpPost("{courseId}/addStudentInGroup/{groupId}")]
[Authorize(Roles = Roles.LecturerRole)]
public async Task<IActionResult> AddStudentInGroup(long courseId, long groupId, [FromQuery] string userId)
{
await _coursesClient.AddStudentInGroup(courseId, groupId, userId);
return Ok();
}
[HttpPost("{courseId}/removeStudentFromGroup/{groupId}")]
[Authorize(Roles = Roles.LecturerRole)]
public async Task<IActionResult> RemoveStudentFromGroup(long courseId, long groupId, [FromQuery] string userId)
{
await _coursesClient.RemoveStudentFromGroup(courseId, groupId, userId);
return Ok();
}
[HttpGet("get/{groupId}")]
[ProducesResponseType(typeof(GroupViewModel), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetGroup(long groupId)
{
var result = (await _coursesClient.GetGroupsById(groupId)).FirstOrDefault();
return result == null
? NotFound()
: Ok(result);
}
[HttpGet("getTasks/{groupId}")]
[ProducesResponseType(typeof(long[]), (int)HttpStatusCode.OK)]
public async Task<IActionResult> GetGroupTasks(long groupId)
{
var result = await _coursesClient.GetGroupTasks(groupId);
return Ok(result);
}
}