-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
396 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/umc/kkijuk/server/review/controller/ReviewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package umc.kkijuk.server.review.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
import umc.kkijuk.server.recruit.controller.port.RecruitService; | ||
import umc.kkijuk.server.recruit.domain.Recruit; | ||
import umc.kkijuk.server.review.controller.port.ReviewService; | ||
import umc.kkijuk.server.review.controller.response.ReviewIdResponse; | ||
import umc.kkijuk.server.review.domain.Review; | ||
import umc.kkijuk.server.review.domain.ReviewCreate; | ||
|
||
@Tag(name = "review", description = "모집 공고 후기 API") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/recruit/{recruitId}") | ||
public class ReviewController { | ||
private final ReviewService reviewService; | ||
private final RecruitService recruitService; | ||
|
||
@Operation( | ||
summary = "지원 공고 후기 추가", | ||
description = "주어진 지원 공고에 후기를 생성합니다") | ||
@Parameter(name = "recruitId", description = "지원 공고 ID", example = "1") | ||
@PostMapping("/review") | ||
public ResponseEntity<ReviewIdResponse> create( | ||
@PathVariable Long recruitId, | ||
@RequestBody @Valid ReviewCreate reviewCreate | ||
) { | ||
Recruit recruit = recruitService.getById(recruitId); | ||
Review review = reviewService.create(recruit, reviewCreate); | ||
|
||
return ResponseEntity | ||
.ok() | ||
.body(ReviewIdResponse.from(review)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/umc/kkijuk/server/review/controller/port/ReviewService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package umc.kkijuk.server.review.controller.port; | ||
|
||
import umc.kkijuk.server.recruit.domain.Recruit; | ||
import umc.kkijuk.server.review.domain.Review; | ||
import umc.kkijuk.server.review.domain.ReviewCreate; | ||
|
||
public interface ReviewService { | ||
Review create(Recruit recruit, ReviewCreate reviewCreate); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/umc/kkijuk/server/review/controller/response/ReviewIdResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package umc.kkijuk.server.review.controller.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import umc.kkijuk.server.review.domain.Review; | ||
|
||
@Getter | ||
@Builder | ||
public class ReviewIdResponse { | ||
private Long id; | ||
|
||
public static ReviewIdResponse from(Review review) { | ||
return ReviewIdResponse.builder() | ||
.id(review.getId()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package umc.kkijuk.server.review.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import umc.kkijuk.server.recruit.domain.Recruit; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Builder | ||
public class Review { | ||
private final Long id; | ||
private final Long recruitId; | ||
private final String title; | ||
private final String content; | ||
private final LocalDate date; | ||
|
||
public static Review from(Recruit recruit, ReviewCreate reviewCreate) { | ||
return Review.builder() | ||
.recruitId(recruit.getId()) | ||
.title(reviewCreate.getTitle()) | ||
.content(reviewCreate.getContent()) | ||
.date(reviewCreate.getDate()) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/umc/kkijuk/server/review/domain/ReviewCreate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package umc.kkijuk.server.review.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ReviewCreate { | ||
|
||
@NotBlank(message = "공고 후기 제목은 필수 입력 항목입니다.") | ||
@Schema(description = "공고 후기 제목", example = "코딩 테스트", type = "string") | ||
private String title; | ||
|
||
@Schema(description = "공고 후기 내용", example = "Dijkstra 알고리즘을 활용하는 문제", type = "string") | ||
private String content; | ||
|
||
@NotNull(message = "날짜는 필수 입력 항목입니다.") | ||
@Schema(description = "날짜", example = "2024-07-21", pattern = "yyyy-MM-dd") | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") | ||
private LocalDate date; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/umc/kkijuk/server/review/infrastructure/ReviewEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package umc.kkijuk.server.review.infrastructure; | ||
|
||
import jakarta.persistence.*; | ||
import umc.kkijuk.server.review.domain.Review; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Entity | ||
@Table(name = "review") | ||
public class ReviewEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long recruitId; | ||
@Column(nullable = false) | ||
private String title; | ||
private String content; | ||
@Column(nullable = false) | ||
private LocalDate date; | ||
|
||
|
||
public static ReviewEntity from(Review review) { | ||
ReviewEntity reviewEntity = new ReviewEntity(); | ||
reviewEntity.id = review.getId(); | ||
reviewEntity.recruitId = review.getRecruitId(); | ||
reviewEntity.title = review.getTitle(); | ||
reviewEntity.content = review.getContent(); | ||
reviewEntity.date = review.getDate(); | ||
return reviewEntity; | ||
} | ||
|
||
public Review toModel() { | ||
return Review.builder() | ||
.id(id) | ||
.recruitId(recruitId) | ||
.title(title) | ||
.content(content) | ||
.date(date) | ||
.build(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/umc/kkijuk/server/review/infrastructure/ReviewJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package umc.kkijuk.server.review.infrastructure; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReviewJpaRepository extends JpaRepository<ReviewEntity, Long> { | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/umc/kkijuk/server/review/infrastructure/ReviewRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package umc.kkijuk.server.review.infrastructure; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; | ||
import umc.kkijuk.server.review.domain.Review; | ||
import umc.kkijuk.server.review.service.port.ReviewRepository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ReviewRepositoryImpl implements ReviewRepository { | ||
private final ReviewJpaRepository reviewJpaRepository; | ||
|
||
@Override | ||
public Review save(Review review) { | ||
return reviewJpaRepository.save(ReviewEntity.from(review)).toModel(); | ||
} | ||
|
||
@Override | ||
public Optional<Review> findById(Long id) { | ||
return reviewJpaRepository.findById(id).map(ReviewEntity::toModel); | ||
} | ||
|
||
@Override | ||
public Review getById(Long id) { | ||
return findById(id) | ||
.orElseThrow(() -> new ResourceNotFoundException("recruit", id)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/umc/kkijuk/server/review/service/ReviewServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package umc.kkijuk.server.review.service; | ||
|
||
import lombok.Builder; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import umc.kkijuk.server.recruit.domain.Recruit; | ||
import umc.kkijuk.server.review.controller.port.ReviewService; | ||
import umc.kkijuk.server.review.domain.Review; | ||
import umc.kkijuk.server.review.domain.ReviewCreate; | ||
import umc.kkijuk.server.review.service.port.ReviewRepository; | ||
|
||
@Service | ||
@Builder | ||
@RequiredArgsConstructor | ||
public class ReviewServiceImpl implements ReviewService { | ||
private final ReviewRepository reviewRepository; | ||
|
||
public Review getById(Long id) { | ||
return reviewRepository.getById(id); | ||
} | ||
|
||
@Override | ||
@Transactional //멤버 + recruit 사이의 인가 예외처리 | ||
public Review create(Recruit recruit, ReviewCreate reviewCreate) { | ||
Review review = Review.from(recruit, reviewCreate); | ||
System.out.println("review.getRecruitId() = " + review.getRecruitId()); | ||
return reviewRepository.save(review); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/umc/kkijuk/server/review/service/port/ReviewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package umc.kkijuk.server.review.service.port; | ||
|
||
import umc.kkijuk.server.review.domain.Review; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ReviewRepository { | ||
Review save(Review review); | ||
|
||
Optional<Review> findById(Long id); | ||
|
||
Review getById(Long id); | ||
} |
Oops, something went wrong.