Skip to content

Commit

Permalink
Merge pull request #48 from LetsCareer-A/feat/#47
Browse files Browse the repository at this point in the history
#47 [feat] 자기소개서 저장 로직 변경
  • Loading branch information
pkl0912 authored Sep 3, 2024
2 parents 7b684fd + f3ab993 commit 553017c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.letscareer.self_intro.dto;

public record SelfIntroDTO(
String title,
int sequence,
String content) {
}
Original file line number Diff line number Diff line change
@@ -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<SelfIntroDTO> selfIntros
) {
}
Original file line number Diff line number Diff line change
@@ -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<SelfIntro, Long> {
void deleteByStage(Stage stage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
}
}

0 comments on commit 553017c

Please sign in to comment.