Skip to content

Commit

Permalink
Feature: 교육 추가시 세션 주차 목록 반환하는 리스트 기준 변경 (#165)
Browse files Browse the repository at this point in the history
- 기존 generationId에 CS_ON인 session을 전부 반환 -> education이랑 mapping이 되지 않은 session 만 반환

Co-authored-by: Youth <[email protected]>
  • Loading branch information
gikhoon and Youthhing authored May 18, 2024
1 parent c257f86 commit 7560acf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ public ResponseEntity<Void> updateSessionPhoto(@ModelAttribute @Valid UpdateSess
public ResponseEntity<List<CsEducationOnSessionNumberResponse>> findAllCsOnSessionsByGenerationId(
@RequestParam Long generationId) {
return ResponseEntity.status(HttpStatus.OK)
.body(sessionService.findAllCsOnSessionsByGenerationId(generationId));
.body(sessionService.findAllNotLinkedCsOnSessionsByGenerationId(generationId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import cotato.csquiz.domain.entity.Generation;
import cotato.csquiz.domain.entity.Session;
import cotato.csquiz.domain.enums.CSEducation;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SessionRepository extends JpaRepository<Session, Long> {
List<Session> findAllByGeneration(Generation generation);

List<Session> findAllByGenerationId(Long generationId);
List<Session> findAllByGenerationAndCsEducation(Generation generation, CSEducation csEducation);
}
7 changes: 6 additions & 1 deletion src/main/java/cotato/csquiz/service/EducationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void validateNotEmpty(String newSubject) {
}

public List<AllEducationResponse> findEducationListByGeneration(Long generationId) {
return educationRepository.findAllByGenerationId(generationId).stream()
return findAllEducationByGenerationId(generationId).stream()
.map(AllEducationResponse::from)
.toList();
}
Expand Down Expand Up @@ -127,4 +127,9 @@ public EducationIdOfQuizResponse findEducationIdOfQuizId(Long quizId) {
.orElseThrow(() -> new EntityNotFoundException("해당 문제를 찾을 수 없습니다."));
return EducationIdOfQuizResponse.from(quiz);
}

public List<Education> findAllEducationByGenerationId(Long generationId) {
return educationRepository.findAllByGenerationId(generationId);
}
}

22 changes: 14 additions & 8 deletions src/main/java/cotato/csquiz/service/SessionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cotato.csquiz.controller.dto.session.UpdateSessionNumberRequest;
import cotato.csquiz.controller.dto.session.UpdateSessionPhotoRequest;
import cotato.csquiz.controller.dto.session.UpdateSessionRequest;
import cotato.csquiz.domain.entity.Education;
import cotato.csquiz.domain.entity.Generation;
import cotato.csquiz.domain.entity.Session;
import cotato.csquiz.domain.enums.CSEducation;
Expand All @@ -32,6 +33,7 @@ public class SessionService {
private static final String SESSION_BUCKET_DIRECTORY = "session";
private final SessionRepository sessionRepository;
private final GenerationRepository generationRepository;
private final EducationService educationService;
private final S3Uploader s3Uploader;

@Transactional
Expand Down Expand Up @@ -127,22 +129,26 @@ public List<SessionListResponse> findSessionsByGenerationId(Long generationId) {
.toList();
}

public List<CsEducationOnSessionNumberResponse> findAllCsOnSessionsByGenerationId(Long generationId) {
public Session findSessionById(Long sessionId) {
return sessionRepository.findById(sessionId)
.orElseThrow(() -> new EntityNotFoundException("해당 세션을 찾을 수 없습니다."));
}

public List<CsEducationOnSessionNumberResponse> findAllNotLinkedCsOnSessionsByGenerationId(Long generationId) {
Generation generation = generationRepository.findById(generationId)
.orElseThrow(() -> new EntityNotFoundException("해당 기수를 찾을 수 없습니다."));
List<Session> sessions = sessionRepository.findAllByGeneration(generation);
List<Session> sessions = sessionRepository.findAllByGenerationAndCsEducation(generation, CSEducation.CS_ON);

List<Long> educationLinkedSessionIds = educationService.findAllEducationByGenerationId(generationId).stream()
.map(Education::getSessionId)
.toList();

return sessions.stream()
.filter(session -> session.getCsEducation() == CSEducation.CS_ON)
.filter(session -> !educationLinkedSessionIds.contains(session.getId()))
.map(CsEducationOnSessionNumberResponse::from)
.toList();
}

private Session findSessionById(Long sessionId) {
return sessionRepository.findById(sessionId)
.orElseThrow(() -> new EntityNotFoundException("해당 세션을 찾을 수 없습니다."));
}

private boolean isImageExist(MultipartFile sessionImage) {
return sessionImage != null && !sessionImage.isEmpty();
}
Expand Down

0 comments on commit 7560acf

Please sign in to comment.