Skip to content

Commit

Permalink
Feat: Review 추가로 인한 지원 공고 상세 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
tape4 committed Jul 21, 2024
1 parent 62e6af5 commit 7d3d359
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package umc.kkijuk.server.common.domian.exception;

public class ReviewRecruitNotMatchException extends RuntimeException{
public ReviewRecruitNotMatchException(long reviewId, long recruitId, long requestedRecruitId) {
super("Review " + reviewId + "의 Recruit ID " + recruitId + "가 요청한 " + requestedRecruitId + "와 일치하지 않습니다.");
public ReviewRecruitNotMatchException(long recruitId, long reviewId) {
super("Recruit "+ recruitId + "에서 Review " + reviewId + "를 찾을수 없습니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import umc.kkijuk.server.recruit.controller.response.RecruitListByEndTimeAfterResponse;
import umc.kkijuk.server.recruit.domain.*;
import umc.kkijuk.server.recruit.controller.response.RecruitIdResponse;
import umc.kkijuk.server.review.controller.port.ReviewService;
import umc.kkijuk.server.review.domain.Review;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Tag(name = "recruit", description = "모집 공고 API")
Expand All @@ -28,6 +29,7 @@
@RequestMapping("/recruit")
public class RecruitController {
private final RecruitService recruitService;
private final ReviewService reviewService;

@Operation(
summary = "지원 공고 생성",
Expand Down Expand Up @@ -79,7 +81,6 @@ public ResponseEntity<Long> delete(@PathVariable long recruitId) {
.body(recruitService.disable(recruitId).getId());
}

// review 만든 후 테스트 코드 작성
@Operation(
summary = "지원 공고 상세",
description = "지원 공고 ID에 해당하는 공고의 상세 정보를 요청합니다.")
Expand All @@ -88,11 +89,11 @@ public ResponseEntity<Long> delete(@PathVariable long recruitId) {
public ResponseEntity<RecruitInfoResponse> getRecruitInfo(@PathVariable long recruitId) {
LoginUser loginUser = LoginUser.get();
Recruit recruit = recruitService.getById(recruitId);
// List<Review> reviews = reviewService.getByRecruitId(recruitId);
List<Review> reviews = reviewService.findAllByRecruitId(recruitId);

return ResponseEntity
.ok()
.body(RecruitInfoResponse.from(recruit, new ArrayList<>()));
.body(RecruitInfoResponse.from(recruit, reviews));
}
@Operation(
summary = "지원 공고 목록 (특정 날짜 이후)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import lombok.Builder;
import lombok.Getter;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.Review;
import umc.kkijuk.server.review.domain.Review;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import umc.kkijuk.server.recruit.domain.Review;
import umc.kkijuk.server.review.domain.Review;

import java.time.LocalDate;

Expand Down
15 changes: 0 additions & 15 deletions src/main/java/umc/kkijuk/server/recruit/domain/Review.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import umc.kkijuk.server.review.domain.ReviewCreate;
import umc.kkijuk.server.review.domain.ReviewUpdate;

import java.util.List;

public interface ReviewService {
Review create(Recruit recruit, ReviewCreate reviewCreate);

Review update(Recruit recruit, Long reviewId, ReviewUpdate reviewUpdate);

List<Review> findAllByRecruitId(Long recruitId);

Review getById(Long reviewId);

void delete(Recruit recruit, Long reviewId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ReviewJpaRepository extends JpaRepository<ReviewEntity, Long> {
List<ReviewEntity> findAllByRecruitId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import umc.kkijuk.server.review.domain.Review;
import umc.kkijuk.server.review.service.port.ReviewRepository;

import java.util.List;
import java.util.Optional;

@Repository
Expand Down Expand Up @@ -33,4 +34,9 @@ public Review getById(Long id) {
public void delete(Review review) {
reviewJpaRepository.delete(ReviewEntity.from(review));
}

@Override
public List<Review> findAllByRecruitId(Long id) {
return reviewJpaRepository.findAllByRecruitId(id).stream().map(ReviewEntity::toModel).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@
import umc.kkijuk.server.review.domain.ReviewUpdate;
import umc.kkijuk.server.review.service.port.ReviewRepository;

import java.util.List;

@Service
@Builder
@RequiredArgsConstructor
public class ReviewServiceImpl implements ReviewService {
private final ReviewRepository reviewRepository;

@Override
public List<Review> findAllByRecruitId(Long recruitId) {
return reviewRepository.findAllByRecruitId(recruitId);
}

public Review getById(Long id) {
return reviewRepository.getById(id);
}
Expand All @@ -34,7 +41,7 @@ public Review create(Recruit recruit, ReviewCreate reviewCreate) {
public Review update(Recruit recruit, Long reviewId, ReviewUpdate reviewUpdate) {
Review review = getById(reviewId);
if (!review.getRecruitId().equals(recruit.getId())) {
throw new ReviewRecruitNotMatchException(reviewId, review.getRecruitId(), review.getId());
throw new ReviewRecruitNotMatchException(recruit.getId(), reviewId);
}

review = review.update(reviewUpdate);
Expand All @@ -45,7 +52,7 @@ public Review update(Recruit recruit, Long reviewId, ReviewUpdate reviewUpdate)
public void delete(Recruit recruit, Long reviewId) {
Review review = getById(reviewId);
if (!review.getRecruitId().equals(recruit.getId())) {
throw new ReviewRecruitNotMatchException(reviewId, review.getRecruitId(), review.getId());
throw new ReviewRecruitNotMatchException(recruit.getId(), reviewId);
}

reviewRepository.delete(review);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import umc.kkijuk.server.review.domain.Review;

import java.util.List;
import java.util.Optional;

public interface ReviewRepository {
Expand All @@ -12,4 +13,6 @@ public interface ReviewRepository {
Review getById(Long id);

void delete(Review review);

List<Review> findAllByRecruitId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,11 @@ public Review getById(Long id) {
public void delete(Review review) {
data.remove(review);
}

@Override
public List<Review> findAllByRecruitId(Long id) {
return data.stream()
.filter(review -> review.getRecruitId().equals(id))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import umc.kkijuk.server.review.service.port.ReviewRepository;

import java.time.LocalDate;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
Expand Down Expand Up @@ -179,4 +180,23 @@ void Init() {
assertThatThrownBy(
() -> reviewService.delete(recruit_2, review.getId())).isInstanceOf(ReviewRecruitNotMatchException.class);
}

@Test
void findAllByRecruitId_공고의_모든_review찾기() {
//given
Recruit recruit = Recruit.builder().id(3333L).build();
ReviewCreate reviewCreate = ReviewCreate.builder()
.title("new-title")
.content("new-content")
.date(LocalDate.of(2024, 7, 21))
.build();
for (int i = 0; i < 10; i++)
reviewService.create(recruit, reviewCreate);

//when
List<Review> reviews = reviewService.findAllByRecruitId(recruit.getId());

//then
assertThat(reviews.size()).isEqualTo(10);
}
}

0 comments on commit 7d3d359

Please sign in to comment.