Добавил для пользователей, дисциплин и групп получение списка по конкретной кафедре.
This commit is contained in:
@@ -57,6 +57,28 @@ public class GroupController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{departmentId}")
|
||||||
|
public ResponseEntity<?> getGroupsByDepartmentId(@PathVariable Long departmentId) {
|
||||||
|
logger.info("Получен запрос на получение списка групп для кафедры с ID - {}", departmentId);
|
||||||
|
try {
|
||||||
|
List<StudentGroup> groups = groupRepository.findByDepartmentId(departmentId);
|
||||||
|
|
||||||
|
if(groups.isEmpty()) {
|
||||||
|
logger.info("Группы для кафедры с ID - {} не найдены", departmentId);
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||||
|
.body("Группы для указанной кафедры не найдены");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Найдено {} групп для кафедры с ID - {}", groups.size(), departmentId);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(groups);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Получена ошибка при получении списка групп для кафедры с ID - {}: {}", departmentId, e.getMessage());
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Произошла ошибка при получении списка групп");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<?> createGroup(@RequestBody CreateGroupRequest request) {
|
public ResponseEntity<?> createGroup(@RequestBody CreateGroupRequest request) {
|
||||||
logger.info("Получен запрос на создание новой группы: name = {}, groupSize = {}, educationFormId = {}, departmentId = {}, course = {}",
|
logger.info("Получен запрос на создание новой группы: name = {}, groupSize = {}, educationFormId = {}, departmentId = {}, course = {}",
|
||||||
|
|||||||
@@ -47,6 +47,27 @@ public class SubjectController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{departmentId}")
|
||||||
|
public ResponseEntity<?> getSubjectsByDepartmentId(@PathVariable Long departmentId) {
|
||||||
|
logger.info("Получен запрос на получение дисциплин для кафедры с ID - {}", departmentId);
|
||||||
|
try{
|
||||||
|
List<Subject> subjects = subjectRepository.findByDepartmentId(departmentId);
|
||||||
|
|
||||||
|
if(subjects.isEmpty()){
|
||||||
|
logger.info("Дисциплины для кафедры с ID - {} не найдены", departmentId);
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||||
|
.body("Дисциплины для указанной кафедры не найдены");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Найдено {} дисциплин для кафедры с ID - {}", subjects.size(), departmentId);
|
||||||
|
return ResponseEntity.ok(subjects);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Произошла ошибка при получении списка дисциплин для кафедры с ID - {}", departmentId);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Произошла ошибка при получении списка дисциплин");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<?> createSubject(@RequestBody CreateSubjectRequest request) {
|
public ResponseEntity<?> createSubject(@RequestBody CreateSubjectRequest request) {
|
||||||
logger.info("Получен запрос на создание дисциплины: name = {}, code = {}, departmentId = {}",
|
logger.info("Получен запрос на создание дисциплины: name = {}, code = {}, departmentId = {}",
|
||||||
|
|||||||
@@ -79,6 +79,40 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/teachers/{departmentId}")
|
||||||
|
public ResponseEntity<?> getTeachersByDepartmentId(@PathVariable Long departmentId){
|
||||||
|
logger.info("Получен запрос на получение преподавателей для кафедры с ID - {}", departmentId);
|
||||||
|
try {
|
||||||
|
List<User> users = userRepository.findByRoleAndDepartmentId(Role.TEACHER, departmentId);
|
||||||
|
|
||||||
|
if (users.isEmpty()) {
|
||||||
|
logger.info("Преподаватели для кафедры с ID - {} не найдены", departmentId);
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||||
|
.body("Преподаватели для указанной кафедры не найдены");
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info("Найдено {} преподавателей для кафедры с ID - {}", users.size(), departmentId);
|
||||||
|
|
||||||
|
List<UserResponse> userResponses = users.stream()
|
||||||
|
.map( user -> {
|
||||||
|
|
||||||
|
return new UserResponse(
|
||||||
|
user.getId(),
|
||||||
|
user.getRole().name(),
|
||||||
|
user.getFullName(),
|
||||||
|
user.getJobTitle(),
|
||||||
|
user.getDepartmentId()
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
return ResponseEntity.ok(userResponses);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Произошла ошибка при получении списка преподавателей для кафедры с ID - {}: {}",departmentId, e.getMessage());
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Произошла ошибка при получении списка преподавателей");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<?> createUser(@RequestBody CreateUserRequest request) {
|
public ResponseEntity<?> createUser(@RequestBody CreateUserRequest request) {
|
||||||
logger.info("Получен запрос на создание нового пользователя: username = {}, fullName = {}, jobTitle = {}, departmentId = {}", request.getUsername(), request.getFullName(), request.getJobTitle(), request.getDepartmentId());
|
logger.info("Получен запрос на создание нового пользователя: username = {}, fullName = {}, jobTitle = {}, departmentId = {}", request.getUsername(), request.getFullName(), request.getJobTitle(), request.getDepartmentId());
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package com.magistr.app.dto;
|
package com.magistr.app.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
public class UserResponse {
|
public class UserResponse {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
@@ -21,6 +24,14 @@ public class UserResponse {
|
|||||||
this.departmentId = departmentId;
|
this.departmentId = departmentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserResponse(Long id, String role, String fullName, String jobTitle, Long departmentId) {
|
||||||
|
this.id = id;
|
||||||
|
this.role = role;
|
||||||
|
this.fullName = fullName;
|
||||||
|
this.jobTitle = jobTitle;
|
||||||
|
this.departmentId = departmentId;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ public interface GroupRepository extends JpaRepository<StudentGroup, Long> {
|
|||||||
Optional<StudentGroup> findByName(String name);
|
Optional<StudentGroup> findByName(String name);
|
||||||
|
|
||||||
List<StudentGroup> findByEducationFormId(Long educationFormId);
|
List<StudentGroup> findByEducationFormId(Long educationFormId);
|
||||||
|
|
||||||
|
List<StudentGroup> findByDepartmentId(Long departmentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package com.magistr.app.repository;
|
|||||||
import com.magistr.app.model.Subject;
|
import com.magistr.app.model.Subject;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface SubjectRepository extends JpaRepository<Subject, Long> {
|
public interface SubjectRepository extends JpaRepository<Subject, Long> {
|
||||||
Optional<Subject> findByName(String name);
|
Optional<Subject> findByName(String name);
|
||||||
|
|
||||||
|
List<Subject> findByDepartmentId(Long departmentId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
|||||||
Optional<User> findByUsername(String username);
|
Optional<User> findByUsername(String username);
|
||||||
|
|
||||||
List<User> findByRole(Role role);
|
List<User> findByRole(Role role);
|
||||||
|
|
||||||
|
List<User> findByRoleAndDepartmentId(Role role, Long departmentId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user