diff --git a/src/main/java/com/groom/orbit/common/exception/ErrorCode.java b/src/main/java/com/groom/orbit/common/exception/ErrorCode.java index b78c6f6..0e93392 100644 --- a/src/main/java/com/groom/orbit/common/exception/ErrorCode.java +++ b/src/main/java/com/groom/orbit/common/exception/ErrorCode.java @@ -17,6 +17,7 @@ public enum ErrorCode { NOT_FOUND_LOGIN_USER(40401, HttpStatus.NOT_FOUND, "로그인한 사용자가 존재하지 않습니다."), NOT_FOUND_AUTHORIZATION_HEADER(40401, HttpStatus.NOT_FOUND, "Authorization 헤더가 존재하지 않습니다."), NOT_FOUND_MEMBER(40402, HttpStatus.NOT_FOUND, "해당 사용자가 존재하지 않습니다."), + NOT_FOUND_RESUME(40403, HttpStatus.BAD_REQUEST, "해당 이력이 존재하지 않습니다."), // Invalid Argument Error MISSING_REQUEST_PARAMETER(40000, HttpStatus.BAD_REQUEST, "필수 요청 파라미터가 누락되었습니다."), diff --git a/src/main/java/com/groom/orbit/resume/app/ResumeCommendService.java b/src/main/java/com/groom/orbit/resume/app/ResumeCommendService.java index b80e66d..995fa3f 100644 --- a/src/main/java/com/groom/orbit/resume/app/ResumeCommendService.java +++ b/src/main/java/com/groom/orbit/resume/app/ResumeCommendService.java @@ -4,9 +4,11 @@ import org.springframework.transaction.annotation.Transactional; import com.groom.orbit.common.dto.CommonSuccessDto; +import com.groom.orbit.common.exception.CommonException; +import com.groom.orbit.common.exception.ErrorCode; import com.groom.orbit.member.app.MemberQueryService; import com.groom.orbit.member.dao.jpa.entity.Member; -import com.groom.orbit.resume.app.dto.CreateResumeRequestDto; +import com.groom.orbit.resume.app.dto.ResumeRequestDto; import com.groom.orbit.resume.dao.ResumeRepository; import com.groom.orbit.resume.dao.entity.Resume; @@ -20,18 +22,23 @@ public class ResumeCommendService { private final ResumeRepository resumeRepository; private final MemberQueryService memberQueryService; - public CommonSuccessDto createResume(Long memberId, CreateResumeRequestDto request) { + public CommonSuccessDto createResume(Long memberId, ResumeRequestDto request) { Member member = memberQueryService.findMember(memberId); + resumeRepository.save(request.toResume(member)); + + return CommonSuccessDto.fromEntity(true); + } + + public CommonSuccessDto updateResume(Long resumeId, ResumeRequestDto requestDto) { + Resume resume = - Resume.builder() - .resumeCategory(request.resumeCategory()) - .content(request.content()) - .startDate(request.startDate()) - .endDate(request.endDate()) - .member(member) - .build(); + resumeRepository + .findById(resumeId) + .orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESUME)); + + resume.updateResume(requestDto); resumeRepository.save(resume); diff --git a/src/main/java/com/groom/orbit/resume/app/dto/CreateResumeRequestDto.java b/src/main/java/com/groom/orbit/resume/app/dto/CreateResumeRequestDto.java deleted file mode 100644 index 4e56885..0000000 --- a/src/main/java/com/groom/orbit/resume/app/dto/CreateResumeRequestDto.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.groom.orbit.resume.app.dto; - -import java.util.Date; - -import com.groom.orbit.resume.dao.entity.ResumeCategory; - -public record CreateResumeRequestDto( - ResumeCategory resumeCategory, String content, Date startDate, Date endDate) {} diff --git a/src/main/java/com/groom/orbit/resume/app/dto/ResumeRequestDto.java b/src/main/java/com/groom/orbit/resume/app/dto/ResumeRequestDto.java new file mode 100644 index 0000000..16fc221 --- /dev/null +++ b/src/main/java/com/groom/orbit/resume/app/dto/ResumeRequestDto.java @@ -0,0 +1,22 @@ +package com.groom.orbit.resume.app.dto; + +import java.util.Date; + +import com.groom.orbit.member.dao.jpa.entity.Member; +import com.groom.orbit.resume.dao.entity.Resume; +import com.groom.orbit.resume.dao.entity.ResumeCategory; + +public record ResumeRequestDto( + ResumeCategory resumeCategory, String title, String content, Date startDate, Date endDate) { + + public Resume toResume(Member member) { + return Resume.builder() + .resumeCategory(this.resumeCategory) + .title(this.title) + .content(this.content) + .startDate(this.startDate) + .endDate(this.endDate) + .member(member) + .build(); + } +} diff --git a/src/main/java/com/groom/orbit/resume/controller/ResumeCommandController.java b/src/main/java/com/groom/orbit/resume/controller/ResumeCommandController.java index a805e69..0216720 100644 --- a/src/main/java/com/groom/orbit/resume/controller/ResumeCommandController.java +++ b/src/main/java/com/groom/orbit/resume/controller/ResumeCommandController.java @@ -1,15 +1,12 @@ package com.groom.orbit.resume.controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.groom.orbit.common.annotation.AuthMember; import com.groom.orbit.common.dto.CommonSuccessDto; import com.groom.orbit.common.dto.ResponseDto; import com.groom.orbit.resume.app.ResumeCommendService; -import com.groom.orbit.resume.app.dto.CreateResumeRequestDto; +import com.groom.orbit.resume.app.dto.ResumeRequestDto; import lombok.RequiredArgsConstructor; @@ -22,7 +19,15 @@ public class ResumeCommandController { @PostMapping() public ResponseDto createResume( - @AuthMember Long memberId, @RequestBody CreateResumeRequestDto requestDto) { + @AuthMember Long memberId, @RequestBody ResumeRequestDto requestDto) { return ResponseDto.ok(resumeCommandService.createResume(memberId, requestDto)); } + + @PatchMapping("/{resumeId}") + public ResponseDto updateResume( + @AuthMember Long memberId, + @PathVariable Long resumeId, + @RequestBody ResumeRequestDto requestDto) { + return ResponseDto.ok(resumeCommandService.updateResume(resumeId, requestDto)); + } } diff --git a/src/main/java/com/groom/orbit/resume/dao/ResumeRepository.java b/src/main/java/com/groom/orbit/resume/dao/ResumeRepository.java index 136674a..3108176 100644 --- a/src/main/java/com/groom/orbit/resume/dao/ResumeRepository.java +++ b/src/main/java/com/groom/orbit/resume/dao/ResumeRepository.java @@ -1,7 +1,12 @@ package com.groom.orbit.resume.dao; +import java.util.Optional; + import org.springframework.data.jpa.repository.JpaRepository; import com.groom.orbit.resume.dao.entity.Resume; -public interface ResumeRepository extends JpaRepository {} +public interface ResumeRepository extends JpaRepository { + + Optional findById(Long resumeId); +} diff --git a/src/main/java/com/groom/orbit/resume/dao/entity/Resume.java b/src/main/java/com/groom/orbit/resume/dao/entity/Resume.java index f8acaef..a17b029 100644 --- a/src/main/java/com/groom/orbit/resume/dao/entity/Resume.java +++ b/src/main/java/com/groom/orbit/resume/dao/entity/Resume.java @@ -5,6 +5,7 @@ import jakarta.persistence.*; import com.groom.orbit.member.dao.jpa.entity.Member; +import com.groom.orbit.resume.app.dto.ResumeRequestDto; import lombok.AllArgsConstructor; import lombok.Builder; @@ -28,6 +29,9 @@ public class Resume { @Enumerated(EnumType.STRING) private ResumeCategory resumeCategory; + @Column(name = "title") + private String title; + @Column(name = "content") private String content; @@ -40,4 +44,12 @@ public class Resume { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "member_id") private Member member; + + public void updateResume(ResumeRequestDto requestDto) { + this.resumeCategory = requestDto.resumeCategory(); + this.title = requestDto.title(); + this.content = requestDto.content(); + this.startDate = requestDto.startDate(); + this.endDate = requestDto.endDate(); + } }