From 75a4baf7828f1c172cc1371b5d05fddf8b44b149 Mon Sep 17 00:00:00 2001 From: kgc91747 Date: Fri, 2 Aug 2024 15:41:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Registration=20=EB=AF=B8=EC=8A=B9?= =?UTF-8?q?=EC=9D=B8=20=EC=88=98=EA=B0=95=EC=8B=A0=EC=B2=AD=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C,=20=EC=A4=91=EB=B3=B5=EC=8B=A0=EC=B2=AD=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/RegistrationController.java | 2 +- .../repository/RegistrationRepository.java | 1 + .../service/RegistrationService.java | 2 +- .../service/RegistrationServiceImpl.java | 20 +++++++++++-------- 4 files changed, 15 insertions(+), 10 deletions(-) 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(); + } }