Skip to content
Snippets Groups Projects
Commit 0dad06c7 authored by Lucca Santangelo Dodera's avatar Lucca Santangelo Dodera
Browse files

Merge branch 'develop' into 'master'

Develop

See merge request !31
parents d0041b10 399f38e7
No related branches found
No related tags found
1 merge request!31Develop
Pipeline #10474 passed with stage
Showing
with 168 additions and 38 deletions
......@@ -42,7 +42,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
......@@ -63,16 +63,83 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student)]
[HttpGet("GetMyCommunications")]
public async Task<IActionResult> GetMyCommunications()
[Authorize(Roles = UserTypes.FacultyAdmin)]
[HttpGet("GetAllCommunications")]
public async Task<IActionResult> GetAllCommunications()
{
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.GetAllCommunications(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.FacultyAdmin)]
[HttpGet("GetAllCourseCommunications")]
public async Task<IActionResult> GetAllCourseCommunications()
{
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _communicationService.GetAllCourseCommunications(tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
var result = await _communicationService.GetMyCommunications(userId);
[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.GetGlobalCommunications(tenantId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("GetAllGlobalCommunications")]
public async Task<IActionResult> GetAllGlobalCommunications()
{
var result = await _communicationService.GetAllGlobalCommunications();
if (result.HasError)
{
......
......@@ -51,7 +51,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
......
......@@ -47,7 +47,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Professor)]
......
......@@ -71,7 +71,7 @@ namespace Tsi1.Api.Controllers
}
}
return Ok();
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
......
......@@ -51,7 +51,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
......
......@@ -29,7 +29,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[HttpPut("Modify/{sectionId}")]
......
......@@ -34,7 +34,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[HttpDelete("Delete/{sectionItemId}")]
......
......@@ -42,7 +42,7 @@ namespace Tsi1.Api.Controllers
return BadRequest(result.Message);
}
return Ok();
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
......@@ -64,15 +64,11 @@ namespace Tsi1.Api.Controllers
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpGet("GetAllGlobalSurveys")]
public async Task<IActionResult> GetAllGlobalSurveys(int tenantId)
public async Task<IActionResult> GetAllGlobalSurveys()
{
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
if (userType == UserTypes.FacultyAdmin)
{
tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
}
var result = await _surveyService.GetAllGlobalSurveys(tenantId, userType);
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _surveyService.GetAllGlobalSurveys(tenantId);
if (result.HasError)
{
......
......@@ -17,12 +17,9 @@ namespace Tsi1.Api.Controllers
{
private readonly ITenantService _tenantService;
private readonly IFileService _fileService;
public TenantController(ITenantService tenantService, IFileService fileService)
public TenantController(ITenantService tenantService)
{
_tenantService = tenantService;
_fileService = fileService;
}
[Authorize(Roles = UserTypes.UdelarAdmin)]
......@@ -106,10 +103,40 @@ namespace Tsi1.Api.Controllers
}
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("CourseList")]
public async Task<IActionResult> CourseList()
[HttpGet("AllCourseStudentQuantity")]
public async Task<IActionResult> AllCourseStudentQuantity()
{
var result = await _tenantService.CourseStudentQuantity();
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("FacultyRegistrations")]
public async Task<IActionResult> FacultyRegistrations()
{
var result = await _tenantService.CourseList();
var result = await _tenantService.FacultyRegistrations();
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin)]
[HttpGet("CourseStudentQuantity")]
public async Task<IActionResult> CourseStudentQuantity()
{
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _tenantService.CourseStudentQuantity(tenantId);
if (result.HasError)
{
......
......@@ -159,7 +159,7 @@ namespace Tsi1.Api.Controllers
BadRequest(userServiceResult.Message);
}
return Ok();
return Ok(userServiceResult.Data);
}
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
......@@ -349,7 +349,7 @@ namespace Tsi1.Api.Controllers
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)]
[Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor + ", " + UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin)]
[HttpGet("GetById/{userId}")]
public async Task<IActionResult> GetById(int userId)
{
......@@ -482,5 +482,12 @@ namespace Tsi1.Api.Controllers
return Ok();
}
[AllowAnonymous]
[HttpGet("GetAllRefreshTokens")]
public IActionResult GetAllRefreshTokens()
{
return Ok(_jwtAuthManager.GetRefreshTokens());
}
}
}
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
......@@ -17,5 +18,6 @@ namespace Tsi1.Api.Infrastructure
int GenerateVerificationCode(string username, DateTime now);
bool ValidateVerificationCode(string username, int code);
public void RemoveExpiredVerificationCodes(DateTime now);
public IEnumerable<RefreshToken> GetRefreshTokens();
}
}
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
......@@ -150,6 +151,11 @@ namespace Tsi1.Api.Infrastructure
}
}
public IEnumerable<RefreshToken> GetRefreshTokens()
{
return _usersRefreshTokens.Select(x => x.Value).ToList();
}
private static string GenerateRefreshTokenString()
{
var randomNumber = new byte[32];
......
......@@ -28,8 +28,6 @@ namespace Tsi1.Api.SignalR
public async Task Join(string roomName, string offer)
{
Console.WriteLine(offer);
await Clients.Group(roomName).SendAsync("Join", Context.ConnectionId, offer);
await Groups.AddToGroupAsync(Context.ConnectionId, roomName);
......
......@@ -16,5 +16,7 @@ namespace Tsi1.BusinessLayer.Dtos
public int PostId { get; set; }
public string CompleteName { get; set; }
}
}
......@@ -16,5 +16,7 @@ namespace Tsi1.BusinessLayer.Dtos
public int UserId { get; set; }
public string CompleteName { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class RegistrationDto
{
public int Id { get; set; }
public string Name { get; set; }
public int StudentQuantity { get; set; }
}
}
......@@ -9,7 +9,5 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; }
public string Name { get; set; }
public int StudentQuantity { get; set; }
}
}
......@@ -30,7 +30,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<Course, CoursePreviewDto>();
CreateMap<Tenant, TenantPreviewDto>();
CreateMap<Tenant, TenantCreateDto>();
CreateMap<Tenant, TenantCourseDto>().ForMember(x => x.Courses, opt => opt.Ignore());
CreateMap<Tenant, TenantCourseDto>().ForMember(x => x.Courses, opt => opt.Ignore());
CreateMap<UserType, UserTypeDto>();
CreateMap<File, FileDto>();
CreateMap<SectionItem, SectionItemCreateDto>();
......@@ -52,6 +52,8 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<Communication, CommunicationCreateDto>();
CreateMap<Communication, CommunicationPreviewDto>();
CreateMap<AnswerOption, AnswerOptionDetailDto>();
CreateMap<Tenant, RegistrationDto>();
CreateMap<Course, RegistrationDto>();
CreateMap<ForumCreateDto, Forum>();
CreateMap<ForumPreviewDto, Forum>();
......@@ -93,6 +95,8 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<CommunicationCreateDto, Communication>();
CreateMap<CommunicationPreviewDto, Communication>();
CreateMap<AnswerOptionDetailDto, AnswerOption>();
CreateMap<RegistrationDto, Tenant>();
CreateMap<RegistrationDto, Course>();
}
}
}
......@@ -9,12 +9,18 @@ namespace Tsi1.BusinessLayer.Interfaces
{
public interface ICommunicationService
{
Task<ServiceResult<bool>> Create(CommunicationCreateDto newCommunication, int id);
Task<ServiceResult<int>> Create(CommunicationCreateDto newCommunication, int id);
Task<ServiceResult<bool>> Delete(int communicationId);
Task<ServiceResult<List<CommunicationPreviewDto>>> GetMyCommunications(int userId);
Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllCommunications(int tenantId);
Task<ServiceResult<List<CommunicationPreviewDto>>> GetCourseCommunications(int courseId, int tenantId);
Task<ServiceResult<List<CommunicationPreviewDto>>> GetGlobalCommunications(int tenantId);
Task<ServiceResult<bool>> TenantValidation(int tenantId, int courseId);
Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllGlobalCommunications();
Task<ServiceResult<List<CommunicationPreviewDto>>> GetAllCourseCommunications(int tenantId);
}
}
......@@ -12,7 +12,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{
Task<ServiceResult<List<ForumPreviewDto>>> GetForums(int sectionId);
Task<ServiceResult<Forum>> Create(ForumCreateDto newForum);
Task<ServiceResult<int>> Create(ForumCreateDto newForum);
Task<ServiceResult<Forum>> Delete(int forumId);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment