-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
338 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 37 additions & 12 deletions
49
src/main/java/com/example/umc3_teamproject/controller/MemoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,37 @@ | ||
//package com.example.umc3_teamproject.controller; | ||
// | ||
//import org.springframework.web.bind.annotation.GetMapping; | ||
// | ||
//public class MemoController { | ||
//// | ||
//// private final MemoController memoController; | ||
//// | ||
//// @GetMapping("/") | ||
// | ||
// | ||
//} | ||
package com.example.umc3_teamproject.controller; | ||
|
||
import com.example.umc3_teamproject.config.resTemplate.ResponseTemplate; | ||
import com.example.umc3_teamproject.domain.dto.request.MemoRequestDto; | ||
import com.example.umc3_teamproject.domain.dto.response.MemoResponseDto; | ||
import com.example.umc3_teamproject.service.MemoService; | ||
import io.swagger.annotations.Api; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Api(tags = {"Result Memo Api"}) | ||
@RequestMapping("/record/{script-interview-id}/memo") | ||
public class MemoController { | ||
|
||
private final MemoService memoService; | ||
|
||
@PostMapping("/new") | ||
public ResponseTemplate<MemoResponseDto.createBody> createMemo(@PathVariable("script-interview-id") Long script_interview_id, | ||
@RequestBody @Validated MemoRequestDto.createRequest request){ | ||
return memoService.createMemo(script_interview_id,request); | ||
} | ||
|
||
@PutMapping("/edit/{memo-id}") | ||
public ResponseTemplate<MemoResponseDto.updateBody> updateMemo(@PathVariable("memo-id") Long memo_id, | ||
@RequestBody @Validated MemoRequestDto.updateRequest request){ | ||
return memoService.updateMemo(memo_id,request); | ||
} | ||
|
||
@GetMapping("/{memo-id}") | ||
public ResponseTemplate<MemoResponseDto.updateBody> getMemo(@PathVariable("memo-id") Long memo_id){ | ||
return memoService.getMemo(memo_id); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/umc3_teamproject/domain/dto/request/MemoRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.umc3_teamproject.domain.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
public class MemoRequestDto { | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class createRequest { | ||
@NotNull(message = "script 또는 interview 둘 중에 하나 기입하시면 됩니다.(해당 메모가 script인지 interview인지 구분하기 위함.") | ||
private String type; | ||
|
||
@NotNull(message = "메모 내용을 넣어주세요. 비어있으면 안됩니다.") | ||
private String memo; | ||
} | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class updateRequest { | ||
@NotNull(message = "메모 내용을 넣어주세요. 비어있으면 안됩니다.") | ||
private String memo; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/example/umc3_teamproject/domain/dto/response/MemoResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.example.umc3_teamproject.domain.dto.response; | ||
|
||
import com.example.umc3_teamproject.domain.item.Interview; | ||
import com.example.umc3_teamproject.domain.item.Memo; | ||
import com.example.umc3_teamproject.domain.item.Script; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
public class MemoResponseDto { | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class createBody { | ||
private String script_interview_type; | ||
private Long script_interview_id; | ||
private Long memo_id; | ||
private String memo; | ||
} | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class updateBody { | ||
private Long memo_id; | ||
private String memo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 48 additions & 18 deletions
66
src/main/java/com/example/umc3_teamproject/domain/item/Memo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,48 @@ | ||
//package com.example.umc3_teamproject.domain.item; | ||
// | ||
//import lombok.AllArgsConstructor; | ||
// | ||
//import javax.persistence.*; | ||
// | ||
//@Entity @Table(name="memo") @AllArgsConstructor | ||
//public class Memo { | ||
// | ||
// @ManyToOne(fetch= FetchType.LAZY) | ||
// @JoinColumn(name="script_id") | ||
// private Script script; | ||
// | ||
// @ManyToOne(fetch = FetchType.LAZY) | ||
// @JoinColumn(name = "interview_id") | ||
// private Interview interview; | ||
// | ||
//} | ||
package com.example.umc3_teamproject.domain.item; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.Where; | ||
|
||
import javax.persistence.*; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PUBLIC) | ||
@Table(name = "memo") | ||
public class Memo { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "record_memo_id") | ||
private Long id; | ||
|
||
@OneToOne(fetch= FetchType.LAZY) | ||
@JoinColumn(name="script_id") | ||
private Script script; | ||
|
||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "interview_id") | ||
private Interview interview; | ||
|
||
private String memo; | ||
|
||
// 비즈니스 로직 | ||
public void createMemo(Script script, Interview interview, String memo){ | ||
if(script != null){ | ||
this.script = script; | ||
} | ||
|
||
if(interview != null){ | ||
this.interview = interview; | ||
} | ||
|
||
this.memo = memo; | ||
} | ||
|
||
public void changeMemo(String memo){ | ||
this.memo = memo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 24 additions & 4 deletions
28
src/main/java/com/example/umc3_teamproject/repository/MemoRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,24 @@ | ||
//package com.example.umc3_teamproject.repository; | ||
// | ||
//public class MemoRepository { | ||
//} | ||
package com.example.umc3_teamproject.repository; | ||
|
||
import com.example.umc3_teamproject.domain.item.Interview; | ||
import com.example.umc3_teamproject.domain.item.Memo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import javax.transaction.Transactional; | ||
import java.util.List; | ||
|
||
public interface MemoRepository extends JpaRepository<Memo, Long> { | ||
|
||
@Transactional | ||
@Modifying | ||
@Query("delete from Memo m where m.script.scriptId in :id") | ||
void deleteByScriptIdInQuery(@Param("id") Long id); | ||
|
||
@Transactional | ||
@Modifying | ||
@Query("delete from Memo m where m.interview.interviewId in :id") | ||
void deleteByInterviewIdInQuery(@Param("id") Long id); | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/example/umc3_teamproject/service/MemoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.example.umc3_teamproject.service; | ||
|
||
import com.example.umc3_teamproject.config.resTemplate.ResponseTemplate; | ||
import com.example.umc3_teamproject.domain.dto.request.MemoRequestDto; | ||
import com.example.umc3_teamproject.domain.dto.response.MemoResponseDto; | ||
import com.example.umc3_teamproject.domain.item.Interview; | ||
import com.example.umc3_teamproject.domain.item.InterviewParagraph; | ||
import com.example.umc3_teamproject.domain.item.Memo; | ||
import com.example.umc3_teamproject.domain.item.Script; | ||
import com.example.umc3_teamproject.exception.CustomException; | ||
import com.example.umc3_teamproject.exception.ErrorCode; | ||
import com.example.umc3_teamproject.repository.InterviewRepository; | ||
import com.example.umc3_teamproject.repository.MemoRepository; | ||
import com.example.umc3_teamproject.repository.ScriptRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.hibernate.sql.Template; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class MemoService { | ||
private final MemoRepository memoRepository; | ||
private final ScriptRepository scriptRepository; | ||
private final InterviewRepository interviewRepository; | ||
|
||
@Transactional | ||
public ResponseTemplate<MemoResponseDto.createBody> createMemo(Long script_interview_id,MemoRequestDto.createRequest request){ | ||
Memo memo = new Memo(); | ||
if(request.getType().equals("script")){ | ||
Script findScript = scriptRepository.findById(script_interview_id).orElseThrow( | ||
() -> new CustomException(ErrorCode.SCRIPT_NOT_FOUND) | ||
); | ||
memo.createMemo(findScript,null, request.getMemo()); | ||
}else if(request.getType().equals("interview")){ | ||
Interview findInterview = interviewRepository.findById(script_interview_id).orElseThrow( | ||
() -> new CustomException(ErrorCode.INTERVIEW_NOT_FOUND) | ||
); | ||
memo.createMemo(null,findInterview, request.getMemo()); | ||
} | ||
memoRepository.save(memo); | ||
return new ResponseTemplate<>(new MemoResponseDto.createBody( | ||
request.getType(),script_interview_id,memo.getId(),memo.getMemo())); | ||
} | ||
|
||
@Transactional | ||
public ResponseTemplate<MemoResponseDto.updateBody> updateMemo(Long memo_id,MemoRequestDto.updateRequest request){ | ||
Memo findMemo = memoRepository.findById(memo_id).orElseThrow( | ||
() -> new CustomException(ErrorCode.MEMO_NOT_FOUND) | ||
); | ||
|
||
findMemo.changeMemo(request.getMemo()); | ||
|
||
return new ResponseTemplate<>(new MemoResponseDto.updateBody( | ||
findMemo.getId(),findMemo.getMemo())); | ||
} | ||
|
||
|
||
@Transactional | ||
public void deleteMemo(String type,Long script_interview_id){ | ||
if(type.equals("script")){ | ||
memoRepository.deleteByScriptIdInQuery(script_interview_id); | ||
}else if(type.equals("interview")){ | ||
memoRepository.deleteByInterviewIdInQuery(script_interview_id); | ||
} | ||
} | ||
|
||
public ResponseTemplate<MemoResponseDto.updateBody> getMemo(Long memo_id) { | ||
Memo findMemo = memoRepository.findById(memo_id).orElseThrow( | ||
() -> new CustomException(ErrorCode.MEMO_NOT_FOUND) | ||
); | ||
|
||
return new ResponseTemplate<>(new MemoResponseDto.updateBody( | ||
findMemo.getId(),findMemo.getMemo())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.