Merge branch 'be/registration' into 'backend'

feat: registration 수강 현황 조회 추가

See merge request s11-webmobile1-sub2/S11P12A701!113
This commit is contained in:
김한얼 2024-08-08 16:32:30 +09:00
commit 95f06da233
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,19 +74,26 @@ 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;
}