From f3ab993fb92b20d715b5f32a05e03b4f6f7a73d5 Mon Sep 17 00:00:00 2001 From: oosedus Date: Mon, 2 Sep 2024 21:48:34 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EB=A9=94=EC=86=8C=EB=93=9C=20PUT=20?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../self_intro/controller/SelfIntroController.java | 2 +- .../self_intro/repository/SelfIntroRepository.java | 2 ++ .../letscareer/self_intro/service/SelfIntroService.java | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/letscareer/self_intro/controller/SelfIntroController.java b/src/main/java/com/example/letscareer/self_intro/controller/SelfIntroController.java index ab7ebae..07cf34c 100644 --- a/src/main/java/com/example/letscareer/self_intro/controller/SelfIntroController.java +++ b/src/main/java/com/example/letscareer/self_intro/controller/SelfIntroController.java @@ -17,7 +17,7 @@ public class SelfIntroController { private final SelfIntroService selfIntroService; - @PostMapping("/schedules/{scheduleId}/stages/{stageId}/self-intro") + @PutMapping("/schedules/{scheduleId}/stages/{stageId}/self-intro") public ApiResponse saveSelfIntro( @RequestHeader("userId") Long userId, @PathVariable Long scheduleId, diff --git a/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java b/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java index 3563b21..dbd33af 100644 --- a/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java +++ b/src/main/java/com/example/letscareer/self_intro/repository/SelfIntroRepository.java @@ -1,9 +1,11 @@ package com.example.letscareer.self_intro.repository; import com.example.letscareer.self_intro.domain.SelfIntro; +import com.example.letscareer.stage.domain.Stage; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface SelfIntroRepository extends JpaRepository { + void deleteByStage(Stage stage); } diff --git a/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java b/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java index d77b7ba..033c6a0 100644 --- a/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java +++ b/src/main/java/com/example/letscareer/self_intro/service/SelfIntroService.java @@ -15,7 +15,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - import static com.example.letscareer.common.exception.enums.ErrorCode.*; @Service @@ -37,7 +36,11 @@ public void saveSelfIntro(Long userId, Long scheduleId, Long stageId, SaveSelfIn User user = userRepository.findById(userId) .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - for(SelfIntroDTO selfIntroDTO : request.selfIntros()) { + // 현재 stage에 있는 모든 SelfIntro를 삭제한다. + selfIntroRepository.deleteByStage(stage); + + // 새로 들어온 자기소개서 항목을 저장한다. + for (SelfIntroDTO selfIntroDTO : request.selfIntros()) { SelfIntro selfIntro = SelfIntro.builder() .title(selfIntroDTO.title()) .sequence(selfIntroDTO.sequence())