Skip to content

Commit

Permalink
[SL-16 CHORE] interview 필터링 쿼리 파라미터 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoungpark00 committed Dec 29, 2023
1 parent 6effd9c commit e3a32bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -27,8 +24,8 @@ public class InterviewController {

@Operation(summary = "interview 정보 조회")
@GetMapping
public ResponseEntity<List<InterviewResponse>> getInterviews() {
val response = interviewService.getInterviews();
public ResponseEntity<List<InterviewResponse>> getInterviews(@RequestParam(required = false) String part) {
val response = interviewService.getInterviews(part);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
import com.startlion.startlionserver.domain.entity.Interview;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface InterviewJpaRepository extends JpaRepository<Interview, Long> {
List<Interview> findByPart(String part);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -32,12 +33,18 @@ public InterviewDetailResponse getInterviewById(Long interviewId) {
return InterviewDetailResponse.of(interview, interviewAnswerResponses);
}

public List<InterviewResponse> getInterviews() {
return interviewJpaRepository.findAll()
.stream()
.map(interview ->
InterviewResponse.of(interview))
.toList();
public List<InterviewResponse> getInterviews(String part) {
List<Interview> interviews;

if (part == null || part.equalsIgnoreCase("ALL")) {
interviews = interviewJpaRepository.findAll();
} else {
interviews = interviewJpaRepository.findByPart(part);
}

return interviews.stream()
.map(InterviewResponse::of)
.collect(Collectors.toList());
}

@Transactional
Expand All @@ -50,6 +57,4 @@ protected Interview findById(Long interviewId) {
return interviewJpaRepository.findById(interviewId)
.orElseThrow(() -> new EntityNotFoundException("해당하는 인터뷰가 없습니다."));
}


}

0 comments on commit e3a32bb

Please sign in to comment.