Skip to content

Commit

Permalink
feat: 지원 공고 상세 API 추가
Browse files Browse the repository at this point in the history
아직 review 테이블을 만들지 않아서 테스트코드는 작성하지 않음
  • Loading branch information
tape4 committed Jul 19, 2024
1 parent 2fff34d commit 72487b5
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import org.springframework.web.bind.annotation.*;
import umc.kkijuk.server.common.LoginUser;
import umc.kkijuk.server.recruit.controller.port.RecruitService;
import umc.kkijuk.server.recruit.domain.RecruitStatusUpdate;
import umc.kkijuk.server.recruit.domain.RecruitUpdate;
import umc.kkijuk.server.recruit.controller.response.RecruitResponse;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.RecruitCreateDto;
import umc.kkijuk.server.recruit.controller.response.RecruitInfoResponse;
import umc.kkijuk.server.recruit.domain.*;
import umc.kkijuk.server.recruit.controller.response.RecruitIdResponse;

import java.util.ArrayList;

@Tag(name = "recruit", description = "모집 공고 API")
@RestController
Expand All @@ -22,12 +22,12 @@ public class RecruitController {
private final RecruitService recruitService;

@PostMapping
public ResponseEntity<RecruitResponse> create(@RequestBody @Valid RecruitCreateDto recruitCreateDto) {
public ResponseEntity<RecruitIdResponse> create(@RequestBody @Valid RecruitCreateDto recruitCreateDto) {
LoginUser loginUser = LoginUser.get();
Recruit recruit = recruitService.create(recruitCreateDto);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(RecruitResponse.from(recruit));
.body(RecruitIdResponse.from(recruit));
}

@PutMapping("/{recruitId}")
Expand Down Expand Up @@ -55,4 +55,16 @@ public ResponseEntity<Long> delete(@PathVariable long recruitId) {
.ok()
.body(recruitService.disable(recruitId).getId());
}

// review 만든 후 테스트 코드 작성
@GetMapping("/{recruitId}")
public ResponseEntity<RecruitInfoResponse> getRecruitInfo(@PathVariable long recruitId) {
LoginUser loginUser = LoginUser.get();
Recruit recruit = recruitService.getById(recruitId);
// List<Review> reviews = reviewService.getByRecruitId(recruitId);

return ResponseEntity
.ok()
.body(RecruitInfoResponse.from(recruit, new ArrayList<>()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

@Getter
@Builder
public class RecruitResponse {
public class RecruitIdResponse {
private final Long id;
public static RecruitResponse from(Recruit recruit) {
return RecruitResponse.builder()
public static RecruitIdResponse from(Recruit recruit) {
return RecruitIdResponse.builder()
.id(recruit.getId())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package umc.kkijuk.server.recruit.controller.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.domain.Review;

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

@Getter
@Builder
public class RecruitInfoResponse {
private final String title;

@Schema(description = "공고 모집 시작 날짜", example = "2022-09-18 10:11", pattern = "yyyy-MM-dd HH:mm", type = "string")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
private final LocalDateTime startTime;

@Schema(description = "공고 모집 마감 날짜", example = "2022-09-25 10:11", pattern = "yyyy-MM-dd HH:mm", type = "string" )
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm", timezone = "Asia/Seoul")
private final LocalDateTime endTime;

@Schema(description = "공고 지원 날짜", example = "2024-07-19")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
private final LocalDate applyDate;
private final List<String> tags;
private final int reviewCount;
private final String link;
private final List<ReviewResponse> reviews;

public static RecruitInfoResponse from(Recruit recruit, List<Review> reviews) {
return RecruitInfoResponse.builder()
.title(recruit.getTitle())
.startTime(recruit.getStartTime())
.endTime(recruit.getEndTime())
.applyDate(recruit.getApplyDate())
.tags(recruit.getTags())
.link(recruit.getLink())
.reviewCount(reviews.size())
.reviews(reviews.stream().map(ReviewResponse::from).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package umc.kkijuk.server.recruit.controller.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import umc.kkijuk.server.recruit.domain.Review;

import java.time.LocalDate;

@Getter
@Builder
public class ReviewResponse {
private final Long reviewId;
private final String title;
private final String content;

@Schema(description = "날짜", example = "2024-07-19")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul")
private final LocalDate date;

public static ReviewResponse from(Review review) {
return ReviewResponse.builder()
.reviewId(review.getId())
.title(review.getTitle())
.content(review.getContent())
.date(review.getDate())
.build();
}
}
5 changes: 3 additions & 2 deletions src/main/java/umc/kkijuk/server/recruit/domain/Recruit.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

@Builder
Expand All @@ -28,7 +29,7 @@ public static Recruit from(RecruitCreateDto recruitCreateDto) {
.startTime(recruitCreateDto.getStartTime())
.endTime(recruitCreateDto.getEndTime())
.applyDate(recruitCreateDto.getApplyDate())
.tags(recruitCreateDto.getTags())
.tags(recruitCreateDto.getTags() != null ? recruitCreateDto.getTags() : new ArrayList<>())
.link(recruitCreateDto.getLink())
.isActive(true)
.build();
Expand All @@ -42,7 +43,7 @@ public Recruit update(RecruitUpdate recruitUpdate) {
.startTime(recruitUpdate.getStartTime())
.endTime(recruitUpdate.getEndTime())
.applyDate(recruitUpdate.getApplyDate())
.tags(recruitUpdate.getTags())
.tags(recruitUpdate.getTags() != null ? recruitUpdate.getTags() : new ArrayList<>())
.link(recruitUpdate.getLink())
.isActive(this.isActive)
.build();
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/umc/kkijuk/server/recruit/domain/Review.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package umc.kkijuk.server.recruit.domain;

import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;

@Getter
@Builder
public class Review {
private final Long id;
private final String title;
private final String content;
private final LocalDate date;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void init() {
() -> assertThat(result.getStartTime()).isEqualTo(LocalDateTime.of(2024, 7, 19, 2, 30)),
() -> assertThat(result.getEndTime().isEqual(LocalDateTime.of(2024, 7, 30, 2, 30))),
() -> assertThat(result.getApplyDate()).isNull(),
() -> assertThat(result.getTags()).isNull(),
() -> assertThat(result.getTags().size()).isZero(),
() -> assertThat(result.getLink()).isNull()
);
}
Expand Down

0 comments on commit 72487b5

Please sign in to comment.