Merge branch 'be/Registration' into 'backend'

feat: Registration 미승인 수강신청 조회, 중복신청 확인 추가

See merge request s11-webmobile1-sub2/S11P12A701!28
This commit is contained in:
박정민 2024-08-02 15:47:54 +09:00
commit 176a68dfb8
4 changed files with 15 additions and 10 deletions

View File

@ -29,7 +29,7 @@ public class RegistrationController {
Long lectureId = map.get("lectureId"); Long lectureId = map.get("lectureId");
if (!registrationService.createRegistration(userId, lectureId)) { if (!registrationService.createRegistration(userId, lectureId)) {
return new ResponseEntity<>(HttpStatus.CONFLICT); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} }
return new ResponseEntity<>(HttpStatus.CREATED); return new ResponseEntity<>(HttpStatus.CREATED);

View File

@ -12,6 +12,7 @@ import java.util.List;
public interface RegistrationRepository extends JpaRepository<Registration, Long> { public interface RegistrationRepository extends JpaRepository<Registration, Long> {
List<Registration> findAllByUserId(@Param("userId") Long userId); List<Registration> findAllByUserId(@Param("userId") Long userId);
@Query("SELECT r FROM Registration r WHERE r.lecture.id = :lectureId AND r.status = 'WAITING'")
List<Registration> findAllNotAcceptedByLectureId(@Param("lectureId") Long lectureId); List<Registration> findAllNotAcceptedByLectureId(@Param("lectureId") Long lectureId);
Registration findByUserIdAndLectureId(Long userId, Long lectureId); Registration findByUserIdAndLectureId(Long userId, Long lectureId);

View File

@ -18,5 +18,5 @@ public interface RegistrationService {
List<RegistrationSearchResponse> searchRegistrations(Long LectureId); List<RegistrationSearchResponse> searchRegistrations(Long LectureId);
//RegistrationStatus getStatus(Long userId, Long lectureId); RegistrationStatus getStatus(Long userId, Long lectureId);
} }

View File

@ -34,7 +34,11 @@ public class RegistrationServiceImpl implements RegistrationService {
return false; return false;
} }
Registration registration = new Registration().builder() if (registrationRepository.findByUserIdAndLectureId(userId, lectureId) != null) {
return false;
}
Registration registration = Registration.builder()
.user(userRepository.findById(userId).get()) .user(userRepository.findById(userId).get())
.lecture(lectureRepository.findById(lectureId).get()) .lecture(lectureRepository.findById(lectureId).get())
.status(RegistrationStatus.WAITING) .status(RegistrationStatus.WAITING)
@ -76,7 +80,7 @@ public class RegistrationServiceImpl implements RegistrationService {
List<RegistrationSearchResponse> responses = new ArrayList<>(); List<RegistrationSearchResponse> responses = new ArrayList<>();
for (Registration registration : registrations) { for (Registration registration : registrations) {
RegistrationSearchResponse response = new RegistrationSearchResponse().builder() RegistrationSearchResponse response = RegistrationSearchResponse.builder()
.id(registration.getId()) .id(registration.getId())
.userName(registration.getUser().getName()) .userName(registration.getUser().getName())
.build(); .build();
@ -87,11 +91,11 @@ public class RegistrationServiceImpl implements RegistrationService {
return responses; return responses;
} }
// @Override @Override
// public RegistrationStatus getStatus(Long userId, Long lectureId) { public RegistrationStatus getStatus(Long userId, Long lectureId) {
//
// Registration registration = registrationRepository.findByUserIdAndLectureId(userId, lectureId); Registration registration = registrationRepository.findByUserIdAndLectureId(userId, lectureId);
// return registration.getStatus(); return registration.getStatus();
// } }
} }