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

fix endpoint MyCourses

parent 847173c6
No related branches found
No related tags found
1 merge request!5Multi tenancy
......@@ -30,9 +30,8 @@ namespace Tsi1.Api.Controllers
{
var userId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var userType = HttpContext.User.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Role).Value;
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
var result = await _courseService.GetCoursePreviews(userType, tenantId);
var result = await _courseService.GetCoursePreviews(userId, userType);
if (result.HasError)
{
return BadRequest(result.Message);
......
......@@ -10,7 +10,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{
public interface ICourseService
{
Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(string userType, int tenantId);
Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(int userId, string userType);
Task<ServiceResult<Course>> Create(CourseCreateDto newCourse);
......
......@@ -48,17 +48,26 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(string userType, int tenantId)
public async Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(int userId, string userType)
{
var result = new ServiceResult<List<CoursePreviewDto>>();
var courses = new List<Course>();
var user = await _context.Users.FirstOrDefaultAsync(x => x.Id == userId);
if (user == null)
{
result.HasError = true;
result.Message = string.Format(ErrorMessages.UserDoesNotExist, userId);
return result;
}
if (userType == UserTypes.Student)
{
courses = await _context.StudentCourses
.Include(x => x.Course)
.Where(x => x.Course.TenantId == tenantId)
.Where(x => x.StudentId == user.StudentId)
.Select(x => x.Course)
.ToListAsync();
}
......@@ -66,7 +75,7 @@ namespace Tsi1.BusinessLayer.Services
{
courses = await _context.ProfessorCourses
.Include(x => x.Course)
.Where(x => x.Course.TenantId == tenantId)
.Where(x => x.ProfessorId == user.ProfessorId)
.Select(x => x.Course)
.ToListAsync();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment