diff --git a/GradeBookServer.Application/DTOs/Direction/DirectionTableDto.cs b/GradeBookServer.Application/DTOs/Direction/DirectionNameDto.cs similarity index 76% rename from GradeBookServer.Application/DTOs/Direction/DirectionTableDto.cs rename to GradeBookServer.Application/DTOs/Direction/DirectionNameDto.cs index cb9e07b..c10de81 100644 --- a/GradeBookServer.Application/DTOs/Direction/DirectionTableDto.cs +++ b/GradeBookServer.Application/DTOs/Direction/DirectionNameDto.cs @@ -6,10 +6,9 @@ using System.Threading.Tasks; namespace GradeBookServer.Application.DTOs.Direction { - public class DirectionTableDto + public class DirectionNameDto { public int ID { get; set; } public required string Name { get; set; } - public string? FacultyName { get; set; } } } diff --git a/GradeBookServer.Application/DTOs/Direction/DirectionDetailDto.cs b/GradeBookServer.Application/DTOs/Direction/DirectionReadDto.cs similarity index 70% rename from GradeBookServer.Application/DTOs/Direction/DirectionDetailDto.cs rename to GradeBookServer.Application/DTOs/Direction/DirectionReadDto.cs index c426311..1e3b8ad 100644 --- a/GradeBookServer.Application/DTOs/Direction/DirectionDetailDto.cs +++ b/GradeBookServer.Application/DTOs/Direction/DirectionReadDto.cs @@ -8,12 +8,12 @@ using System.Threading.Tasks; namespace GradeBookServer.Application.DTOs.Direction { - public class DirectionDetailDto + public class DirectionReadDto { public int ID { get; set; } public required string Name { get; set; } public required string FacultyName { get; set; } - public List Disciplines { get; set; } = new(); - public List Groups { get; set; } = new(); + public List Disciplines { get; set; } = new(); + public List Groups { get; set; } = new(); } } diff --git a/GradeBookServer.Application/DTOs/Discipline/DisciplineTableDto.cs b/GradeBookServer.Application/DTOs/Discipline/DisciplineNameDto.cs similarity index 78% rename from GradeBookServer.Application/DTOs/Discipline/DisciplineTableDto.cs rename to GradeBookServer.Application/DTOs/Discipline/DisciplineNameDto.cs index ee4a57b..bbb4db7 100644 --- a/GradeBookServer.Application/DTOs/Discipline/DisciplineTableDto.cs +++ b/GradeBookServer.Application/DTOs/Discipline/DisciplineNameDto.cs @@ -6,10 +6,9 @@ using System.Threading.Tasks; namespace GradeBookServer.Application.DTOs.Discipline { - public class DisciplineTableDto + public class DisciplineNameDto { public int ID { get; set; } public required string Name { get; set; } - public int Hours { get; set; } } } diff --git a/GradeBookServer.Application/DTOs/Discipline/DisciplineDetailDto.cs b/GradeBookServer.Application/DTOs/Discipline/DisciplineReadDto.cs similarity index 73% rename from GradeBookServer.Application/DTOs/Discipline/DisciplineDetailDto.cs rename to GradeBookServer.Application/DTOs/Discipline/DisciplineReadDto.cs index ac53bac..7c37c56 100644 --- a/GradeBookServer.Application/DTOs/Discipline/DisciplineDetailDto.cs +++ b/GradeBookServer.Application/DTOs/Discipline/DisciplineReadDto.cs @@ -7,11 +7,11 @@ using System.Threading.Tasks; namespace GradeBookServer.Application.DTOs.Discipline { - public class DisciplineDetailDto + public class DisciplineReadDto { public int ID { get; set; } public required string Name { get; set; } public int Hours { get; set; } - public List Directions { get; set; } = new List(); + public List Directions { get; set; } = new List(); } } diff --git a/GradeBookServer.Application/DTOs/Faculty/FacultyReadDto.cs b/GradeBookServer.Application/DTOs/Faculty/FacultyReadDto.cs index 65f8405..89d0e3c 100644 --- a/GradeBookServer.Application/DTOs/Faculty/FacultyReadDto.cs +++ b/GradeBookServer.Application/DTOs/Faculty/FacultyReadDto.cs @@ -11,6 +11,6 @@ namespace GradeBookServer.Application.DTOs.Faculty { public int ID { get; set; } public required string Name { get; set; } - public List Directions { get; set; } = new List(); + public List Directions { get; set; } = new List(); } } diff --git a/GradeBookServer.Application/DTOs/Group/GroupTableDto.cs b/GradeBookServer.Application/DTOs/Group/GroupNameDto.cs similarity index 89% rename from GradeBookServer.Application/DTOs/Group/GroupTableDto.cs rename to GradeBookServer.Application/DTOs/Group/GroupNameDto.cs index b9900d5..fa4c69b 100644 --- a/GradeBookServer.Application/DTOs/Group/GroupTableDto.cs +++ b/GradeBookServer.Application/DTOs/Group/GroupNameDto.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GradeBookServer.Application.DTOs.Group { - public class GroupTableDto + public class GroupNameDto { public int ID { get; set; } public required string Name { get; set; } diff --git a/GradeBookServer.Application/DTOs/Group/GroupDetailDto.cs b/GradeBookServer.Application/DTOs/Group/GroupReadDto.cs similarity index 93% rename from GradeBookServer.Application/DTOs/Group/GroupDetailDto.cs rename to GradeBookServer.Application/DTOs/Group/GroupReadDto.cs index 413429b..df3a84f 100644 --- a/GradeBookServer.Application/DTOs/Group/GroupDetailDto.cs +++ b/GradeBookServer.Application/DTOs/Group/GroupReadDto.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace GradeBookServer.Application.DTOs.Group { - public class GroupDetailDto + public class GroupReadDto { public int ID { get; set; } public required string Name { get; set; } diff --git a/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs b/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs index 1ea4ee0..455d244 100644 --- a/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs +++ b/GradeBookServer.Application/DTOs/Student/StudentReadDto.cs @@ -13,5 +13,4 @@ namespace GradeBookServer.Application.DTOs.Student public int Age { get; set; } public string? GroupName { get; set; } } - } diff --git a/GradeBookServer.Application/Interfaces/IBaseRepository.cs b/GradeBookServer.Application/Interfaces/IBaseRepository.cs index 2ebacb5..8610c48 100644 --- a/GradeBookServer.Application/Interfaces/IBaseRepository.cs +++ b/GradeBookServer.Application/Interfaces/IBaseRepository.cs @@ -14,6 +14,7 @@ namespace GradeBookServer.Application.Interfaces { Task GetByIdAsync(int id); Task?> GetAllAsync(IncludeSpecification? includeSpec = null); + Task> WhereAsync(Expression> predicate, IncludeSpecification? includeSpec = null); Task AddAsync(TEntity entity); Task UpdateAsync(TEntity entity); Task DeleteAsync(int id); diff --git a/GradeBookServer.Application/Services/DirectionService.cs b/GradeBookServer.Application/Services/DirectionService.cs index a1e30b6..fab81e7 100644 --- a/GradeBookServer.Application/Services/DirectionService.cs +++ b/GradeBookServer.Application/Services/DirectionService.cs @@ -2,6 +2,7 @@ using GradeBookServer.Application.DTOs.Direction; using GradeBookServer.Application.DTOs.Discipline; using GradeBookServer.Application.DTOs.Group; +using GradeBookServer.Application.DTOs.Student; using GradeBookServer.Application.Interfaces; using GradeBookServer.Domain.Entities; using System; @@ -21,7 +22,7 @@ namespace GradeBookServer.Application.Services _baseRepository = baseRepository; } - public async Task GetDirectionByIdAsync(int id) + public async Task GetDirectionByIdAsync(int id) { var direction = await _baseRepository.GetByIdWithIncludeAsync( d => d.ID == id, @@ -34,30 +35,48 @@ namespace GradeBookServer.Application.Services if (direction == null) return null; - return new DirectionDetailDto + return new DirectionReadDto { ID = direction.ID, Name = direction.Name, FacultyName = direction.Faculty?.Name ?? "—", - Disciplines = direction.Disciplines.Select(x => new DisciplineTableDto { ID = x.ID, Name = x.Name, Hours = x.TotalHours}).ToList(), - Groups = direction.Groups.Select(g => new GroupTableDto { ID = g.ID, Name = g.Name}).ToList() + Disciplines = direction.Disciplines.Select(x => new DisciplineNameDto { ID = x.ID, Name = x.Name}).ToList(), + Groups = direction.Groups.Select(g => new GroupNameDto { ID = g.ID, Name = g.Name}).ToList() }; } - public async Task?> GetAllDirectionsAsync() + public async Task?> GetAllDirectionsAsync() { - var directions = await _baseRepository.GetAllAsync( - new IncludeSpecification(d => d.Faculty!) - ); + var directions = await _baseRepository.GetAllAsync(); if (directions == null) return null; - return directions.Select(d => new DirectionTableDto + return directions.Select(d => new DirectionNameDto { ID = d.ID, - Name = d.Name, - FacultyName = d.Faculty?.Name ?? "—" + Name = d.Name + }); + } + + public async Task> GetDirectionsByFacultyIdAsync(int facultyId) + { + var directions = await _baseRepository + .WhereAsync( + d => d.FacultyID == facultyId, + new IncludeSpecification( + d => d.Faculty!, + d => d.Disciplines, + d => d.Groups) + ); + + return directions.Select(direction => new DirectionReadDto + { + ID = direction.ID, + Name = direction.Name, + FacultyName = direction.Faculty?.Name ?? "—", + Disciplines = direction.Disciplines.Select(x => new DisciplineNameDto { ID = x.ID, Name = x.Name }).ToList(), + Groups = direction.Groups.Select(g => new GroupNameDto { ID = g.ID, Name = g.Name }).ToList() }); } diff --git a/GradeBookServer.Application/Services/DisciplineService.cs b/GradeBookServer.Application/Services/DisciplineService.cs index 6bc1717..38b1903 100644 --- a/GradeBookServer.Application/Services/DisciplineService.cs +++ b/GradeBookServer.Application/Services/DisciplineService.cs @@ -1,6 +1,8 @@ using GradeBookServer.Application.Common.Specifications; using GradeBookServer.Application.DTOs.Direction; using GradeBookServer.Application.DTOs.Discipline; +using GradeBookServer.Application.DTOs.Group; +using GradeBookServer.Application.DTOs.Student; using GradeBookServer.Application.Interfaces; using GradeBookServer.Domain.Entities; using System; @@ -20,7 +22,7 @@ namespace GradeBookServer.Application.Services _baseRepository = baseRepository; } - public async Task GetDisciplineByIdAsync(int id) + public async Task GetDisciplineByIdAsync(int id) { var discipline = await _baseRepository.GetByIdWithIncludeAsync( d => d.ID == id, @@ -30,32 +32,30 @@ namespace GradeBookServer.Application.Services if (discipline == null) return null; - return new DisciplineDetailDto + return new DisciplineReadDto { ID = discipline.ID, Name = discipline.Name, Hours = discipline.TotalHours, - Directions = discipline.Directions.Select(d => new DirectionTableDto + Directions = discipline.Directions.Select(d => new DirectionNameDto { ID = d.ID, - Name = d.Name, - FacultyName = d.Faculty?.Name ?? "—" + Name = d.Name }).ToList() }; } - public async Task?> GetAllDisciplinesAsync() + public async Task?> GetAllDisciplinesAsync() { var disciplines = await _baseRepository.GetAllAsync(); if (disciplines == null) return null; - return disciplines.Select(d => new DisciplineTableDto + return disciplines.Select(d => new DisciplineNameDto { ID = d.ID, - Name = d.Name, - Hours = d.TotalHours + Name = d.Name }); } diff --git a/GradeBookServer.Application/Services/FacultyService.cs b/GradeBookServer.Application/Services/FacultyService.cs index cc1e328..6eed3b6 100644 --- a/GradeBookServer.Application/Services/FacultyService.cs +++ b/GradeBookServer.Application/Services/FacultyService.cs @@ -36,7 +36,7 @@ namespace GradeBookServer.Application.Services ID = faculty.ID, Name = faculty.Name, Directions = faculty.Directions.Select( - d => new DirectionTableDto { ID = d.ID, Name = d.Name, FacultyName = null} + d => new DirectionNameDto { ID = d.ID, Name = d.Name} ).ToList() }; } @@ -54,7 +54,7 @@ namespace GradeBookServer.Application.Services { ID = f.ID, Name = f.Name, - Directions = f.Directions.Select(d => new DirectionTableDto { ID = d.ID, Name = d.Name, FacultyName = null } + Directions = f.Directions.Select(d => new DirectionNameDto { ID = d.ID, Name = d.Name } ).ToList() }); } diff --git a/GradeBookServer.Application/Services/GroupService.cs b/GradeBookServer.Application/Services/GroupService.cs index 4ab9cdf..92d4338 100644 --- a/GradeBookServer.Application/Services/GroupService.cs +++ b/GradeBookServer.Application/Services/GroupService.cs @@ -20,7 +20,7 @@ namespace GradeBookServer.Application.Services _baseRepository = baseRepository; } - public async Task GetGroupByIdAsync(int id) + public async Task GetGroupByIdAsync(int id) { var group = await _baseRepository.GetByIdWithIncludeAsync( g => g.ID == id, @@ -30,7 +30,7 @@ namespace GradeBookServer.Application.Services if (group == null) return null; - return new GroupDetailDto + return new GroupReadDto { ID = group.ID, Name = group.Name, @@ -45,14 +45,37 @@ namespace GradeBookServer.Application.Services }; } - public async Task?> GetAllGroupsAsync() + public async Task> GetGroupsByDirectionIdAsync(int directionId) + { + var groups = await _baseRepository + .WhereAsync( + g => g.DirectionID == directionId, + new IncludeSpecification(g => g.Students!, g => g.Direction!) + ); + + return groups.Select(group => new GroupReadDto + { + ID = group.ID, + Name = group.Name, + DirectionName = group.Direction?.Name ?? "—", + Students = group.Students.Select(s => new StudentReadDto + { + ID = s.ID, + FullName = s.FullName, + Age = s.Age, + GroupName = null + }).ToList() + }); + } + + public async Task?> GetAllGroupsAsync() { var groups = await _baseRepository.GetAllAsync(); if (groups == null) return null; - return groups.Select(g => new GroupTableDto + return groups.Select(g => new GroupNameDto { ID = g.ID, Name = g.Name diff --git a/GradeBookServer.Application/Services/StudentService.cs b/GradeBookServer.Application/Services/StudentService.cs index 3b40647..24cebf1 100644 --- a/GradeBookServer.Application/Services/StudentService.cs +++ b/GradeBookServer.Application/Services/StudentService.cs @@ -5,6 +5,7 @@ using GradeBookServer.Domain.Entities; using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; @@ -56,6 +57,23 @@ namespace GradeBookServer.Application.Services }); } + public async Task> GetStudentsByGroupIdAsync(int groupId) + { + var students = await _baseRepository + .WhereAsync( + s => s.GroupID == groupId, + new IncludeSpecification(s => s.Group!) + ); + + return students.Select(s => new StudentReadDto + { + ID = s.ID, + FullName = s.FullName, + Age = s.Age, + GroupName = s.Group?.Name + }); + } + public async Task AddStudentAsync(StudentCreateDto studentDto) { var student = new Student diff --git a/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs b/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs index 86b0712..b0c1997 100644 --- a/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs +++ b/GradeBookServer.Infrastructure/Repositories/BaseRepository.cs @@ -46,6 +46,19 @@ namespace GradeBookServer.Infrastructure.Repositories return await query.ToListAsync(); } + public async Task> WhereAsync(Expression> predicate, IncludeSpecification? includeSpec = null) + { + IQueryable query = _dbSet.Where(predicate); + + if (includeSpec is not null) + { + foreach (var include in includeSpec.Includes) + query = query.Include(include); + } + + return await query.ToListAsync(); + } + public virtual async Task UpdateAsync(TEntity entity) { _dbSet.Update(entity); diff --git a/GradeBookServer.WebAPI/Controllers/DirectionsController.cs b/GradeBookServer.WebAPI/Controllers/DirectionsController.cs index 14acb46..e9489b7 100644 --- a/GradeBookServer.WebAPI/Controllers/DirectionsController.cs +++ b/GradeBookServer.WebAPI/Controllers/DirectionsController.cs @@ -1,4 +1,5 @@ using GradeBookServer.Application.DTOs.Direction; +using GradeBookServer.Application.DTOs.Group; using GradeBookServer.Application.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -18,7 +19,7 @@ namespace GradeBookServer.WebAPI.Controllers [HttpGet] [Authorize(Roles = "Employee")] - public async Task>> GetAll() + public async Task>> GetAll() { var directions = await _directionService.GetAllDirectionsAsync(); return directions == null ? NotFound() : Ok(directions); @@ -26,12 +27,20 @@ namespace GradeBookServer.WebAPI.Controllers [HttpGet("{id}")] [Authorize(Roles = "Employee")] - public async Task> GetById(int id) + public async Task> GetById(int id) { var direction = await _directionService.GetDirectionByIdAsync(id); return direction == null ? NotFound() : Ok(direction); } + [HttpGet("by-faculty/{facultyId}")] + [Authorize(Roles = "Employee")] + public async Task>> GetDirectionsByFacultyId(int facultyId) + { + var directions = await _directionService.GetDirectionsByFacultyIdAsync(facultyId); + return Ok(directions); + } + [HttpPost] [Authorize(Roles = "Employee")] public async Task Create(DirectionCreateDto dto) diff --git a/GradeBookServer.WebAPI/Controllers/DisciplineController.cs b/GradeBookServer.WebAPI/Controllers/DisciplineController.cs index ab9baed..9c3fc98 100644 --- a/GradeBookServer.WebAPI/Controllers/DisciplineController.cs +++ b/GradeBookServer.WebAPI/Controllers/DisciplineController.cs @@ -18,7 +18,7 @@ namespace GradeBookServer.WebAPI.Controllers [HttpGet] [Authorize(Roles = "Employee")] - public async Task>> GetAllDisciplines() + public async Task>> GetAllDisciplines() { var disciplines = await _disciplineService.GetAllDisciplinesAsync(); return Ok(disciplines); @@ -26,7 +26,7 @@ namespace GradeBookServer.WebAPI.Controllers [HttpGet("{id}")] [Authorize(Roles = "Employee")] - public async Task> GetDisciplineById(int id) + public async Task> GetDisciplineById(int id) { var discipline = await _disciplineService.GetDisciplineByIdAsync(id); if (discipline == null) diff --git a/GradeBookServer.WebAPI/Controllers/GroupsController.cs b/GradeBookServer.WebAPI/Controllers/GroupsController.cs index 0b517d1..3174e00 100644 --- a/GradeBookServer.WebAPI/Controllers/GroupsController.cs +++ b/GradeBookServer.WebAPI/Controllers/GroupsController.cs @@ -1,4 +1,5 @@ using GradeBookServer.Application.DTOs.Group; +using GradeBookServer.Application.DTOs.Student; using GradeBookServer.Application.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -18,7 +19,7 @@ namespace GradeBookServer.WebAPI.Controllers [HttpGet] [Authorize(Roles = "Employee")] - public async Task>> GetAll() + public async Task>> GetAll() { var groups = await _groupService.GetAllGroupsAsync(); return groups == null ? NotFound() : Ok(groups); @@ -26,12 +27,20 @@ namespace GradeBookServer.WebAPI.Controllers [HttpGet("{id}")] [Authorize(Roles = "Employee")] - public async Task> GetById(int id) + public async Task> GetById(int id) { var group = await _groupService.GetGroupByIdAsync(id); return group == null ? NotFound() : Ok(group); } + [HttpGet("by-direction/{directionId}")] + [Authorize(Roles = "Employee")] + public async Task>> GetGroupsByDirectionId(int directionId) + { + var groups = await _groupService.GetGroupsByDirectionIdAsync(directionId); + return Ok(groups); + } + [HttpPost] [Authorize(Roles = "Employee")] public async Task Create(GroupCreateDto dto) diff --git a/GradeBookServer.WebAPI/Controllers/StudentController.cs b/GradeBookServer.WebAPI/Controllers/StudentController.cs index 8b89402..3ce7711 100644 --- a/GradeBookServer.WebAPI/Controllers/StudentController.cs +++ b/GradeBookServer.WebAPI/Controllers/StudentController.cs @@ -28,6 +28,14 @@ namespace WebAPI.Controllers return Ok(students); } + [HttpGet("by-group/{groupId}")] + [Authorize(Roles = "Employee")] + public async Task>> GetStudentsByGroupId(int groupId) + { + var students = await _studentService.GetStudentsByGroupIdAsync(groupId); + return Ok(students); + } + [HttpGet("{id}")] [Authorize(Roles = "Employee")] public async Task> GetStudentById(int id) @@ -45,7 +53,7 @@ namespace WebAPI.Controllers public async Task AddStudent([FromBody] StudentCreateDto studentDto) { await _studentService.AddStudentAsync(studentDto); - return CreatedAtAction(nameof(GetStudentById), studentDto); + return Ok(); } [HttpPut("{id}")] diff --git a/GradeBookServer.WebAPI/Controllers/UsersController.cs b/GradeBookServer.WebAPI/Controllers/UsersController.cs index 2a078d6..aae1c8a 100644 --- a/GradeBookServer.WebAPI/Controllers/UsersController.cs +++ b/GradeBookServer.WebAPI/Controllers/UsersController.cs @@ -67,7 +67,6 @@ namespace GradeBookServer.WebAPI.Controllers return Ok(token); } - [Authorize] [HttpPost("cancel-session")] public IActionResult CancelSession([FromBody] string sessionId) { @@ -84,12 +83,12 @@ namespace GradeBookServer.WebAPI.Controllers return user == null ? NotFound() : Ok(user); } - [HttpGet("teachers")] + [HttpGet("professors")] [Authorize(Roles = "Employee")] public async Task GetTeachers() { - var teachers = await _service.GetTeachersAsync(); - return Ok(teachers); + var professors = await _service.GetTeachersAsync(); + return Ok(professors); } } } diff --git a/GradeBookServer.WebAPI/Properties/launchSettings.json b/GradeBookServer.WebAPI/Properties/launchSettings.json index 7ed0d49..781e4cf 100644 --- a/GradeBookServer.WebAPI/Properties/launchSettings.json +++ b/GradeBookServer.WebAPI/Properties/launchSettings.json @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "http://192.168.1.64:5142", + "applicationUrl": "http://localhost:5142", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } @@ -24,7 +24,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:7270;http://192.168.1.64:5142", + "applicationUrl": "https://192.168.1.67:7270;http://localhost:5142", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }