feat: registration 수강 현황 조회 추가

This commit is contained in:
kgc91747 2024-08-08 16:31:12 +09:00
parent 7f20b2f1ae
commit 159125a12a
3 changed files with 13 additions and 7 deletions

View File

@ -13,8 +13,7 @@ import java.util.List;
public interface RegistrationRepository extends JpaRepository<Registration, Long> {
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> findAllByLectureId(Long lectureId);
Registration findByUserIdAndLectureId(Long userId, Long lectureId);

View File

@ -16,7 +16,7 @@ public interface RegistrationService {
boolean deleteRegistration(Long userId, Long registrationId);
List<RegistrationSearchResponse> searchRegistrations(Long LectureId);
List<RegistrationSearchResponse>[] searchRegistrations(Long LectureId);
RegistrationStatus getStatus(Long userId, Long lectureId);
}

View File

@ -74,18 +74,25 @@ public class RegistrationServiceImpl implements RegistrationService {
}
@Override
public List<RegistrationSearchResponse> searchRegistrations(Long lectureId) {
List<Registration> registrations = registrationRepository.findAllNotAcceptedByLectureId(lectureId);
public List<RegistrationSearchResponse>[] searchRegistrations(Long lectureId) {
List<Registration> registrations = registrationRepository.findAllByLectureId(lectureId);
List<RegistrationSearchResponse> responses = new ArrayList<>();
List<RegistrationSearchResponse>[] responses = new ArrayList[2];
responses[0] = new ArrayList<>();
responses[1] = new ArrayList<>();
for (Registration registration : registrations) {
RegistrationSearchResponse response = RegistrationSearchResponse.builder()
.id(registration.getId())
.userName(registration.getUser().getName())
.build();
responses.add(response);
if (registration.getStatus() == RegistrationStatus.ACCEPTED) {
responses[0].add(response);
} else {
responses[1].add(response);
}
}
return responses;
}