diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java b/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java index 6e008fe..4b8bba3 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/controller/RegistrationController.java @@ -29,7 +29,7 @@ public class RegistrationController { Long lectureId = map.get("lectureId"); if (!registrationService.createRegistration(userId, lectureId)) { - return new ResponseEntity<>(HttpStatus.CONFLICT); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } return new ResponseEntity<>(HttpStatus.CREATED); diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java index f8c31b7..ef2c721 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/repository/RegistrationRepository.java @@ -12,6 +12,7 @@ import java.util.List; public interface RegistrationRepository extends JpaRepository { List findAllByUserId(@Param("userId") Long userId); + @Query("SELECT r FROM Registration r WHERE r.lecture.id = :lectureId AND r.status = 'WAITING'") List findAllNotAcceptedByLectureId(@Param("lectureId") Long lectureId); Registration findByUserIdAndLectureId(Long userId, Long lectureId); diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java index d1cc462..b01c410 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationService.java @@ -18,5 +18,5 @@ public interface RegistrationService { List searchRegistrations(Long LectureId); - //RegistrationStatus getStatus(Long userId, Long lectureId); + RegistrationStatus getStatus(Long userId, Long lectureId); } diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java index 0225f44..4e69660 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/service/RegistrationServiceImpl.java @@ -34,7 +34,11 @@ public class RegistrationServiceImpl implements RegistrationService { return false; } - Registration registration = new Registration().builder() + if (registrationRepository.findByUserIdAndLectureId(userId, lectureId) != null) { + return false; + } + + Registration registration = Registration.builder() .user(userRepository.findById(userId).get()) .lecture(lectureRepository.findById(lectureId).get()) .status(RegistrationStatus.WAITING) @@ -76,7 +80,7 @@ public class RegistrationServiceImpl implements RegistrationService { List responses = new ArrayList<>(); for (Registration registration : registrations) { - RegistrationSearchResponse response = new RegistrationSearchResponse().builder() + RegistrationSearchResponse response = RegistrationSearchResponse.builder() .id(registration.getId()) .userName(registration.getUser().getName()) .build(); @@ -87,11 +91,11 @@ public class RegistrationServiceImpl implements RegistrationService { return responses; } -// @Override -// public RegistrationStatus getStatus(Long userId, Long lectureId) { -// -// Registration registration = registrationRepository.findByUserIdAndLectureId(userId, lectureId); -// return registration.getStatus(); -// } + @Override + public RegistrationStatus getStatus(Long userId, Long lectureId) { + + Registration registration = registrationRepository.findByUserIdAndLectureId(userId, lectureId); + return registration.getStatus(); + } }