Skip to content
Snippets Groups Projects

fix GetMyCommunications and add 2 endpoints

3 files
+ 100
4
Compare changes
  • Side-by-side
  • Inline

Files

@@ -71,8 +71,45 @@ namespace Tsi1.Api.Controllers
public async Task<IActionResult> GetMyCommunications()
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _communicationService.GetMyCommunications(userId, tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.FacultyAdmin + ", " + UserTypes.Professor)]
[HttpGet("GetCourseCommunications/{courseId}")]
public async Task<IActionResult> GetCourseCommunications(int courseId)
{
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _communicationService.GetCourseCommunications(courseId, tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.FacultyAdmin + ", " + UserTypes.Professor + ", " + UserTypes.UdelarAdmin)]
[HttpGet("GetGlobalCommunications")]
public async Task<IActionResult> GetGlobalCommunications(int tenantId)
{
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
if (userType != UserTypes.UdelarAdmin)
{
tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
}
var result = await _communicationService.GetMyCommunications(userId);
var result = await _communicationService.GetGlobalCommunications(tenantId);
if (result.HasError)
{
Loading