Skip to content

Commit

Permalink
[feat] #81 merge
Browse files Browse the repository at this point in the history
  • Loading branch information
myhyun0002 committed Feb 5, 2023
2 parents f989559 + 1f1f27c commit e2d1e79
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 154 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ dependencies {

// m1 mac os에서 dsn server 문제 해결
implementation 'io.netty:netty-resolver-dns-native-macos:4.1.68.Final:osx-aarch_64'



testImplementation('org.junit.jupiter:junit-jupiter:5.9.1')

}

Expand Down
Binary file removed build/tmp/compileJava/previous-compilation-data.bin
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public ResponseTemplate<List<ForumResponseDto.ForumDataToGetResult>> getForumByU
return forumService.getForumByUserId(user_id);
}

@ApiOperation(value = "현재 사용중인 사용자가 만든 모든 forum 조회", notes = "user-id의 사용자가 만든 모든 forum 조회")
@ResponseBody
@GetMapping("/user/me")
public ResponseTemplate<List<ForumResponseDto.ForumDataToGetResult>> getMyForums() throws ResponseException {
Long user_id = jwtService.getmemberId();
return forumService.getForumByUserId(user_id);
}

// forum_id로 조회
@ApiOperation(value = "해당 forum-id인 forum 하나 조회",notes = "해당 forum-id인 forum 하나 조회")
@ResponseBody
Expand Down
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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ public ResponseTemplate<List<NestedCommentResponseDto.Body>> getAllNestedComment
return nestedCommentService.getAllByCommentId(comment_id);
}

@ApiOperation(value = "해당 comment-id인 comment 좋아요 수 하나 증가")
@ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 하나 증가")
@PutMapping("/{nested-comment-id}/like/plus")
public ResponseTemplate<NestedCommentResponseDto.LikeResponseDto> likePlus(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException {
return nestedCommentService.likePlus(nested_comment_id);
}

@ApiOperation(value = "해당 comment-id인 comment 좋아요 수 하나 감소")
@ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 하나 감소")
@PutMapping("/{nested-comment-id}/like/minus")
public ResponseTemplate<NestedCommentResponseDto.LikeResponseDto> likeMinus(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException {
return nestedCommentService.likeMinus(nested_comment_id);
}

@ApiOperation(value = "해당 comment-id인 comment 좋아요 수 조회")
@ApiOperation(value = "해당 nested-comment-id인 대댓글 좋아요 수 조회")
@GetMapping("/{nested-comment-id}/like")
public ResponseTemplate<NestedCommentResponseDto.LikeResponseDto> getNestedCommentLike(@PathVariable("nested-comment-id") Long nested_comment_id) throws ResponseException {
return nestedCommentService.getLike(nested_comment_id);
Expand Down
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;
}

}
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ public class Interview extends BaseEntity {
private LocalDate interviewDate;


//paragraph를 list로 추가
@OneToMany(mappedBy = "scriptId")
@JsonBackReference
private List<Paragraph> paragraphList = new ArrayList<>();
// interiview paragraph는 InterviewParagraph로 새로 Entity 만들었어요!
// //paragraph를 list로 추가
// @OneToMany(mappedBy = "scriptId")
// @JsonBackReference
// private List<Paragraph> paragraphList = new ArrayList<>();

@OneToMany(mappedBy = "interview",orphanRemoval = true)
private List<InterviewParagraph> interviewParagraphs = new ArrayList<>();
Expand Down
66 changes: 48 additions & 18 deletions src/main/java/com/example/umc3_teamproject/domain/item/Memo.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class Script extends BaseEntity {
@JsonBackReference
private List<RecordScript> record_script;

@OneToOne(mappedBy = "script",fetch = LAZY,orphanRemoval = true)
private Memo memo;

@OneToMany(mappedBy = "scriptId", fetch=FetchType.LAZY, cascade = CascadeType.ALL)
@JsonBackReference
// private List<Paragraph> paragraphList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum ErrorCode {
FIREBASE_INITIAL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "firebase 초기화에 실패하였습니다."),

REPORT_TYPE_ERROR(HttpStatus.NO_CONTENT, "Report 타입은 Forum, Comment, NestedComment 세개 입니다."),

MEMO_NOT_FOUND(HttpStatus.NOT_FOUND,"해당 memo는 존재하지 않습니다.")
;


Expand Down
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);
}
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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ScriptService {
@Autowired
private final ScriptRepository scriptRepository;
private final ScriptResponseDto scriptResponse;

private final MemoService memoService;
private final EntityManager em;


Expand Down Expand Up @@ -98,7 +100,8 @@ public String remove(Long id){
Script toRemoveScript=em.find(Script.class, id);
toRemoveScript.setDeleted(true);
em.merge(toRemoveScript);

// script가 삭제될 때 memo도 삭제되게 했다.
memoService.deleteMemo("script",id);
return "script id ["+id+"] deleted success";
}

Expand Down
Loading

0 comments on commit e2d1e79

Please sign in to comment.