Skip to content

Commit

Permalink
Feat: 지원 공고 후기 작성 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tape4 committed Jul 21, 2024
1 parent afcd1b9 commit c92f3ae
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class RecruitController {
summary = "지원 공고 생성",
description = "주어진 정보를 바탕으로 지원 공고 데이터를 생성합니다.")
@PostMapping
public ResponseEntity<RecruitIdResponse> create(@RequestBody @Valid RecruitCreateDto recruitCreateDto) {
public ResponseEntity<RecruitIdResponse> create(@RequestBody @Valid RecruitCreate recruitCreate) {
LoginUser loginUser = LoginUser.get();
Recruit recruit = recruitService.create(recruitCreateDto);
Recruit recruit = recruitService.create(recruitCreate);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(RecruitIdResponse.from(recruit));
Expand Down Expand Up @@ -120,4 +120,10 @@ public ResponseEntity<RecruitListByEndTimeAfterResponse> findAllRecruitListByEnd
.ok()
.body(RecruitListByEndTimeAfterResponse.from(recruits));
}

// 멤버 추가시 추가
// @GetMapping("/list/valid")
// public ResponseEntity<ValidRecruitListResponse> findValidRecruit() {
//
// }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package umc.kkijuk.server.recruit.controller.port;

import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitCreateDto;
import umc.kkijuk.server.recruit.domain.RecruitCreate;
import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;

Expand All @@ -10,7 +10,7 @@
import java.util.List;

public interface RecruitService {
Recruit create(RecruitCreateDto recruitCreateDto);
Recruit create(RecruitCreate recruitCreate);

Recruit update(Long recruitId, RecruitUpdate recruitUpdate);

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ public class Recruit {
private final boolean active;
private final LocalDateTime disabledTime;

public static Recruit from(RecruitCreateDto recruitCreateDto) {
public static Recruit from(RecruitCreate recruitCreate) {
return Recruit.builder()
.title(recruitCreateDto.getTitle())
.status(recruitCreateDto.getStatus())
.startTime(recruitCreateDto.getStartTime())
.endTime(recruitCreateDto.getEndTime())
.applyDate(recruitCreateDto.getApplyDate())
.tags(recruitCreateDto.getTags() != null ? recruitCreateDto.getTags() : new ArrayList<>())
.link(recruitCreateDto.getLink())
.title(recruitCreate.getTitle())
.status(recruitCreate.getStatus())
.startTime(recruitCreate.getStartTime())
.endTime(recruitCreate.getEndTime())
.applyDate(recruitCreate.getApplyDate())
.tags(recruitCreate.getTags() != null ? recruitCreate.getTags() : new ArrayList<>())
.link(recruitCreate.getLink())
.active(true)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RecruitCreateDto {
public class RecruitCreate {
@NotBlank(message = "공고 제목은 필수 입력 항목입니다.")
@Schema(description = "공고 제목", example = "[00] 공고제목", type = "string")
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException;
import umc.kkijuk.server.recruit.controller.port.RecruitService;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitCreateDto;
import umc.kkijuk.server.recruit.domain.RecruitCreate;
import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;
import umc.kkijuk.server.recruit.service.port.RecruitRepository;
Expand All @@ -31,8 +31,8 @@ public Recruit getById(long id) {

@Override
@Transactional
public Recruit create(RecruitCreateDto recruitCreateDto) {
Recruit recruit = Recruit.from(recruitCreateDto);
public Recruit create(RecruitCreate recruitCreate) {
Recruit recruit = Recruit.from(recruitCreate);
return recruitRepository.save(recruit);
}

Expand Down
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));
}
}
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);
}
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();
}
}
26 changes: 26 additions & 0 deletions src/main/java/umc/kkijuk/server/review/domain/Review.java
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 src/main/java/umc/kkijuk/server/review/domain/ReviewCreate.java
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;
}
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();
}
}
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> {
}
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));
}
}
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);
}
}
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);
}
Loading

0 comments on commit c92f3ae

Please sign in to comment.