Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[넬리] 자기소개서 CRUD 및 마스터 자기소개서 응답 수정 #15

Merged
merged 9 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,125 @@
package umc.kkijuk.server.introduce.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import umc.kkijuk.server.introduce.common.BaseResponse;
import umc.kkijuk.server.introduce.dto.*;
import umc.kkijuk.server.introduce.error.BaseErrorResponse;
import umc.kkijuk.server.introduce.error.BaseException;
import umc.kkijuk.server.introduce.service.IntroduceService;

import java.util.List;

@Tag(name = "introduce", description = "자기소개서 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/history/intro/")
@Slf4j
public class IntroduceController {
private final IntroduceService introduceService;

@PostMapping("/{recruitId}")
@Operation(summary = "자기소개서 생성")
public ResponseEntity<Object> save(@PathVariable("recruitId") Long recruitId, @RequestBody IntroduceReqDto introduceReqDto){
try {
IntroduceResDto introduceResDto = introduceService.saveIntro(recruitId, introduceReqDto);
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 생성 완료", introduceResDto));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@GetMapping("detail/{introId}")
@Operation(summary = "자기소개서 개별 조회")
public ResponseEntity<Object> get(@PathVariable("introId") Long introId){
try {
IntroduceResDto introduceResDto = introduceService.getIntro(introId);
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 조회 완료", introduceResDto));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@GetMapping("list")
@Operation(summary = "자기소개서 목록 조회")
public ResponseEntity<Object> getList(){
try {
List<IntroduceListResDto> introduceListResDtos = introduceService.getIntroList();
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 목록 조회 완료", introduceListResDtos));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@PatchMapping("/{introId}")
@Operation(summary = "자기소개서 수정")
public ResponseEntity<Object> update(@PathVariable("introId") Long introId, @RequestBody IntroduceReqDto introduceReqDto){
try {
IntroduceResDto introduceResDto = introduceService.updateIntro(introId, introduceReqDto);
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 수정 완료", introduceResDto));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error "+e.getMessage()+e.getCause()));
}
}

@DeleteMapping("/{introId}")
@Operation(summary = "자기소개서 삭제")
public ResponseEntity<Object> delete(@PathVariable("introId") Long introId){
try {
Long intro_Id = introduceService.deleteIntro(introId);
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "자기소개서 삭제 완료", intro_Id));
} catch (BaseException e) {
return ResponseEntity
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package umc.kkijuk.server.introduce.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -19,10 +21,12 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/history/intro/master")
@Slf4j
public class MasterIntroduceController {
private final MasterIntroduceService masterIntroduceService;

@PostMapping
@Operation(summary = "마스터 자기소개서 생성")
public ResponseEntity<Object> save(@RequestBody MasterIntroduceReqDto masterIntroduceReqDto){
try {
MasterIntroduceResDto masterIntroduceResDto = masterIntroduceService.saveMasterIntro(masterIntroduceReqDto);
Expand All @@ -34,16 +38,18 @@ public ResponseEntity<Object> save(@RequestBody MasterIntroduceReqDto masterIntr
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@GetMapping
@Operation(summary = "마스터 자기소개서 조회")
public ResponseEntity<Object> get(){
try {
List<MasterIntroduce> masterIntroduce = masterIntroduceService.getMasterIntro();
List<MasterIntroduceResDto> masterIntroduce = masterIntroduceService.getMasterIntro();
return ResponseEntity
.status(HttpStatus.OK)
.body(new BaseResponse<>(HttpStatus.OK.value(), "마스터 자기소개서 조회 완료", masterIntroduce));
Expand All @@ -52,13 +58,15 @@ public ResponseEntity<Object> get(){
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
}
}

@PatchMapping
@Operation(summary = "마스터 자기소개서 수정")
public ResponseEntity<Object> update(Long id, @RequestBody MasterIntroduceReqDto masterIntroduceReqDto){
try {
MasterIntroduceResDto masterIntroduceResDto = masterIntroduceService.updateMasterIntro(id, masterIntroduceReqDto);
Expand All @@ -70,6 +78,7 @@ public ResponseEntity<Object> update(Long id, @RequestBody MasterIntroduceReqDto
.status(e.getCode())
.body(new BaseErrorResponse(e.getCode(), e.getMessage()));
} catch (Exception e) {
log.info("Exception occurred: ", e);
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(new BaseErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error"));
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/umc/kkijuk/server/introduce/domain/Introduce.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,62 @@

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import umc.kkijuk.server.recruit.domain.Recruit;
import umc.kkijuk.server.recruit.infrastructure.RecruitEntity;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Entity
@Table(name="introduce")
@Getter
@NoArgsConstructor
public class Introduce {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne
@JoinColumn(name = "recruit_id", nullable = false)
@NotNull
private RecruitEntity recruit;

@NotNull
@OneToMany(mappedBy = "introduce", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Question> questions;

@NotNull
private int state;

@CreationTimestamp
private LocalDateTime created_at;

@UpdateTimestamp
private LocalDateTime updated_at;

@Builder
public Introduce(RecruitEntity recruit, List<Question> questions, int state) {
this.recruit = recruit;
this.questions = questions;
this.state = state;
setQuestions(questions);
}

public void setQuestions(List<Question> questions) {
this.questions = questions;
for (Question question : questions) {
question.setIntroduce(this);
}
}

public void update(int state) {
this.state=state;
}

}
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.Optional;

public interface IntroduceRepository extends JpaRepository<Introduce, Long> {
Optional<Introduce> findByRecruitId(Long recruitId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public class MasterIntroduce {

@Size(max = 24)
private String oneLiner;

private String subTitle;
private String content;
private String introduction;
private String motive;
private String prosAndCons;

@CreationTimestamp
private LocalDateTime created_at;
Expand All @@ -37,21 +37,23 @@ public class MasterIntroduce {
private LocalDateTime updated_at;

@Builder
public MasterIntroduce(String oneLiner, String subTitle, String content) {
public MasterIntroduce(String oneLiner, String introduction, String motive, String prosAndCons) {
this.oneLiner = oneLiner;
this.subTitle = subTitle;
this.content = content;
this.introduction = introduction;
this.motive = motive;
this.prosAndCons = prosAndCons;
}

public String getUpdated_at() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
return updated_at != null ? updated_at.format(formatter) : null;
}

public void update(String oneLiner, String subTitle, String content) {
public void update(String oneLiner, String introduction, String motive, String prosAndCons) {
this.oneLiner = oneLiner;
this.subTitle = subTitle;
this.content = content;
this.introduction = introduction;
this.motive = motive;
this.prosAndCons = prosAndCons;
}

}
47 changes: 47 additions & 0 deletions src/main/java/umc/kkijuk/server/introduce/domain/Question.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package umc.kkijuk.server.introduce.domain;


import jakarta.persistence.*;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Table(name="question")
@Getter
@Setter
@NoArgsConstructor
public class Question {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "introduce_id", nullable = false)
private Introduce introduce;

private String title;

private String content;

private int number;

@Builder
public Question(String title, String content, int number) {
this.title = title;
this.content = content;
this.number = number;
}

public void setIntroduce(Introduce introduce) {
this.introduce = introduce;
}

public void update(String title, String content) {
this.title = title;
this.content = content;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package umc.kkijuk.server.introduce.domain;

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

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

public interface QuestionRepository extends JpaRepository<Question, Long> {

}
Loading