Skip to content
Snippets Groups Projects
Commit 2f5e89a2 authored by esantangelo's avatar esantangelo
Browse files

add endpoint GET api/Courses/GetProfessors/{courseId}

parent 44780f68
No related branches found
No related tags found
1 merge request!20merge from develop
...@@ -14,6 +14,7 @@ using Tsi1.BusinessLayer.Interfaces; ...@@ -14,6 +14,7 @@ using Tsi1.BusinessLayer.Interfaces;
namespace Tsi1.Api.Controllers namespace Tsi1.Api.Controllers
{ {
[Authorize]
[Route("api/[controller]")] [Route("api/[controller]")]
[ApiController] [ApiController]
public class CourseController : ControllerBase public class CourseController : ControllerBase
...@@ -220,5 +221,18 @@ namespace Tsi1.Api.Controllers ...@@ -220,5 +221,18 @@ namespace Tsi1.Api.Controllers
return Ok(); return Ok();
} }
[HttpGet("GetProfessors/{courseId}")]
public async Task<IActionResult> GetProfessors(int courseId)
{
var result = await _courseService.GetProfessors(courseId);
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
} }
} }
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class UserDetailDto
{
public int Id { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public StudentPreviewDto Student { get; set; }
public ProfessorPreviewDto Professor { get; set; }
}
}
...@@ -8,14 +8,10 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -8,14 +8,10 @@ namespace Tsi1.BusinessLayer.Dtos
{ {
public int Id { get; set; } public int Id { get; set; }
public string Username { get; set; }
public string FirstName { get; set; } public string FirstName { get; set; }
public string LastName { get; set; } public string LastName { get; set; }
public StudentPreviewDto Student { get; set; } public string Email { get; set; }
public ProfessorPreviewDto Professor { get; set; }
} }
} }
...@@ -20,9 +20,10 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -20,9 +20,10 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<PostMessage, PostMessagePreviewDto>(); CreateMap<PostMessage, PostMessagePreviewDto>();
CreateMap<Message, MessagePreviewDto>(); CreateMap<Message, MessagePreviewDto>();
CreateMap<Message, MessageCreateDto>(); CreateMap<Message, MessageCreateDto>();
CreateMap<User, UserPreviewDto>(); CreateMap<User, UserDetailDto>();
CreateMap<User, UserRegisterDto>(); CreateMap<User, UserRegisterDto>();
CreateMap<User, UserModifyDto>(); CreateMap<User, UserModifyDto>();
CreateMap<User, UserPreviewDto>();
CreateMap<Student, StudentPreviewDto>(); CreateMap<Student, StudentPreviewDto>();
CreateMap<Professor, ProfessorPreviewDto>(); CreateMap<Professor, ProfessorPreviewDto>();
CreateMap<Course, CourseCreateDto>(); CreateMap<Course, CourseCreateDto>();
...@@ -41,9 +42,10 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -41,9 +42,10 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<PostMessagePreviewDto, PostMessage>(); CreateMap<PostMessagePreviewDto, PostMessage>();
CreateMap<MessagePreviewDto, Message>(); CreateMap<MessagePreviewDto, Message>();
CreateMap<MessageCreateDto, Message>(); CreateMap<MessageCreateDto, Message>();
CreateMap<UserPreviewDto, User>(); CreateMap<UserDetailDto, User>();
CreateMap<UserRegisterDto, User>(); CreateMap<UserRegisterDto, User>();
CreateMap<UserModifyDto, User>(); CreateMap<UserModifyDto, User>();
CreateMap<UserPreviewDto, User>();
CreateMap<StudentPreviewDto, Student>(); CreateMap<StudentPreviewDto, Student>();
CreateMap<ProfessorPreviewDto, Professor>(); CreateMap<ProfessorPreviewDto, Professor>();
CreateMap<CourseCreateDto, Course>(); CreateMap<CourseCreateDto, Course>();
......
...@@ -27,5 +27,6 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -27,5 +27,6 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<bool>> DropOutFromCourse(int userId, int courseId); Task<ServiceResult<bool>> DropOutFromCourse(int userId, int courseId);
Task<ServiceResult<bool>> RemoveProfessorToCourse(ProfessorCourseDto professorCourseDto); Task<ServiceResult<bool>> RemoveProfessorToCourse(ProfessorCourseDto professorCourseDto);
Task<ServiceResult<List<UserPreviewDto>>> GetProfessors(int courseId);
} }
} }
...@@ -14,9 +14,9 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -14,9 +14,9 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<User>> Create(UserRegisterDto dto, string type, int tenantId); Task<ServiceResult<User>> Create(UserRegisterDto dto, string type, int tenantId);
Task<ServiceResult<List<UserPreviewDto>>> GetAll(int tenantId); Task<ServiceResult<List<UserDetailDto>>> GetAll(int tenantId);
Task<ServiceResult<UserPreviewDto>> GetById(int userId); Task<ServiceResult<UserDetailDto>> GetById(int userId);
Task<ServiceResult<User>> GetByUsername(string username, int tenantId); Task<ServiceResult<User>> GetByUsername(string username, int tenantId);
......
...@@ -323,5 +323,23 @@ namespace Tsi1.BusinessLayer.Services ...@@ -323,5 +323,23 @@ namespace Tsi1.BusinessLayer.Services
return result; return result;
} }
public async Task<ServiceResult<List<UserPreviewDto>>> GetProfessors(int courseId)
{
var result = new ServiceResult<List<UserPreviewDto>>();
var users = await _context.ProfessorCourses
.Include(x => x.Professor)
.ThenInclude(x => x.User)
.Where(x => x.CourseId == courseId)
.Select(x => x.Professor.User)
.ToListAsync();
var userDtos = _mapper.Map<List<UserPreviewDto>>(users);
result.Data = userDtos;
return result;
}
} }
} }
...@@ -135,24 +135,24 @@ namespace Tsi1.BusinessLayer.Services ...@@ -135,24 +135,24 @@ namespace Tsi1.BusinessLayer.Services
return result; return result;
} }
public async Task<ServiceResult<List<UserPreviewDto>>> GetAll(int tenantId) public async Task<ServiceResult<List<UserDetailDto>>> GetAll(int tenantId)
{ {
var result = new ServiceResult<List<UserPreviewDto>>(); var result = new ServiceResult<List<UserDetailDto>>();
var users = await _context.Users var users = await _context.Users
.Where(x => x.UserType.Name != UserTypes.FacultyAdmin && x.TenantId == tenantId) .Where(x => x.UserType.Name != UserTypes.FacultyAdmin && x.TenantId == tenantId)
.ToListAsync(); .ToListAsync();
var usersDto = _mapper.Map<List<UserPreviewDto>>(users); var usersDto = _mapper.Map<List<UserDetailDto>>(users);
result.Data = usersDto; result.Data = usersDto;
return result; return result;
} }
public async Task<ServiceResult<UserPreviewDto>> GetById(int userId) public async Task<ServiceResult<UserDetailDto>> GetById(int userId)
{ {
var result = new ServiceResult<UserPreviewDto>(); var result = new ServiceResult<UserDetailDto>();
var user = await _context.Users var user = await _context.Users
.Include(x => x.UserType) .Include(x => x.UserType)
...@@ -182,7 +182,7 @@ namespace Tsi1.BusinessLayer.Services ...@@ -182,7 +182,7 @@ namespace Tsi1.BusinessLayer.Services
return result; return result;
} }
var userDto = _mapper.Map<UserPreviewDto>(user); var userDto = _mapper.Map<UserDetailDto>(user);
result.Data = userDto; result.Data = userDto;
......
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