Skip to content

Commit

Permalink
Merge pull request #89 from LetsCareer-A/refactor/#88
Browse files Browse the repository at this point in the history
#88 [refactor] 커리어 조회 필터링 추가
  • Loading branch information
oosedus authored Sep 10, 2024
2 parents 91ff850 + 64d4091 commit 9fae0df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/careers")
Expand Down Expand Up @@ -47,9 +49,10 @@ public ApiResponse getCareerDetail(@RequestHeader("userId") Long userId,
@GetMapping
public ApiResponse getCareers(@RequestHeader("userId") Long userId,
@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "size", defaultValue = "15") int size) {
@RequestParam(value = "size", defaultValue = "15") int size,
@RequestParam(value = "category", defaultValue = "ACTIVITY") List<String> category) {
try {
return SuccessResponse.success(SuccessCode.GET_CAREER_SUCCESS, careerService.getCareers(userId, page, size));
return SuccessResponse.success(SuccessCode.GET_CAREER_SUCCESS, careerService.getCareers(userId, page, size, category));
} catch (NotFoundException | BadRequestException e) {
return ErrorResponse.error(e.getErrorCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public interface CareerRepository extends JpaRepository<Career, Long> {
Optional<Career> findByCareerIdAndUser(Long careerId, User user);

Page<Career> findByUser(User user, Pageable pageable);

List<Career> findByUser(User user);

Page<Career> findByUserAndCategoryIn(User user, List<String> category, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public GetCareerDetailResponse getCareerDetail(Long userId, Long careerId) {
}

@Transactional
public GetCareersResponse getCareers(Long userId, int page, int size) {
public GetCareersResponse getCareers(Long userId, int page, int size, List<String> category) {
User user = getUser(userId);
Pageable pageable = PageRequest.of(page - 1, size);
Page<Career> careers = careerRepository.findByUser(user, pageable);
Page<Career> careers = careerRepository.findByUserAndCategoryIn(user, category, pageable);
List<CareerDTO> careerDTOS = CareerConverter.convertToCareerDTOList(careers);

return GetCareersResponse.from(careers, careerDTOS);
Expand Down

0 comments on commit 9fae0df

Please sign in to comment.