Skip to content

Commit

Permalink
[refactor] 중복 코드 합치기
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunihs committed Aug 31, 2023
1 parent bb185a5 commit 998cde6
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ceos.backend.domain.recruitment;


import ceos.backend.domain.recruitment.dto.request.UpdateRecruitmentRequest;
import ceos.backend.domain.recruitment.dto.response.GetRecruitmentResponse;
import ceos.backend.domain.recruitment.dto.response.OpenChatUrlResponse;
import ceos.backend.domain.recruitment.dto.RecruitmentDTO;
import ceos.backend.domain.recruitment.dto.UserRecruitmentDTO;
import ceos.backend.domain.recruitment.service.RecruitmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -21,25 +20,24 @@ public class RecruitmentController {

private final RecruitmentService recruitmentService;

@Operation(summary = "리크루팅 정보 보기")
@GetMapping
public GetRecruitmentResponse getRecruitment() {
@Operation(summary = "모든 리크루팅 정보 보기 (오픈채팅 포함)")
@GetMapping("/all")
public RecruitmentDTO getRecruitment() {
log.info("리크루팅 정보 보기");
return recruitmentService.getRecruitment();
}

@Operation(summary = "오픈채팅 링크")
@GetMapping("/openchat")
public OpenChatUrlResponse getOpenChatUrl() {
@Operation(summary = "리크루팅 정보 보기")
@GetMapping
public UserRecruitmentDTO getOpenChatUrl() {
log.info("오픈채팅 링크");
return recruitmentService.getOpenChatUrl();
}

@Operation(summary = "리크루팅 정보 수정")
@PutMapping
public void updateRecruitment(
@RequestBody @Valid UpdateRecruitmentRequest updateRecruitmentRequest) {
public void updateRecruitment(@RequestBody @Valid RecruitmentDTO recruitmentDTO) {
log.info("리크루팅 정보 수정");
recruitmentService.updateRecruitment(updateRecruitmentRequest);
recruitmentService.updateRecruitment(recruitmentDTO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import ceos.backend.domain.admin.exception.NotAllowedToModify;
import ceos.backend.domain.application.exception.exceptions.WrongGeneration;
import ceos.backend.domain.recruitment.dto.request.UpdateRecruitmentRequest;
import ceos.backend.domain.recruitment.dto.RecruitmentDTO;
import ceos.backend.domain.recruitment.exception.*;
import ceos.backend.global.common.entity.BaseEntity;
import jakarta.persistence.*;
Expand Down Expand Up @@ -86,20 +86,20 @@ private Recruitment(
this.applicationExcelCreatedAt = applicationExcelCreatedAt;
}

public void updateRecruitment(UpdateRecruitmentRequest updateRecruitmentRequest) {
this.generation = updateRecruitmentRequest.getGeneration();
this.prodStudyUrl = updateRecruitmentRequest.getProdStudyUrl();
this.designStudyUrl = updateRecruitmentRequest.getDesignStudyUrl();
this.devStudyUrl = updateRecruitmentRequest.getDevStudyUrl();
this.startDateDoc = updateRecruitmentRequest.getStartDateDoc();
this.endDateDoc = updateRecruitmentRequest.getEndDateDoc();
this.resultDateDoc = updateRecruitmentRequest.getResultDateDoc();
this.startDateInterview = updateRecruitmentRequest.getStartDateInterview();
this.endDateInterview = updateRecruitmentRequest.getEndDateInterview();
this.resultDateFinal = updateRecruitmentRequest.getResultDateFinal();
this.openChatUrl = updateRecruitmentRequest.getOpenChatUrl();
this.otDate = updateRecruitmentRequest.getOtDate();
this.demodayDate = updateRecruitmentRequest.getDemodayDate();
public void updateRecruitment(RecruitmentDTO recruitmentDTO) {
this.generation = recruitmentDTO.getGeneration();
this.prodStudyUrl = recruitmentDTO.getProdStudyUrl();
this.designStudyUrl = recruitmentDTO.getDesignStudyUrl();
this.devStudyUrl = recruitmentDTO.getDevStudyUrl();
this.startDateDoc = recruitmentDTO.getStartDateDoc();
this.endDateDoc = recruitmentDTO.getEndDateDoc();
this.resultDateDoc = recruitmentDTO.getResultDateDoc();
this.startDateInterview = recruitmentDTO.getStartDateInterview();
this.endDateInterview = recruitmentDTO.getEndDateInterview();
this.resultDateFinal = recruitmentDTO.getResultDateFinal();
this.openChatUrl = recruitmentDTO.getOpenChatUrl();
this.otDate = recruitmentDTO.getOtDate();
this.demodayDate = recruitmentDTO.getDemodayDate();
}

public void updateApplicationExcelCreatedAt(LocalDateTime createdAt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package ceos.backend.domain.recruitment.dto;


import ceos.backend.domain.recruitment.domain.Recruitment;
import java.time.LocalDate;
import lombok.Builder;
import lombok.Getter;

@Getter
public class RecruitmentDTO {
private int generation;
private String prodStudyUrl;
private String designStudyUrl;
private String devStudyUrl;
private LocalDate startDateDoc;
private LocalDate endDateDoc;
private LocalDate resultDateDoc;
private LocalDate startDateInterview;
private LocalDate endDateInterview;
private LocalDate resultDateFinal;
private String openChatUrl;
private LocalDate otDate;
private LocalDate demodayDate;

@Builder
public RecruitmentDTO(
int generation,
String prodStudyUrl,
String designStudyUrl,
String devStudyUrl,
LocalDate startDateDoc,
LocalDate endDateDoc,
LocalDate resultDateDoc,
LocalDate startDateInterview,
LocalDate endDateInterview,
LocalDate resultDateFinal,
String openChatUrl,
LocalDate otDate,
LocalDate demodayDate) {
this.generation = generation;
this.prodStudyUrl = prodStudyUrl;
this.designStudyUrl = designStudyUrl;
this.devStudyUrl = devStudyUrl;
this.startDateDoc = startDateDoc;
this.endDateDoc = endDateDoc;
this.resultDateDoc = resultDateDoc;
this.startDateInterview = startDateInterview;
this.endDateInterview = endDateInterview;
this.resultDateFinal = resultDateFinal;
this.openChatUrl = openChatUrl;
this.otDate = otDate;
this.demodayDate = demodayDate;
}

public static RecruitmentDTO from(Recruitment recruitment) {
return RecruitmentDTO.builder()
.generation(recruitment.getGeneration())
.prodStudyUrl(recruitment.getProdStudyUrl())
.designStudyUrl(recruitment.getDesignStudyUrl())
.devStudyUrl(recruitment.getDevStudyUrl())
.startDateDoc(recruitment.getStartDateDoc())
.endDateDoc(recruitment.getEndDateDoc())
.resultDateDoc(recruitment.getResultDateDoc())
.startDateInterview(recruitment.getStartDateInterview())
.endDateInterview(recruitment.getEndDateInterview())
.resultDateFinal(recruitment.getResultDateFinal())
.openChatUrl(recruitment.getOpenChatUrl())
.otDate(recruitment.getOtDate())
.demodayDate(recruitment.getDemodayDate())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ceos.backend.domain.recruitment.dto.response;
package ceos.backend.domain.recruitment.dto;


import ceos.backend.domain.recruitment.domain.Recruitment;
Expand All @@ -7,8 +7,7 @@
import lombok.Getter;

@Getter
@Builder
public class GetRecruitmentResponse {
public class UserRecruitmentDTO {
private int generation;
private String prodStudyUrl;
private String designStudyUrl;
Expand All @@ -22,8 +21,36 @@ public class GetRecruitmentResponse {
private LocalDate otDate;
private LocalDate demodayDate;

public static GetRecruitmentResponse from(Recruitment recruitment) {
return GetRecruitmentResponse.builder()
@Builder
public UserRecruitmentDTO(
int generation,
String prodStudyUrl,
String designStudyUrl,
String devStudyUrl,
LocalDate startDateDoc,
LocalDate endDateDoc,
LocalDate resultDateDoc,
LocalDate startDateInterview,
LocalDate endDateInterview,
LocalDate resultDateFinal,
LocalDate otDate,
LocalDate demodayDate) {
this.generation = generation;
this.prodStudyUrl = prodStudyUrl;
this.designStudyUrl = designStudyUrl;
this.devStudyUrl = devStudyUrl;
this.startDateDoc = startDateDoc;
this.endDateDoc = endDateDoc;
this.resultDateDoc = resultDateDoc;
this.startDateInterview = startDateInterview;
this.endDateInterview = endDateInterview;
this.resultDateFinal = resultDateFinal;
this.otDate = otDate;
this.demodayDate = demodayDate;
}

public static UserRecruitmentDTO from(Recruitment recruitment) {
return UserRecruitmentDTO.builder()
.generation(recruitment.getGeneration())
.prodStudyUrl(recruitment.getProdStudyUrl())
.designStudyUrl(recruitment.getDesignStudyUrl())
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@


import ceos.backend.domain.recruitment.domain.Recruitment;
import ceos.backend.domain.recruitment.dto.request.UpdateRecruitmentRequest;
import ceos.backend.domain.recruitment.dto.response.GetRecruitmentResponse;
import ceos.backend.domain.recruitment.dto.response.OpenChatUrlResponse;
import ceos.backend.domain.recruitment.dto.RecruitmentDTO;
import ceos.backend.domain.recruitment.dto.UserRecruitmentDTO;
import ceos.backend.domain.recruitment.helper.RecruitmentHelper;
import ceos.backend.domain.recruitment.repository.RecruitmentRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -22,22 +21,22 @@ public class RecruitmentService {
private final RecruitmentHelper recruitmentHelper;

@Transactional(readOnly = true)
public GetRecruitmentResponse getRecruitment() {
public RecruitmentDTO getRecruitment() {
Recruitment recruitment = recruitmentHelper.takeRecruitment();
return GetRecruitmentResponse.from(recruitment);
return RecruitmentDTO.from(recruitment);
}

public OpenChatUrlResponse getOpenChatUrl() {
public UserRecruitmentDTO getOpenChatUrl() {
Recruitment recruitment = recruitmentHelper.takeRecruitment();
return OpenChatUrlResponse.from(recruitment);
return UserRecruitmentDTO.from(recruitment);
}

@Transactional
public void updateRecruitment(UpdateRecruitmentRequest updateRecruitmentRequest) {
public void updateRecruitment(RecruitmentDTO recruitmentDTO) {
Recruitment recruitment = recruitmentHelper.takeRecruitment();

// 객체 업데이트
recruitment.updateRecruitment(updateRecruitmentRequest);
recruitment.updateRecruitment(recruitmentDTO);
recruitmentRepository.save(recruitment);
}
}

0 comments on commit 998cde6

Please sign in to comment.