diff --git a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs index 7c82f7a8e4863b1150bebce631dcba9e8100412b..4a8d4b838b69c414438d9802c0ded5433fa78b0a 100644 --- a/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs +++ b/Tsi1.Api/Tsi1.Api/Controllers/CourseController.cs @@ -225,5 +225,18 @@ namespace Tsi1.Api.Controllers return Ok(result.Data); } + [Authorize(Roles = UserTypes.Student + ", " + UserTypes.Professor)] + [HttpGet("GetById/{courseId}")] + public async Task<IActionResult> GetById(int courseId) + { + var result = await _courseService.GetById(courseId); + if (result.HasError) + { + return BadRequest(result.Message); + } + + return Ok(result.Data); + } + } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/CourseDetailDto.cs b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/CourseDetailDto.cs new file mode 100644 index 0000000000000000000000000000000000000000..2aacbdedbd55c960a4355d27517081a083b58d8f --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/CourseDetailDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.BusinessLayer.Dtos +{ + public class CourseDetailDto + { + public int Id { get; set; } + public string Name { get; set; } + public int TenantId { get; set; } + public List<SectionDetailDto> Sections { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/FileDetailDto.cs b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/FileDetailDto.cs new file mode 100644 index 0000000000000000000000000000000000000000..3f289693699cb41e4a50ec61dae3fc16ef24f264 --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/FileDetailDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.BusinessLayer.Dtos +{ + public class FileDetailDto + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Path { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/SectionDetailDto.cs b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/SectionDetailDto.cs new file mode 100644 index 0000000000000000000000000000000000000000..4a2cc5b4e5ce00b1893cb1c3cd38eb3626e72155 --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/SectionDetailDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.BusinessLayer.Dtos +{ + public class SectionDetailDto + { + public int Id { get; set; } + public string Name { get; set; } + public int Order { get; set; } + public List<SectionItemDetailDto> SectionItems { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Dtos/SectionItemDetailDto.cs b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/SectionItemDetailDto.cs new file mode 100644 index 0000000000000000000000000000000000000000..9b6929057d90d5d05100f272a1818a7f01772e54 --- /dev/null +++ b/Tsi1.Api/Tsi1.BusinessLayer/Dtos/SectionItemDetailDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.BusinessLayer.Dtos +{ + public class SectionItemDetailDto + { + public int Id { get; set; } + public int Order { get; set; } + public int SectionItemTypeId { get; set; } + public ForumPreviewDto Forum { get; set; } + public FileDetailDto File { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs b/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs index 369144617f0eba6df858ecd73c83f401abac94fd..4d7d53b30ba60bfd543f4520cac5d16b0a07d6c2 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Helpers/MappingProfile.cs @@ -36,6 +36,12 @@ namespace Tsi1.BusinessLayer.Helpers CreateMap<SectionItem, SectionItemCreateDto>(); CreateMap<Section, SectionCreateDto>(); CreateMap<SectionItemType, SectionItemTypeDto>(); + + CreateMap<Course, CourseDetailDto>(); + CreateMap<Section, SectionDetailDto>(); + CreateMap<SectionItem, SectionItemDetailDto>(); + CreateMap<File, FileDetailDto>(); + CreateMap<ForumCreateDto, Forum>(); CreateMap<ForumPreviewDto, Forum>(); @@ -61,6 +67,11 @@ namespace Tsi1.BusinessLayer.Helpers CreateMap<SectionItemCreateDto, SectionItem>(); CreateMap<SectionCreateDto, Section>(); CreateMap<SectionItemTypeDto, SectionItemType>(); + + CreateMap<CourseDetailDto, Course>(); + CreateMap<SectionDetailDto, Section>(); + CreateMap<SectionItemDetailDto, SectionItem>(); + CreateMap<FileDetailDto, File>(); } } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs index 54b167f3278d6340d0fe16f2282c89dd400df7da..836612b7ca3f7dde220cf84c186e2b5892c9719e 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/ICourseService.cs @@ -28,5 +28,6 @@ namespace Tsi1.BusinessLayer.Interfaces Task<ServiceResult<bool>> RemoveProfessorToCourse(ProfessorCourseDto professorCourseDto); Task<ServiceResult<List<UserPreviewDto>>> GetProfessors(int courseId); + Task<ServiceResult<CourseDetailDto>> GetById(int courseId); } } diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs index 88c42781b34915538f046da2dd4a1682a96c72a5..fffcc93913bd4653c1fc9228a6d362b6e2acd8f8 100644 --- a/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs +++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/CourseService.cs @@ -341,5 +341,30 @@ namespace Tsi1.BusinessLayer.Services return result; } + + public async Task<ServiceResult<CourseDetailDto>> GetById(int courseId) + { + var result = new ServiceResult<CourseDetailDto>(); + + var course = await _context.Courses + .Include(x => x.Sections) + .ThenInclude(x => x.SectionItems) + .ThenInclude(x => x.Forum) + .Include(x => x.Sections) + .ThenInclude(x => x.SectionItems) + .ThenInclude(x => x.File) + .FirstOrDefaultAsync(x => x.Id == courseId); + + if (course == null) + { + result.HasError = true; + result.AddMessage(string.Format(ErrorMessages.CourseDoesNotExist, courseId)); + return result; + } + + result.Data = _mapper.Map<CourseDetailDto>(course); + + return result; + } } }