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 611d85d..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 @@ -6,7 +6,7 @@ import com.example.letscareer.common.exception.enums.SuccessCode; import com.example.letscareer.common.exception.model.BadRequestException; import com.example.letscareer.common.exception.model.NotFoundException; -import com.example.letscareer.self_intro.dto.SaveSelfIntroRequest; +import com.example.letscareer.self_intro.dto.request.SaveSelfIntroRequest; import com.example.letscareer.self_intro.service.SelfIntroService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -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/domain/SelfIntro.java b/src/main/java/com/example/letscareer/self_intro/domain/SelfIntro.java index 251d20e..2a8322c 100644 --- a/src/main/java/com/example/letscareer/self_intro/domain/SelfIntro.java +++ b/src/main/java/com/example/letscareer/self_intro/domain/SelfIntro.java @@ -17,10 +17,14 @@ public class SelfIntro { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long selfIntroId; + private String title; + + private int sequence; + @Lob private String content; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "stageId") @NotNull private Stage stage; diff --git a/src/main/java/com/example/letscareer/self_intro/dto/SaveSelfIntroRequest.java b/src/main/java/com/example/letscareer/self_intro/dto/SaveSelfIntroRequest.java deleted file mode 100644 index 0fadb70..0000000 --- a/src/main/java/com/example/letscareer/self_intro/dto/SaveSelfIntroRequest.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.letscareer.self_intro.dto; - -public record SaveSelfIntroRequest( - String content -) { -} diff --git a/src/main/java/com/example/letscareer/self_intro/dto/SelfIntroDTO.java b/src/main/java/com/example/letscareer/self_intro/dto/SelfIntroDTO.java new file mode 100644 index 0000000..3b4dfef --- /dev/null +++ b/src/main/java/com/example/letscareer/self_intro/dto/SelfIntroDTO.java @@ -0,0 +1,7 @@ +package com.example.letscareer.self_intro.dto; + +public record SelfIntroDTO( + String title, + int sequence, + String content) { +} diff --git a/src/main/java/com/example/letscareer/self_intro/dto/request/SaveSelfIntroRequest.java b/src/main/java/com/example/letscareer/self_intro/dto/request/SaveSelfIntroRequest.java new file mode 100644 index 0000000..1272738 --- /dev/null +++ b/src/main/java/com/example/letscareer/self_intro/dto/request/SaveSelfIntroRequest.java @@ -0,0 +1,10 @@ +package com.example.letscareer.self_intro.dto.request; + +import com.example.letscareer.self_intro.dto.SelfIntroDTO; + +import java.util.List; + +public record SaveSelfIntroRequest( + List selfIntros +) { +} 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 29f15c2..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 @@ -4,7 +4,8 @@ import com.example.letscareer.schedule.domain.Schedule; import com.example.letscareer.schedule.repository.ScheduleRepository; import com.example.letscareer.self_intro.domain.SelfIntro; -import com.example.letscareer.self_intro.dto.SaveSelfIntroRequest; +import com.example.letscareer.self_intro.dto.SelfIntroDTO; +import com.example.letscareer.self_intro.dto.request.SaveSelfIntroRequest; import com.example.letscareer.self_intro.repository.SelfIntroRepository; import com.example.letscareer.stage.domain.Stage; import com.example.letscareer.stage.repository.StageRepository; @@ -14,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 @@ -36,11 +36,18 @@ public void saveSelfIntro(Long userId, Long scheduleId, Long stageId, SaveSelfIn User user = userRepository.findById(userId) .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); - SelfIntro selfIntro = SelfIntro.builder() - .stage(stage) - .content(request.content()) - .build(); + // 현재 stage에 있는 모든 SelfIntro를 삭제한다. + selfIntroRepository.deleteByStage(stage); - selfIntroRepository.save(selfIntro); + // 새로 들어온 자기소개서 항목을 저장한다. + for (SelfIntroDTO selfIntroDTO : request.selfIntros()) { + SelfIntro selfIntro = SelfIntro.builder() + .title(selfIntroDTO.title()) + .sequence(selfIntroDTO.sequence()) + .content(selfIntroDTO.content()) + .stage(stage) + .build(); + selfIntroRepository.save(selfIntro); + } } }