From 015f646f922bdb2ea3cd3c1aca00e467e315daeb Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Sun, 22 Oct 2023 18:46:03 +0900 Subject: [PATCH 01/84] =?UTF-8?q?fix=20:=20MentorPostStateConverter=20refa?= =?UTF-8?q?ctor=20State=20attributer=20null=20=EC=82=AD=EC=A0=9C=20?= =?UTF-8?q?=EB=B0=8F=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/config/utils/StateConverter.java | 27 ---------------- .../example/demo/config/utils/StateEnum.java | 32 ------------------- .../example/demo/mentoring/MentorPost.java | 11 +++---- .../demo/mentoring/MentorPostRequest.java | 4 +-- .../demo/mentoring/MentorPostResponse.java | 13 ++++---- .../demo/mentoring/MentorPostService.java | 6 +--- .../mentoring/MentorPostStateConverter.java | 22 +++++++++++++ .../demo/mentoring/MentorPostStateEnum.java | 30 +++++++++++++++++ .../demo/mentoringtest/MentoringTest.java | 8 ++--- 9 files changed, 66 insertions(+), 87 deletions(-) delete mode 100644 src/main/java/com/example/demo/config/utils/StateConverter.java delete mode 100644 src/main/java/com/example/demo/config/utils/StateEnum.java create mode 100644 src/main/java/com/example/demo/mentoring/MentorPostStateConverter.java create mode 100644 src/main/java/com/example/demo/mentoring/MentorPostStateEnum.java diff --git a/src/main/java/com/example/demo/config/utils/StateConverter.java b/src/main/java/com/example/demo/config/utils/StateConverter.java deleted file mode 100644 index e109d5bf..00000000 --- a/src/main/java/com/example/demo/config/utils/StateConverter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.example.demo.config.utils; - -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; - -import javax.persistence.AttributeConverter; -import java.util.Optional; - -@RequiredArgsConstructor -@Component -public class StateConverter implements AttributeConverter { - - @Override - public String convertToDatabaseColumn(StateEnum attribute) { - return Optional.ofNullable(attribute).orElse(StateEnum.NULL).getValue(); - } - - @Override - public StateEnum convertToEntityAttribute(String dbData) { - if (dbData == null || dbData.length() == 0) { - return StateEnum.NULL; - } - return StateEnum.findOf(dbData); - } -} diff --git a/src/main/java/com/example/demo/config/utils/StateEnum.java b/src/main/java/com/example/demo/config/utils/StateEnum.java deleted file mode 100644 index af51d0c3..00000000 --- a/src/main/java/com/example/demo/config/utils/StateEnum.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.example.demo.config.utils; - -import lombok.Getter; - -import java.util.Collections; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -@Getter -public enum StateEnum { - NULL("NULL", ""), - ACTIVE("ACTIVE", "ACTIVE"), - DONE("DONE", "DONE"), - DELETED("DELETED", "DELETED"); - - private final String desc; - private final String value; - - StateEnum(String desc, String value) { - this.desc = desc; - this.value = value; - } - - private static final Map descriptions = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(StateEnum::getValue, Function.identity()))); - - public static StateEnum findOf(String findValue) { - return Optional.ofNullable(descriptions.get(findValue)).orElse(NULL); - } -} diff --git a/src/main/java/com/example/demo/mentoring/MentorPost.java b/src/main/java/com/example/demo/mentoring/MentorPost.java index 0a53a704..1d543f24 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPost.java +++ b/src/main/java/com/example/demo/mentoring/MentorPost.java @@ -1,14 +1,11 @@ package com.example.demo.mentoring; import com.example.demo.config.utils.BaseTime; -import com.example.demo.config.utils.StateConverter; -import com.example.demo.config.utils.StateEnum; import com.example.demo.user.User; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; @@ -34,9 +31,9 @@ public class MentorPost extends BaseTime { @Column(length = 300) private String content; - @Convert(converter = StateConverter.class) + @Convert(converter = MentorPostStateConverter.class) @Column(name = "state", nullable = false) - private StateEnum state = StateEnum.ACTIVE; + private MentorPostStateEnum state = MentorPostStateEnum.ACTIVE; @Builder public MentorPost(User writer, String title, String content){ @@ -51,8 +48,8 @@ public void update(String title, String content) this.content = content; } - public void changeStatus(StateEnum stateEnum) + public void changeStatus(MentorPostStateEnum mentorPostStateEnum) { - this.state = stateEnum; + this.state = mentorPostStateEnum; } } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRequest.java b/src/main/java/com/example/demo/mentoring/MentorPostRequest.java index a32c24f9..a2fd23c9 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRequest.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRequest.java @@ -1,7 +1,5 @@ package com.example.demo.mentoring; -import com.example.demo.config.utils.StateEnum; -import com.example.demo.user.User; import lombok.Getter; import lombok.Setter; import javax.validation.constraints.NotNull; @@ -20,6 +18,6 @@ public static class CreateDTO { @Getter @Setter public static class StateDTO { - private StateEnum stateEnum; + private MentorPostStateEnum mentorPostStateEnum; } } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostResponse.java b/src/main/java/com/example/demo/mentoring/MentorPostResponse.java index 84a9d647..6b72279d 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostResponse.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostResponse.java @@ -1,7 +1,6 @@ package com.example.demo.mentoring; -import com.example.demo.config.utils.StateEnum; import com.example.demo.mentoring.contact.NotConnectedRegisterUser; import com.example.demo.user.Role; import com.example.demo.user.User; @@ -27,14 +26,14 @@ public static class MentorPostAllDTO { private int postId; private String title; private String content; - private StateEnum stateEnum; + private MentorPostStateEnum mentorPostStateEnum; private WriterDTO writerDTO; public MentorPostAllDTO(MentorPost mentorPost, List userInterests) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.content = mentorPost.getContent(); - this.stateEnum = mentorPost.getState(); + this.mentorPostStateEnum = mentorPost.getState(); WriterDTO writerDTO = new MentorPostAllDTO.WriterDTO(mentorPost.getWriter(), userInterests); this.writerDTO = writerDTO; } @@ -79,14 +78,14 @@ public static class MentorPostDTO { private String title; private String content; private WriterDTO writerDTO; - private StateEnum stateEnum; + private MentorPostStateEnum mentorPostStateEnum; private List menteeDTOList; public MentorPostDTO(MentorPost mentorPost, List mentorFavorites, List mentees, List menteeInterest) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.content = mentorPost.getContent(); - this.stateEnum = mentorPost.getState(); + this.mentorPostStateEnum = mentorPost.getState(); MentorPostDTO.WriterDTO writerDTO = new MentorPostDTO.WriterDTO(mentorPost.getWriter(), mentorFavorites); this.writerDTO = writerDTO; List menteeDTOList = mentees.stream() @@ -153,7 +152,7 @@ public static class MentorPostAllWithTimeStampDTO { private int postId; private String title; private String content; - private StateEnum stateEnum; + private MentorPostStateEnum mentorPostStateEnum; private WriterDTO writerDTO; private LocalDateTime createdAt; private LocalDateTime deletedAt; @@ -163,7 +162,7 @@ public MentorPostAllWithTimeStampDTO(MentorPost mentorPost, List u this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.content = mentorPost.getContent(); - this.stateEnum = mentorPost.getState(); + this.mentorPostStateEnum = mentorPost.getState(); WriterDTO writerDTO = new MentorPostAllWithTimeStampDTO.WriterDTO(mentorPost.getWriter(), userInterests); this.writerDTO = writerDTO; this.createdAt = mentorPost.getCreatedAt(); diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index eabed99c..8d91b7a2 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -1,7 +1,6 @@ package com.example.demo.mentoring; import com.example.demo.config.errors.exception.Exception500; -import com.example.demo.config.errors.exception.Exception400; import com.example.demo.config.errors.exception.Exception404; import com.example.demo.mentoring.contact.ContactJPARepository; import com.example.demo.mentoring.contact.NotConnectedRegisterUser; @@ -14,11 +13,8 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.example.demo.config.errors.exception.Exception400; -import com.example.demo.config.errors.exception.Exception404; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; @Transactional @@ -127,7 +123,7 @@ public void changeMentorPostStatus(MentorPostRequest.StateDTO stateDTO, int id) { MentorPost mentorPost = mentorPostJPARepository.findById(id) .orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다."));; - mentorPost.changeStatus(stateDTO.getStateEnum()); + mentorPost.changeStatus(stateDTO.getMentorPostStateEnum()); } } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostStateConverter.java b/src/main/java/com/example/demo/mentoring/MentorPostStateConverter.java new file mode 100644 index 00000000..39c83ff8 --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/MentorPostStateConverter.java @@ -0,0 +1,22 @@ +package com.example.demo.mentoring; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.AttributeConverter; +import java.util.Optional; + +@RequiredArgsConstructor +@Component +public class MentorPostStateConverter implements AttributeConverter { + + @Override + public String convertToDatabaseColumn(MentorPostStateEnum attribute) { + return attribute.getValue(); + } + + @Override + public MentorPostStateEnum convertToEntityAttribute(String dbData) { + return MentorPostStateEnum.findOf(dbData); + } +} diff --git a/src/main/java/com/example/demo/mentoring/MentorPostStateEnum.java b/src/main/java/com/example/demo/mentoring/MentorPostStateEnum.java new file mode 100644 index 00000000..3795e105 --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/MentorPostStateEnum.java @@ -0,0 +1,30 @@ +package com.example.demo.mentoring; + +import lombok.Getter; + +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +public enum MentorPostStateEnum { + ACTIVE("ACTIVE", "ACTIVE"), + DONE("DONE", "DONE"); + + private final String desc; + private final String value; + + MentorPostStateEnum(String desc, String value) { + this.desc = desc; + this.value = value; + } + + private static final Map descriptions = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(MentorPostStateEnum::getValue, Function.identity()))); + + public static MentorPostStateEnum findOf(String findValue) { + return descriptions.get(findValue); + } +} diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java index 5b4cc8b8..2f5fd936 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java @@ -2,9 +2,8 @@ import com.example.demo.RestDoc; -import com.example.demo.config.errors.exception.Exception400; import com.example.demo.config.errors.exception.Exception404; -import com.example.demo.config.utils.StateEnum; +import com.example.demo.mentoring.MentorPostStateEnum; import com.example.demo.interest.Interest; import com.example.demo.interest.InterestJPARepository; import com.example.demo.mentoring.*; @@ -23,11 +22,8 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.test.context.support.WithUserDetails; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; import org.springframework.test.web.servlet.ResultActions; @@ -320,7 +316,7 @@ public void DeleteMentorPost() throws Exception{ public void PatchDoneMentorPost() throws Exception{ int id = 1; MentorPostRequest.StateDTO stateDTO = new MentorPostRequest.StateDTO(); - stateDTO.setStateEnum(StateEnum.DONE); + stateDTO.setMentorPostStateEnum(MentorPostStateEnum.DONE); mentorPostService.changeMentorPostStatus(stateDTO, id); } From d2154493398b6c3ad72afb9290f8ca71af1d727f Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Sun, 22 Oct 2023 19:01:46 +0900 Subject: [PATCH 02/84] =?UTF-8?q?fix=20:=20mentorPostService=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=EC=B2=98=EB=A6=AC=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/mentoring/MentorPostService.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index 8d91b7a2..a1207dfb 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -1,9 +1,11 @@ package com.example.demo.mentoring; +import com.example.demo.config.errors.exception.Exception401; import com.example.demo.config.errors.exception.Exception500; import com.example.demo.config.errors.exception.Exception404; import com.example.demo.mentoring.contact.ContactJPARepository; import com.example.demo.mentoring.contact.NotConnectedRegisterUser; +import com.example.demo.user.Role; import com.example.demo.user.User; import com.example.demo.user.userInterest.UserInterest; import com.example.demo.user.userInterest.UserInterestJPARepository; @@ -28,6 +30,10 @@ public class MentorPostService { //mentorPost생성 @Transactional public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) { + if ( writer.getRole() == Role.MENTEE ) { + throw new Exception401("해당 사용자는 멘티입니다."); + } + MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent()); try { mentorPostJPARepository.save(mentorPost); @@ -52,10 +58,6 @@ public List findAllMentorPost(int page) { List mentorPostDTOList = pageContent.getContent().stream().map( mentorPost -> { List writerInterests = userInterestJPARepository.findAllById(mentorPost.getWriter().getId()); - if(writerInterests.isEmpty()){ - throw new Exception404("해당 카테고리는 존재하지 않습니다"); - } - return new MentorPostResponse.MentorPostAllDTO(mentorPost,writerInterests); } ).collect(Collectors.toList()); @@ -67,6 +69,7 @@ public MentorPostResponse.MentorPostDTO findMentorPost(int id){ .orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다.\n" + "id : " + id)); //writer 데이터 + //writer를 제외하고는 다 null 가능 User mentor = mentorPost.getWriter(); //mentee들 데이터 List menteeList = contactJPARepository.findAllByMentorPostId(id); @@ -123,7 +126,12 @@ public void changeMentorPostStatus(MentorPostRequest.StateDTO stateDTO, int id) { MentorPost mentorPost = mentorPostJPARepository.findById(id) .orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다."));; - mentorPost.changeStatus(stateDTO.getMentorPostStateEnum()); + + try { + mentorPost.changeStatus(stateDTO.getMentorPostStateEnum()); + } catch (Exception e) { + throw new Exception500("unknown server error"); + } } } From bd35a2a2d88d296519013d40c3e2d21731b13076 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Sun, 22 Oct 2023 23:34:11 +0900 Subject: [PATCH 03/84] =?UTF-8?q?feat=20:=20searchCategory=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=EB=B3=84=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20(=EC=A7=84=ED=96=89=EC=A4=91=20enum?= =?UTF-8?q?=ED=98=95=EC=9C=BC=EB=A1=9C=20=EB=8B=A4=20=EA=B3=A0=EC=B3=90?= =?UTF-8?q?=EC=95=BC=EB=90=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/MentorPostJPARepostiory.java | 11 ++++++ .../mentoring/MentorPostRestController.java | 8 +++- .../demo/mentoring/MentorPostService.java | 27 ++++++++++++- .../demo/mentoringtest/MentoringTest.java | 39 ++++++++++++++++++- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index bf6e112b..6fe348b3 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -1,9 +1,11 @@ package com.example.demo.mentoring; +import org.springframework.data.domain.Page; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.springframework.data.domain.Pageable; import java.util.List; import java.util.Optional; @@ -13,6 +15,15 @@ public interface MentorPostJPARepostiory extends JpaRepository findAllByWriter(@Param("writer") int writer); + @Query("select m from MentorPost m where m.title like :keyword") + Page findAllByTitleKeyword(@Param("keyword") String keyword, Pageable pageable); + + @Query("select m from MentorPost m where m.writer.firstName like :keyword or m.writer.firstName like :keyword") + Page findAllByWriterKeyword(@Param("keyword") String keyword, Pageable pageable); + +// @Query("select m from MentorPost m where m.title like :keyword") +// Page findAllByInterestKeyword(@Param("keyword") String keyword, Pageable pageable); + Optional findById(int id); @Query("select count(*) from MentorPost m where m.writer.id = :userId and m.state = 'ACTIVE'") diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java index baa88154..c4a49025 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java @@ -24,8 +24,12 @@ public ResponseEntity createMentorPost(@RequestBody @Valid MentorPostRequest. } @GetMapping("/mentorings/post") - public ResponseEntity getMentorPost(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { - List responseDTOs = mentorPostService.findAllMentorPost(page); + public ResponseEntity getMentorPost( + @RequestParam(value = "category", defaultValue = "") String category, + @RequestParam(value = "search", defaultValue = "") String keyword, + @RequestParam(value = "page", defaultValue = "0") Integer page, + @AuthenticationPrincipal CustomUserDetails userDetails) { + List responseDTOs = mentorPostService.findAllMentorPost(category, keyword, page); return ResponseEntity.ok(ApiUtils.success(responseDTOs)); } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index a1207dfb..112d55f4 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -45,10 +45,33 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) /* 1. mentorPostList를 조회 2. 각 List당 writer별 writerInterests를 조회 3. MentorPostDTO 생성*/ - public List findAllMentorPost(int page) { + public List findAllMentorPost(String serachCategory, String keyword, int page) { Pageable pageable = PageRequest.of(page,5); + Page pageContent = null; + + //검색별 pageContent 검색 + if(serachCategory == "") + { + pageContent = mentorPostJPARepository.findAll(pageable); + } + else if(serachCategory == "title") + { + pageContent = mentorPostJPARepository.findAllByTitleKeyword("%" + keyword + "%", pageable); + } + else if(serachCategory == "writer") + { + pageContent = mentorPostJPARepository.findAllByWriterKeyword("%" + keyword + "%", pageable); + } + else if(serachCategory == "interest") + { + //이거해야됨 + //pageContent = mentorPostJPARepository.findAllByInterestKeyword("%" + keyword + "%", pageable); + } + else + { + throw new Exception404("검색 분류가 잘못되었습니다."); + } - Page pageContent = mentorPostJPARepository.findAll(pageable); if(pageContent.getTotalPages() == 0){ throw new Exception404("해당 글들이 존재하지 않습니다"); diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java index 2f5fd936..5fae3777 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java @@ -188,7 +188,37 @@ void findMentorPostSaveTest() { MentorPost mentorPost3 = MentorPost.builder() .writer(mentor) - .title("title") + .title("titleab") + .content("content") + .build(); + + MentorPost mentorPost4 = MentorPost.builder() + .writer(mentor) + .title("abtitle4") + .content("content") + .build(); + + MentorPost mentorPost5 = MentorPost.builder() + .writer(mentor) + .title("title5") + .content("content") + .build(); + + MentorPost mentorPost6 = MentorPost.builder() + .writer(mentor) + .title("tabitle6") + .content("content") + .build(); + + MentorPost mentorPost7 = MentorPost.builder() + .writer(mentor) + .title("title7") + .content("content") + .build(); + + MentorPost mentorPost8 = MentorPost.builder() + .writer(mentor) + .title("abtitle8") .content("content") .build(); @@ -212,6 +242,11 @@ void findMentorPostSaveTest() { userJPARepository.save(mentee_One); userJPARepository.save(mentee_Two); mentorPostJPARepostiory.save(mentorPost3); + mentorPostJPARepostiory.save(mentorPost4); + mentorPostJPARepostiory.save(mentorPost5); + mentorPostJPARepostiory.save(mentorPost6); + mentorPostJPARepostiory.save(mentorPost7); + mentorPostJPARepostiory.save(mentorPost8); userInterestJPARepository.save(userInterest1); userInterestJPARepository.save(userInterest2); userInterestJPARepository.save(userInterest3); @@ -322,7 +357,7 @@ public void PatchDoneMentorPost() throws Exception{ @Test void mentorPostServiceTest() throws Exception { - List mentorPostFind = mentorPostService.findAllMentorPostWithTimeStamp(); + List mentorPostFind = mentorPostService.findAllMentorPost("title","ab",0); String responseBody = om.writeValueAsString(mentorPostFind); From c16258b4865e6d6c0efaa522700b09064145cadf Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Tue, 24 Oct 2023 22:06:45 +0900 Subject: [PATCH 04/84] feat : mentorPost: --- .../java/com/example/demo/mentoring/MentorPostService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index 112d55f4..bfc72755 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -34,6 +34,11 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) throw new Exception401("해당 사용자는 멘티입니다."); } + //글자수 확인 + if(createDTO.getContent().length() > 300){ + throw new Exception404("글자수가 300자를 넘어갑니다."); + } + MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent()); try { mentorPostJPARepository.save(mentorPost); From b131d706e35f007fc3a61ad85763c8ce7b009b96 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Tue, 24 Oct 2023 22:07:43 +0900 Subject: [PATCH 05/84] =?UTF-8?q?feat=20:=20mentorPost=20length=20exceptio?= =?UTF-8?q?n=20=EB=A9=98=ED=86=A0=EA=B8=80=20=EA=B8=B8=EC=9D=B4=20?= =?UTF-8?q?=EC=A0=9C=ED=95=9C=20300=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/mentoring/MentorPostService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index bfc72755..b6405407 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -118,6 +118,11 @@ public void updateMentorPost(MentorPostRequest.CreateDTO createDTO, int id) MentorPost mentorPost = mentorPostJPARepository.findById(id). orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다.")); + //글자수 확인 + if(createDTO.getContent().length() > 300){ + throw new Exception404("글자수가 300자를 넘어갑니다."); + } + try { mentorPost.update(createDTO.getTitle(), createDTO.getContent()); } catch (Exception e) { From d8fed85d8fba7b941ebc22a187c2e8e04eb23def Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Tue, 24 Oct 2023 22:40:44 +0900 Subject: [PATCH 06/84] =?UTF-8?q?feat=20:=20findAllByInterestKeyword=20Int?= =?UTF-8?q?erest=ED=83=9C=EA=B7=B8=EB=A1=9C=20=EA=B2=80=EC=83=89=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mentoring/MentorPostJPARepostiory.java | 4 +-- .../demo/mentoring/MentorPostService.java | 3 +- .../demo/mentoringtest/MentoringTest.java | 36 +++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index 6fe348b3..5f5aad56 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -21,8 +21,8 @@ public interface MentorPostJPARepostiory extends JpaRepository findAllByWriterKeyword(@Param("keyword") String keyword, Pageable pageable); -// @Query("select m from MentorPost m where m.title like :keyword") -// Page findAllByInterestKeyword(@Param("keyword") String keyword, Pageable pageable); + @Query("select m from MentorPost m inner join UserInterest ui ON m.writer.id = ui.user.id where ui.interest.category like :keyword") + Page findAllByInterestKeyword(@Param("keyword") String keyword, Pageable pageable); Optional findById(int id); diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index b6405407..85f5336c 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -69,8 +69,7 @@ else if(serachCategory == "writer") } else if(serachCategory == "interest") { - //이거해야됨 - //pageContent = mentorPostJPARepository.findAllByInterestKeyword("%" + keyword + "%", pageable); + pageContent = mentorPostJPARepository.findAllByInterestKeyword("%" + keyword + "%", pageable); } else { diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java index 5fae3777..3251d558 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java @@ -122,6 +122,17 @@ void findMentorPostSaveTest() { .phone("010-0000-0000") .build(); + User mentor2 = User.builder() + .email("anj2312364@gmail.com") + .password("adf1234!") + .firstName("Jin123") + .lastName("Seun123g") + .country("Korea") + .age(23) + .role(Role.MENTOR) + .phone("010-0000-0000") + .build(); + User mentee_One = User.builder() .email("anjda22l6664@gmail.com") .password("asdf221234!") @@ -186,9 +197,14 @@ void findMentorPostSaveTest() { .interest(interest3) .build(); + UserInterest userInterest7 = UserInterest.builder() + .user(mentor2) + .interest(interest1) + .build(); + MentorPost mentorPost3 = MentorPost.builder() .writer(mentor) - .title("titleab") + .title("title") .content("content") .build(); @@ -222,6 +238,18 @@ void findMentorPostSaveTest() { .content("content") .build(); + MentorPost mentorPost9 = MentorPost.builder() + .writer(mentor2) + .title("abtitle8") + .content("content") + .build(); + + MentorPost mentorPost10 = MentorPost.builder() + .writer(mentor2) + .title("abtitle83") + .content("content") + .build(); + NotConnectedRegisterUser menteeNotConnected1 = NotConnectedRegisterUser.builder() .mentorPost(mentorPost3) .menteeUser(mentee_One) @@ -239,6 +267,7 @@ void findMentorPostSaveTest() { interestJPARepository.save(interest2); interestJPARepository.save(interest3); userJPARepository.save(mentor); + userJPARepository.save(mentor2); userJPARepository.save(mentee_One); userJPARepository.save(mentee_Two); mentorPostJPARepostiory.save(mentorPost3); @@ -247,12 +276,15 @@ void findMentorPostSaveTest() { mentorPostJPARepostiory.save(mentorPost6); mentorPostJPARepostiory.save(mentorPost7); mentorPostJPARepostiory.save(mentorPost8); + mentorPostJPARepostiory.save(mentorPost9); + mentorPostJPARepostiory.save(mentorPost10); userInterestJPARepository.save(userInterest1); userInterestJPARepository.save(userInterest2); userInterestJPARepository.save(userInterest3); userInterestJPARepository.save(userInterest4); userInterestJPARepository.save(userInterest5); userInterestJPARepository.save(userInterest6); + userInterestJPARepository.save(userInterest7); contactJPARepository.save(menteeNotConnected1); contactJPARepository.save(menteeNotConnected2); @@ -357,7 +389,7 @@ public void PatchDoneMentorPost() throws Exception{ @Test void mentorPostServiceTest() throws Exception { - List mentorPostFind = mentorPostService.findAllMentorPost("title","ab",0); + List mentorPostFind = mentorPostService.findAllMentorPost("interest","test1",0); String responseBody = om.writeValueAsString(mentorPostFind); From ff93ade4425096edcc54e83bffa6e4741171adf6 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Tue, 24 Oct 2023 23:12:52 +0900 Subject: [PATCH 07/84] =?UTF-8?q?fix=20:=20mentorPostService=20string=20to?= =?UTF-8?q?=20enum=20category=20string=ED=98=95=EC=9D=84=20Enum=ED=98=95?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/mentoring/MentorPostCategoryEnum.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java diff --git a/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java b/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java new file mode 100644 index 00000000..da6f3ebb --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java @@ -0,0 +1,2 @@ +package com.example.demo.mentoring;public enum MentorPostCategoryEnum { +} From 35d01fda9b2511ab5f9eace8f480d55de334fe88 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Thu, 26 Oct 2023 21:56:08 +0900 Subject: [PATCH 08/84] feat : mentorPostCategory --- .../example/demo/mentoring/MentorPostCategoryEnum.java | 5 ++++- .../demo/mentoring/MentorPostRestController.java | 6 +++++- .../com/example/demo/mentoring/MentorPostService.java | 10 +++++----- .../com/example/demo/mentoringtest/MentoringTest.java | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java b/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java index da6f3ebb..0e4829eb 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostCategoryEnum.java @@ -1,2 +1,5 @@ -package com.example.demo.mentoring;public enum MentorPostCategoryEnum { +package com.example.demo.mentoring; + +public enum MentorPostCategoryEnum { + NULL, TITLE, WRITER, INTEREST; } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java index c4a49025..ba3f2b67 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java @@ -25,10 +25,14 @@ public ResponseEntity createMentorPost(@RequestBody @Valid MentorPostRequest. @GetMapping("/mentorings/post") public ResponseEntity getMentorPost( - @RequestParam(value = "category", defaultValue = "") String category, + @RequestParam(value = "category", required = false) MentorPostCategoryEnum category, @RequestParam(value = "search", defaultValue = "") String keyword, @RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { + + if(category == null) + category = MentorPostCategoryEnum.NULL; + List responseDTOs = mentorPostService.findAllMentorPost(category, keyword, page); return ResponseEntity.ok(ApiUtils.success(responseDTOs)); } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index 85f5336c..774f9f6e 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -50,24 +50,24 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) /* 1. mentorPostList를 조회 2. 각 List당 writer별 writerInterests를 조회 3. MentorPostDTO 생성*/ - public List findAllMentorPost(String serachCategory, String keyword, int page) { + public List findAllMentorPost(MentorPostCategoryEnum searchCategory, String keyword, int page) { Pageable pageable = PageRequest.of(page,5); Page pageContent = null; //검색별 pageContent 검색 - if(serachCategory == "") + if(searchCategory == MentorPostCategoryEnum.NULL) { pageContent = mentorPostJPARepository.findAll(pageable); } - else if(serachCategory == "title") + else if(searchCategory == MentorPostCategoryEnum.TITLE) { pageContent = mentorPostJPARepository.findAllByTitleKeyword("%" + keyword + "%", pageable); } - else if(serachCategory == "writer") + else if(searchCategory == MentorPostCategoryEnum.WRITER) { pageContent = mentorPostJPARepository.findAllByWriterKeyword("%" + keyword + "%", pageable); } - else if(serachCategory == "interest") + else if(searchCategory == MentorPostCategoryEnum.INTEREST) { pageContent = mentorPostJPARepository.findAllByInterestKeyword("%" + keyword + "%", pageable); } diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java index 3251d558..66fb3290 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java @@ -389,7 +389,7 @@ public void PatchDoneMentorPost() throws Exception{ @Test void mentorPostServiceTest() throws Exception { - List mentorPostFind = mentorPostService.findAllMentorPost("interest","test1",0); + List mentorPostFind = mentorPostService.findAllMentorPost(MentorPostCategoryEnum.NULL,"",2); String responseBody = om.writeValueAsString(mentorPostFind); From 4ac2ccbe4889f9730071772a2b11ddec16ccad70 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Thu, 26 Oct 2023 23:16:27 +0900 Subject: [PATCH 09/84] =?UTF-8?q?feat=20:=20initialize=20and=20usercategor?= =?UTF-8?q?y=20video=20response=20dto=20restcontroller=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=A0=20=ED=8C=8C=EC=9D=BC=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EB=B0=8F=20restcontroller=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/video/VideoJPARepostiory.java | 7 +++++ .../com/example/demo/video/VideoResponse.java | 4 +++ .../demo/video/VideoRestController.java | 27 +++++++++++++++++++ .../com/example/demo/video/VideoService.java | 12 +++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/main/java/com/example/demo/video/VideoJPARepostiory.java create mode 100644 src/main/java/com/example/demo/video/VideoResponse.java create mode 100644 src/main/java/com/example/demo/video/VideoRestController.java create mode 100644 src/main/java/com/example/demo/video/VideoService.java diff --git a/src/main/java/com/example/demo/video/VideoJPARepostiory.java b/src/main/java/com/example/demo/video/VideoJPARepostiory.java new file mode 100644 index 00000000..2da192ef --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoJPARepostiory.java @@ -0,0 +1,7 @@ +package com.example.demo.video; + +import com.example.demo.user.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface VideoJPARepostiory extends JpaRepository { +} diff --git a/src/main/java/com/example/demo/video/VideoResponse.java b/src/main/java/com/example/demo/video/VideoResponse.java new file mode 100644 index 00000000..f79b730e --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoResponse.java @@ -0,0 +1,4 @@ +package com.example.demo.video; + +public class VideoResponse { +} diff --git a/src/main/java/com/example/demo/video/VideoRestController.java b/src/main/java/com/example/demo/video/VideoRestController.java new file mode 100644 index 00000000..cb4e880f --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoRestController.java @@ -0,0 +1,27 @@ +package com.example.demo.video; + +import com.example.demo.config.auth.CustomUserDetails; +import com.example.demo.config.utils.ApiUtils; +import io.swagger.annotations.Api; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@Api(tags = "Video API") +@RequiredArgsConstructor +@RestController +public class VideoRestController { + + private final VideoService videoService; + + @GetMapping("/videos/main") + public ResponseEntity getUserCategoryVideo(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { + List responseDTOs = videoService.findUserCategoryVideo(page); + return ResponseEntity.ok(ApiUtils.success(responseDTOs)); + } +} diff --git a/src/main/java/com/example/demo/video/VideoService.java b/src/main/java/com/example/demo/video/VideoService.java new file mode 100644 index 00000000..e7af806c --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoService.java @@ -0,0 +1,12 @@ +package com.example.demo.video; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Transactional +@RequiredArgsConstructor +@Service +public class VideoService { + +} From 0b02c4253b3708bde4114ab28b4f240482b5487d Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Thu, 26 Oct 2023 23:36:14 +0900 Subject: [PATCH 10/84] feat : usercategoryVideoResponseDTO videoresponse --- .../java/com/example/demo/video/Video.java | 10 +++++-- .../com/example/demo/video/VideoResponse.java | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/demo/video/Video.java b/src/main/java/com/example/demo/video/Video.java index bdf88b93..e96598d2 100644 --- a/src/main/java/com/example/demo/video/Video.java +++ b/src/main/java/com/example/demo/video/Video.java @@ -22,7 +22,10 @@ public class Video extends BaseTime { private String videoUrl; @Column - private String videoInfo; + private String videoInfoKorean; + + @Column + private String videoInfoEng; @Column private String videoStartTime; @@ -31,9 +34,10 @@ public class Video extends BaseTime { private String videoEndTime; @Builder - public Video(String videoUrl, String videoInfo, String videoStartTime, String videoEndTime) { + public Video(String videoUrl, String videoInfoKorean, String videoInfoEng, String videoStartTime, String videoEndTime) { this.videoUrl = videoUrl; - this.videoInfo = videoInfo; + this.videoInfoKorean = videoInfoKorean; + this.videoInfoEng = videoInfoEng; this.videoStartTime = videoStartTime; this.videoEndTime = videoEndTime; } diff --git a/src/main/java/com/example/demo/video/VideoResponse.java b/src/main/java/com/example/demo/video/VideoResponse.java index f79b730e..8a99dcd2 100644 --- a/src/main/java/com/example/demo/video/VideoResponse.java +++ b/src/main/java/com/example/demo/video/VideoResponse.java @@ -1,4 +1,32 @@ package com.example.demo.video; +import com.example.demo.mentoring.MentorPostResponse; +import com.example.demo.user.userInterest.UserInterest; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.stream.Collectors; + public class VideoResponse { + @Getter + @Setter + public class UserCategoryVideoResponseDTO { + private int videoID; + private String videoUrl; + private String videoInfoKorean; + private String videoInfoEng; + private List interests; + + public UserCategoryVideoResponseDTO(Video video, List videoInterests) + { + this.videoID = video.getId(); + this.videoUrl = video.getVideoUrl(); + this.videoInfoKorean = video.getVideoInfoKorean(); + this.videoInfoEng = video.getVideoInfoEng(); + this.interests = videoInterests.stream() + .map(videoInterest -> videoInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } + } } From e8aaeac2561133ab7b58fa4bfba341394a4fb302 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sat, 28 Oct 2023 16:13:26 +0900 Subject: [PATCH 11/84] =?UTF-8?q?feat=20:=20=EB=A9=98=ED=8B=B0=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=ED=99=94=EB=A9=B4=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EA=B0=AF=EC=88=98=20=EB=B3=B4=EC=97=AC=EC=A3=BC=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../demo/mentoring/contact/ContactJPARepository.java | 3 +++ .../demo/mentoring/contact/ContactRestController.java | 3 ++- .../example/demo/mentoring/contact/ContactService.java | 10 ++++++++++ .../example/demo/mentoring/done/DoneJPARepository.java | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java b/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java index 0758206b..35080934 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java @@ -14,4 +14,7 @@ public interface ContactJPARepository extends JpaRepository findByMentorPostIdAndMenteeUserId(int mentorPostId, int menteeId); + + @Query("SELECT count(*) FROM NotConnectedRegisterUser ncru WHERE ncru.menteeUser.id = :userId") + int countContactByMenteeId(int userId); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 353a41ba..5a89cfc7 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -40,7 +40,8 @@ public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails u Role role = userDetails.getUser().getRole(); if ( role == Role.MENTEE ) { - return null; + ContactResponse.postCountDTO responseDTO = contactService.postCountsMyMentee(userDetails.getUser().getId()); + return ResponseEntity.ok(ApiUtils.success(responseDTO)); } ContactResponse.postCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId()); diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index cac09d1b..26bcc846 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -97,6 +97,15 @@ public ContactResponse.postCountDTO postCountsByMentor(int userId) { return new ContactResponse.postCountDTO(contactCount, doneCount); } + // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 ( 멘티 ) + public ContactResponse.postCountDTO postCountsMyMentee(int userId) { + // contact 화면에서 게시글을 조회 + int contactCount = contactJPARepository.countContactByMenteeId(userId); + // done 화면에서 게시글을 조회 + int doneCount = doneJPARepository.countDoneByMenteeId(userId); + + return new ContactResponse.postCountDTO(contactCount, doneCount); + } @Transactional public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) { @@ -134,4 +143,5 @@ public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) } } + } diff --git a/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java b/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java index 2d58d891..2195ff94 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java @@ -5,4 +5,6 @@ public interface DoneJPARepository extends JpaRepository { + @Query("SELECT count(*) FROM ConnectedUser cu WHERE cu.menteeUser.id = :userId") + int countDoneByMenteeId(int userId); } From f931ddd81972df4144f086bec72a5ddfa20cf5fa Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sat, 28 Oct 2023 16:13:50 +0900 Subject: [PATCH 12/84] =?UTF-8?q?fix=20:=20table=20=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9D=B4=EB=A6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- src/main/resources/db/teardown.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/resources/db/teardown.sql b/src/main/resources/db/teardown.sql index d5685160..c2a2f103 100644 --- a/src/main/resources/db/teardown.sql +++ b/src/main/resources/db/teardown.sql @@ -1,10 +1,10 @@ SET REFERENTIAL_INTEGRITY FALSE; TRUNCATE TABLE user_tb; TRUNCATE TABLE interest_tb; -TRUNCATE TABLE mentor_post_tb; +TRUNCATE TABLE mentor_posts; TRUNCATE TABLE user_interest_tb; -TRUNCATE TABLE not_connected_register_user_tb; -TRUNCATE TABLE connected_user_tb; +TRUNCATE TABLE not_connected_register_users; +TRUNCATE TABLE connected_users; SET REFERENTIAL_INTEGRITY TRUE; -- user Table @@ -24,7 +24,7 @@ INSERT INTO interest_tb (created_at, category) VALUES (NOW(), 'Sports'); -- mentorPost Table -INSERT INTO mentor_post_tb (created_at, writer_id, title, content, state) VALUES +INSERT INTO mentor_posts (created_at, writer_id, title, content, state) VALUES (NOW(), 1, 'Teaching Programming', 'I can teach you how to code.', 'ACTIVE'), (NOW(), 1, 'Art Workshop', 'Let''s create beautiful art together.', 'DONE'), (NOW(), 2, 'Software Development Mentorship', 'I can mentor you in software development.', 'ACTIVE'), @@ -42,14 +42,16 @@ INSERT INTO mentor_post_tb (created_at, writer_id, title, content, state) VALUES -- notConnectedRegisterUser Table -INSERT INTO not_connected_register_user_tb (created_at, mentor_post_id, mentee_user_id, state) VALUES +INSERT INTO not_connected_register_users (created_at, mentor_post_id, mentee_user_id, state) VALUES (NOW(), 1, 3, 'AWAIT'), + (NOW(), 3, 3, 'AWAIT'), (NOW(), 1, 4, 'ACCEPT'), (NOW(), 3, 5, 'AWAIT'); -- connectedUser Table -INSERT INTO connected_user_tb (created_at, mentor_post_id, mentee_user_id) VALUES +INSERT INTO connected_users (created_at, mentor_post_id, mentee_user_id) VALUES (NOW(), 2, 3), + (NOW(), 3, 3), (NOW(), 2, 5), (NOW(), 2, 6); From 342134a11ee1c945b97b5e6cec60c851d9a73d40 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sat, 28 Oct 2023 16:14:07 +0900 Subject: [PATCH 13/84] =?UTF-8?q?test=20:=20=EB=A9=98=ED=8B=B0=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20=EA=B0=AF=EC=88=98=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../java/com/example/demo/contactTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 6c1d8dd2..f3a0a107 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -62,7 +62,7 @@ void contactTest() throws Exception { @Test @WithUserDetails("john@example.com") - @DisplayName("contact, done - count") + @DisplayName("contact, done count : mentor") void countTest() throws Exception { // when @@ -78,6 +78,25 @@ void countTest() throws Exception { resultActions.andExpect(jsonPath("$.status").value("success")); } + @Test + @WithUserDetails("admin@example.com") + @DisplayName("contact, done count : mentee") + void countByMenteeTest() throws Exception { + // given + + // when + ResultActions resultActions = mvc.perform( + get("/contacts/postCounts") + ); + + // console + String responseBody = resultActions.andReturn().getResponse().getContentAsString(); + System.out.println("테스트 : "+responseBody); + + // verify + resultActions.andExpect(jsonPath("$.status").value("success")); + } + @Test @WithUserDetails("john@example.com") @DisplayName("contact - Accept - Test") From e654ed4aa5f3f8af2f40daedab3709c20b7f1b15 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sat, 28 Oct 2023 21:45:07 +0900 Subject: [PATCH 14/84] =?UTF-8?q?feat=20:=20=EB=A9=98=ED=86=A0=20:=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EA=B1=B0=EB=B6=80=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactRequest.java | 16 +++++++++++ .../contact/ContactRestController.java | 8 ++++++ .../mentoring/contact/ContactService.java | 27 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java index 45522e35..73d39160 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java @@ -1,6 +1,7 @@ package com.example.demo.mentoring.contact; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import javax.validation.constraints.NotNull; @@ -8,6 +9,21 @@ public class ContactRequest { + @Getter @Setter + public static class RefuseDTO { + private int mentorPostId; + private int mentorId; + private List mentees; + @Getter @Setter @NoArgsConstructor + public static class MenteeDTO { + @NotNull + private int menteeId; + public MenteeDTO(int menteeId) { + this.menteeId = menteeId; + } + } + } + @Getter @Setter public static class AcceptDTO { private int mentorPostId; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 5a89cfc7..e564137d 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -56,6 +56,14 @@ public ResponseEntity acceptContact(@PathVariable int id, @RequestBody @Valid return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } + @PostMapping(value = "/contacts/{id}/refuse") + @Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.") + public ResponseEntity refuseContact(@PathVariable int id, @RequestBody @Valid ContactRequest.RefuseDTO refuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + // TO-DO : 멘토링 신청 거절 API 로직 만들기 + contactService.refuseContact(id, refuseDTO, userDetails.getUser()); + return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + } + } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 26bcc846..b0ef752d 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -144,4 +144,31 @@ public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) } + @Transactional + public void refuseContact(int id, ContactRequest.RefuseDTO refuseDTO, User user) { + // 예외 처리 + if ( user.getRole() != Role.MENTOR ) { + throw new Exception401("해당 사용자는 멘토가 아닙니다."); + } + + if (id != user.getId() ) { + throw new Exception401("올바른 사용자가 아닙니다."); + } + + int mentorPostId = refuseDTO.getMentorPostId(); + + // 멘토와 현재 유저가 같은지 확인 + if ( refuseDTO.getMentorId() != user.getId() ) { + throw new Exception401("올바른 사용자가 아닙니다."); + } + + // notConnectedRegisterUser 의 state 바꾸기 -> REFUSE + for ( ContactRequest.RefuseDTO.MenteeDTO menteeDTO : refuseDTO.getMentees() ) { + + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, menteeDTO.getMenteeId()) + .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); + + notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.REFUSE); + } + } } From 248d9710336bef0d979c1eabb27e2b8ec6a28258 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sat, 28 Oct 2023 21:45:25 +0900 Subject: [PATCH 15/84] =?UTF-8?q?test=20:=20=EB=A9=98=ED=86=A0=20:=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EA=B1=B0=EB=B6=80=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../java/com/example/demo/contactTest.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index f3a0a107..196c66db 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -97,6 +97,45 @@ void countByMenteeTest() throws Exception { resultActions.andExpect(jsonPath("$.status").value("success")); } + @Test + @WithUserDetails("john@example.com") + @DisplayName("contact - Refuse - Test") + void contactRefuseTest() throws Exception { + // given + ContactRequest.RefuseDTO requestDTOs = new ContactRequest.RefuseDTO(); + requestDTOs.setMentorPostId(1); + requestDTOs.setMentorId(1); + + List menteeDTOs = new ArrayList<>(); + menteeDTOs.add(new ContactRequest.RefuseDTO.MenteeDTO(3)); + + requestDTOs.setMentees(menteeDTOs); + + String requestBody = om.writeValueAsString(requestDTOs); + + System.out.println("테스트 : "+requestBody); + + // when + ResultActions result = mvc.perform( + MockMvcRequestBuilders.post("/contacts/1/refuse") + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON) + ); + String responseBody = result.andReturn().getResponse().getContentAsString(); + System.out.println("테스트 : "+responseBody); + + // 테스트가 잘 됐는지 ( 값이 잘 바뀌는지 확인 ) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(1, 3) + .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); + + System.out.println("state 확인 : " + notConnectedRegisterUser.getState()); + // then + // verify + result.andExpect(jsonPath("$.status").value("success")); // 성공 테스트 확인 + // 값이 잘 들어가는지 확인 + Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.REFUSE); + } + @Test @WithUserDetails("john@example.com") @DisplayName("contact - Accept - Test") From 6535981c9434c65afe7d30d75e47cd14416c8900 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 11:18:30 +0900 Subject: [PATCH 16/84] =?UTF-8?q?fix=20:=20=EB=A9=98=ED=86=A0=EB=A7=81=20A?= =?UTF-8?q?ccept=20requestDTO=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../demo/mentoring/contact/ContactRequest.java | 13 +++++-------- .../demo/mentoring/contact/ContactService.java | 13 ++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java index 73d39160..0a502b3a 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java @@ -27,16 +27,13 @@ public MenteeDTO(int menteeId) { @Getter @Setter public static class AcceptDTO { private int mentorPostId; - private List mentorsAndMentees; - @Getter @Setter - public static class MentorAndMenteeDTO { - @NotNull - private int mentorId; + private int mentorId; + private List mentees; + @Getter @Setter @NoArgsConstructor + public static class MenteeDTO { @NotNull private int menteeId; - - public MentorAndMenteeDTO(int mentorId, int menteeId) { - this.mentorId = mentorId; + public MenteeDTO(int menteeId) { this.menteeId = menteeId; } } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index b0ef752d..383eb5f5 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -113,8 +113,8 @@ public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); } - - if (id != user.getId() ) { + // user 체크 + if (id != user.getId() || acceptDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -125,15 +125,10 @@ public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) .orElseThrow(() -> new Exception404("해당 게시글을 찾을 수 없습니다.")); // ConnectedUser 에 추가 - for ( ContactRequest.AcceptDTO.MentorAndMenteeDTO mentorAndMenteeDTO : acceptDTO.getMentorsAndMentees() ) { - - // 멘토가 현재 유저와 같은지 확인 - if ( mentorAndMenteeDTO.getMentorId() != user.getId() ) { - throw new Exception401("올바른 사용자가 아닙니다."); - } + for ( ContactRequest.AcceptDTO.MenteeDTO menteeDTO : acceptDTO.getMentees() ) { // notConnectedRegisterUser 의 state 바꾸기 -> ACCEPT - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, mentorAndMenteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, menteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.ACCEPT); From 2dfa3b755b1c8863b7a7cf3a6a9cc79b652dae37 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 11:18:47 +0900 Subject: [PATCH 17/84] =?UTF-8?q?test=20:=20=EC=88=98=EC=A0=95=20=ED=9B=84?= =?UTF-8?q?=20=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- src/test/java/com/example/demo/contactTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 196c66db..e5244193 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -144,11 +144,12 @@ void contactAccpetTest() throws Exception { ContactRequest.AcceptDTO requestDTOs = new ContactRequest.AcceptDTO(); requestDTOs.setMentorPostId(1); + requestDTOs.setMentorId(1); - List mentorAndMenteeDTOs = new ArrayList<>(); - mentorAndMenteeDTOs.add(new ContactRequest.AcceptDTO.MentorAndMenteeDTO(1, 3)); + List menteeDTOs = new ArrayList<>(); + menteeDTOs.add(new ContactRequest.AcceptDTO.MenteeDTO(3)); - requestDTOs.setMentorsAndMentees(mentorAndMenteeDTOs); + requestDTOs.setMentees(menteeDTOs); String requestBody = om.writeValueAsString(requestDTOs); From be4cbf358b955ce6d3b629bb111cafea6604dc74 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 12:28:14 +0900 Subject: [PATCH 18/84] =?UTF-8?q?feat=20:=20=EB=A9=98=ED=8B=B0=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactRequest.java | 7 ++++ .../contact/ContactRestController.java | 8 ++++- .../mentoring/contact/ContactService.java | 35 ++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java index 0a502b3a..974d7e09 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java @@ -9,6 +9,13 @@ public class ContactRequest { + @Getter @Setter + public static class CreateDTO { + private int mentorPostId; + private int mentorId; + private int menteeId; + } + @Getter @Setter public static class RefuseDTO { private int mentorPostId; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index e564137d..4a334423 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -64,6 +64,12 @@ public ResponseEntity refuseContact(@PathVariable int id, @RequestBody @Valid return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - + @PostMapping(value = "/contacts/{id}") + @Operation(summary = "멘티의 멘토링 신청", description = "멘토가 작성한 글을 보고, 멘티는 멘토링 신청을 할 수 있다.") + public ResponseEntity createContact(@PathVariable int id, @RequestBody @Valid ContactRequest.CreateDTO createDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + // TO-DO : 멘토링 신청 API 로직 만들기 + contactService.createContact(id, createDTO, userDetails.getUser()); + return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + } } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 383eb5f5..49b522f8 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -108,13 +108,13 @@ public ContactResponse.postCountDTO postCountsMyMentee(int userId) { } @Transactional - public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) { + public void acceptContact(int userId, ContactRequest.AcceptDTO acceptDTO, User user) { // 예외 처리 if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); } // user 체크 - if (id != user.getId() || acceptDTO.getMentorId() != user.getId() ) { + if (userId != user.getId() || acceptDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -140,13 +140,13 @@ public void acceptContact(int id, ContactRequest.AcceptDTO acceptDTO, User user) } @Transactional - public void refuseContact(int id, ContactRequest.RefuseDTO refuseDTO, User user) { + public void refuseContact(int userId, ContactRequest.RefuseDTO refuseDTO, User user) { // 예외 처리 if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); } - if (id != user.getId() ) { + if (userId != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -166,4 +166,31 @@ public void refuseContact(int id, ContactRequest.RefuseDTO refuseDTO, User user) notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.REFUSE); } } + + @Transactional + public void createContact(int userId, ContactRequest.CreateDTO createDTO, User user) { + // 예외 처리 + if ( user.getRole() != Role.MENTEE ) { + throw new Exception401("해당 사용자는 멘티가 아닙니다."); + } + + if (userId != user.getId() ) { + throw new Exception401("올바른 사용자가 아닙니다."); + } + + int mentorPostId = createDTO.getMentorPostId(); + + // 현재 멘토가 작성한 글인지 체크 + MentorPost mentorPost = mentorPostJPARepository.findById(mentorPostId) + .orElseThrow(() -> new Exception404("해당 게시글을 찾을 수 없습니다.")); + + // 이미 신청한 글인지 체크하기 + if ( contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, userId).isPresent() ) { + throw new Exception401("이미 신청한 글입니다."); + } + + // notConnectedRegisterUser 에 save 하기 + contactJPARepository.save(new NotConnectedRegisterUser(mentorPost, user, NotConnectedRegisterUser.State.AWAIT)); + + } } From be37f213aa93b3674e5dae8891d3e4d33307968a Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 12:28:42 +0900 Subject: [PATCH 19/84] =?UTF-8?q?test=20:=20=EB=A9=98=ED=8B=B0=20=EC=8B=A0?= =?UTF-8?q?=EC=B2=AD=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20?= =?UTF-8?q?=EB=B0=8F=20DisplayName=20=EC=97=90=EB=84=88=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EC=85=98=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../java/com/example/demo/contactTest.java | 69 +++++++++++++++++-- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index e5244193..6128332c 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -39,10 +39,29 @@ public class contactTest extends RestDoc { @Autowired private DoneJPARepository doneJPARepository; + @Test + @WithUserDetails("admin@example.com") + @DisplayName("멘티 기준 화면 조회 테스트 코드") + void contactMenteeTest() throws Exception { + // given + + // when + ResultActions resultActions = mvc.perform( + get("/contacts") + ); + + // console + String responseBody = resultActions.andReturn().getResponse().getContentAsString(); + System.out.println("테스트 : "+responseBody); + + // verify + resultActions.andExpect(jsonPath("$.status").value("success")); + } + @Test @WithUserDetails("john@example.com") - @DisplayName("contact - mentor") - void contactTest() throws Exception { + @DisplayName("멘토 기준 화면 조회 테스트 코드") + void contactMentorTest() throws Exception { // given @@ -59,10 +78,10 @@ void contactTest() throws Exception { resultActions.andExpect(jsonPath("$.status").value("success")); } - + @Test @WithUserDetails("john@example.com") - @DisplayName("contact, done count : mentor") + @DisplayName("멘토 기준 게시글 갯수 조회 테스트 코드") void countTest() throws Exception { // when @@ -80,7 +99,7 @@ void countTest() throws Exception { @Test @WithUserDetails("admin@example.com") - @DisplayName("contact, done count : mentee") + @DisplayName("멘티 기준 게시글 조회 테스트 코드") void countByMenteeTest() throws Exception { // given @@ -99,7 +118,7 @@ void countByMenteeTest() throws Exception { @Test @WithUserDetails("john@example.com") - @DisplayName("contact - Refuse - Test") + @DisplayName("멘토 : 신청 거부 기능 테스트 코드") void contactRefuseTest() throws Exception { // given ContactRequest.RefuseDTO requestDTOs = new ContactRequest.RefuseDTO(); @@ -138,7 +157,7 @@ void contactRefuseTest() throws Exception { @Test @WithUserDetails("john@example.com") - @DisplayName("contact - Accept - Test") + @DisplayName("멘토 : 신청 수락 테스트 코드") void contactAccpetTest() throws Exception { // given ContactRequest.AcceptDTO requestDTOs = new ContactRequest.AcceptDTO(); @@ -182,4 +201,40 @@ void contactAccpetTest() throws Exception { Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.ACCEPT); Assertions.assertThat(connectedUser.getId()).isEqualTo(4); } + + @Test + @WithUserDetails("jane@example.com") + @DisplayName("멘티 : 신청 생성 테스트 코드") + void createTest() throws Exception { + // given + ContactRequest.CreateDTO createDTO = new ContactRequest.CreateDTO(); + // mentor, mentorPost, mentee id 지정 + createDTO.setMentorPostId(3); + createDTO.setMentorId(2); + createDTO.setMenteeId(4); + + String requestBody = om.writeValueAsString(createDTO); + + System.out.println("테스트 requestBody : "+requestBody); + + // when + ResultActions result = mvc.perform( + MockMvcRequestBuilders.post("/contacts/4") + .content(requestBody) + .contentType(MediaType.APPLICATION_JSON) + ); + String responseBody = result.andReturn().getResponse().getContentAsString(); + System.out.println("테스트 responseBody : "+responseBody); + + // 테스트가 잘 됐는지 ( 값이 잘 바뀌는지 확인 ) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(5) + .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); + + // then + // verify + result.andExpect(jsonPath("$.status").value("success")); // 성공 테스트 확인 + // 값이 잘 들어가는지 확인 + Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.AWAIT); + + } } From babfe21a9ad8633b78d59900bca4ed3f0270f47f Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 12:32:20 +0900 Subject: [PATCH 20/84] =?UTF-8?q?fix=20:=20=EB=A9=98=ED=86=A0=20:=20?= =?UTF-8?q?=EB=A9=98=ED=8B=B0=20=EC=8B=A0=EC=B2=AD=20=EA=B1=B0=EB=B6=80=20?= =?UTF-8?q?post=20->=20patch=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../example/demo/mentoring/contact/ContactRestController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 4a334423..6b2142cb 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -56,7 +56,7 @@ public ResponseEntity acceptContact(@PathVariable int id, @RequestBody @Valid return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @PostMapping(value = "/contacts/{id}/refuse") + @PatchMapping(value = "/contacts/{id}/refuse") @Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.") public ResponseEntity refuseContact(@PathVariable int id, @RequestBody @Valid ContactRequest.RefuseDTO refuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 거절 API 로직 만들기 From 67453b57c87d4a152fbfadb05e5be24a4d83bd91 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 12:39:04 +0900 Subject: [PATCH 21/84] =?UTF-8?q?test=20:=20patch=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- src/test/java/com/example/demo/contactTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 6128332c..0287abf1 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -136,7 +136,7 @@ void contactRefuseTest() throws Exception { // when ResultActions result = mvc.perform( - MockMvcRequestBuilders.post("/contacts/1/refuse") + MockMvcRequestBuilders.patch("/contacts/1/refuse") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); From 7233bacb726fb5ac815b1d842cf378b6a86a4c7c Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 21:26:07 +0900 Subject: [PATCH 22/84] =?UTF-8?q?fix=20:=20is=5Fdeleted=20SQL=EB=AC=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../demo/mentoring/contact/NotConnectedRegisterUser.java | 2 +- .../java/com/example/demo/mentoring/done/ConnectedUser.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java index ba5ea63d..1a191d2d 100644 --- a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java +++ b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java @@ -16,7 +16,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Where(clause = "deleted_at IS NULL") -@SQLDelete(sql = "UPDATE not_connected_register_users SET deleted_at = CURRENT_TIMESTAMP, isDeleted = TRUE where id = ?") +@SQLDelete(sql = "UPDATE not_connected_register_users SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") @Table(name = "not_connected_register_users") public class NotConnectedRegisterUser extends BaseTime { diff --git a/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java b/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java index 779cb7a8..aa53af5a 100644 --- a/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java +++ b/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java @@ -16,7 +16,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Where(clause = "deleted_at IS NULL") -@SQLDelete(sql = "UPDATE connected_users SET deleted_at = CURRENT_TIMESTAMP, isDeleted = TRUE where id = ?") +@SQLDelete(sql = "UPDATE connected_users SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") @Table(name = "connected_users") public class ConnectedUser extends BaseTime { From dbd1dab183e5f8e1d5ba75701f05098f079a4036 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 21:27:01 +0900 Subject: [PATCH 23/84] =?UTF-8?q?feat=20:=20=EB=A9=98=ED=8B=B0=20:=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=B7=A8=EC=86=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../contact/ContactRestController.java | 8 ++++++++ .../mentoring/contact/ContactService.java | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 6b2142cb..76b3ed48 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -72,4 +72,12 @@ public ResponseEntity createContact(@PathVariable int id, @RequestBody @Valid return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } + @DeleteMapping(value = "/contacts/{id}") + @Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.") + public ResponseEntity deleteContact(@PathVariable int id, @RequestParam("mentorPostId") int mentorPostId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + // TO-DO : 멘토링 신청 취소 API 로직 만들기 + contactService.deleteContact(id, mentorPostId, userDetails.getUser()); + return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); + } + } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 49b522f8..70dea5e9 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -193,4 +193,23 @@ public void createContact(int userId, ContactRequest.CreateDTO createDTO, User u contactJPARepository.save(new NotConnectedRegisterUser(mentorPost, user, NotConnectedRegisterUser.State.AWAIT)); } + + @Transactional + public void deleteContact(int userId, int mentorPostId, User user) { + // 예외 처리 + if ( user.getRole() != Role.MENTEE ) { + throw new Exception401("해당 사용자는 멘티가 아닙니다."); + } + + // 현재 유저와 userId 값이 일치하는지 확인 + if ( user.getId() != userId ) { + throw new Exception401("올바른 사용자가 아닙니다."); + } + // 해당하는 NotConnectedRegisterUser 가져오기 + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, userId) + .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다." )); + + // notConnectedRegisterUser delete 요청 보내기 + contactJPARepository.deleteById(notConnectedRegisterUser.getId()); + } } From c8653f9c1aec894ed2311729aa98162056c26255 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 21:27:15 +0900 Subject: [PATCH 24/84] =?UTF-8?q?test=20:=20=EB=A9=98=ED=8B=B0=20:=20?= =?UTF-8?q?=EC=8B=A0=EC=B2=AD=20=EC=B7=A8=EC=86=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../java/com/example/demo/contactTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 0287abf1..3fc80077 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -237,4 +237,25 @@ void createTest() throws Exception { Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.AWAIT); } + + @Test + @WithUserDetails("admin@example.com") + @DisplayName("멘티 : 신청 취소 테스트 코드") + void deleteTest() throws Exception { + // given + int id = 3; + int mentorPostId = 1; + + // when + ResultActions result = mvc.perform( + MockMvcRequestBuilders.delete("/contacts/" + id) + .param("mentorPostId", String.valueOf(mentorPostId)) + .contentType(MediaType.APPLICATION_JSON) + ); + String responseBody = result.andReturn().getResponse().getContentAsString(); + System.out.println("테스트 responseBody : "+responseBody); + + // then + result.andExpect(jsonPath("$.status").value("success")); // 성공 테스트 확인 + } } From df05ddfffec37add08454803d097567547007864 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 21:43:17 +0900 Subject: [PATCH 25/84] =?UTF-8?q?fix=20:=20Request,=20Response=20DTO=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactRequest.java | 6 ++-- .../mentoring/contact/ContactResponse.java | 8 ++--- .../contact/ContactRestController.java | 18 +++++----- .../mentoring/contact/ContactService.java | 34 +++++++++---------- .../java/com/example/demo/contactTest.java | 23 ++++++------- 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java index 974d7e09..2787de2f 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java @@ -10,14 +10,14 @@ public class ContactRequest { @Getter @Setter - public static class CreateDTO { + public static class ContactCreateDTO { private int mentorPostId; private int mentorId; private int menteeId; } @Getter @Setter - public static class RefuseDTO { + public static class ContactRefuseDTO { private int mentorPostId; private int mentorId; private List mentees; @@ -32,7 +32,7 @@ public MenteeDTO(int menteeId) { } @Getter @Setter - public static class AcceptDTO { + public static class ContactAcceptDTO { private int mentorPostId; private int mentorId; private List mentees; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index 74923a0c..3840a443 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -13,23 +13,23 @@ public class ContactResponse { @Getter @Setter - public static class postCountDTO { + public static class PostCountDTO { private int contactCount; private int doneCount; - public postCountDTO(int contactCount, int doneCount) { + public PostCountDTO(int contactCount, int doneCount) { this.contactCount = contactCount; this.doneCount = doneCount; } } @Getter @Setter - public static class MenteeContactDTO { + public static class ContactMenteeDTO { private int postId; private String title; private MentorDTO mentor; - public MenteeContactDTO(MentorPost mentorPost, MentorDTO mentor) { + public ContactMenteeDTO(MentorPost mentorPost, MentorDTO mentor) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.mentor = mentor; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 76b3ed48..a3e48660 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -23,7 +23,7 @@ public class ContactRestController { @Operation(summary = "contact 화면 조회", description = "멘토, 멘티 화면에 따라 적절한 화면을 보여준다.") public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { if ( userDetails.getUser().getRole() == Role.MENTEE ) { - List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); + List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); @@ -40,35 +40,35 @@ public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails u Role role = userDetails.getUser().getRole(); if ( role == Role.MENTEE ) { - ContactResponse.postCountDTO responseDTO = contactService.postCountsMyMentee(userDetails.getUser().getId()); + ContactResponse.PostCountDTO responseDTO = contactService.postCountsMyMentee(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - ContactResponse.postCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId()); + ContactResponse.PostCountDTO responseDTO = contactService.postCountsByMentor(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } @PostMapping(value = "/contacts/{id}/accept") @Operation(summary = "멘토링 신청 수락", description = "멘토링 신청을 수락한다.") - public ResponseEntity acceptContact(@PathVariable int id, @RequestBody @Valid ContactRequest.AcceptDTO acceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity acceptContact(@PathVariable int id, @RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 수락 API 로직 만들기 - contactService.acceptContact(id, acceptDTO, userDetails.getUser()); + contactService.acceptContact(id, contactAcceptDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } @PatchMapping(value = "/contacts/{id}/refuse") @Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.") - public ResponseEntity refuseContact(@PathVariable int id, @RequestBody @Valid ContactRequest.RefuseDTO refuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity refuseContact(@PathVariable int id, @RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 거절 API 로직 만들기 - contactService.refuseContact(id, refuseDTO, userDetails.getUser()); + contactService.refuseContact(id, contactRefuseDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } @PostMapping(value = "/contacts/{id}") @Operation(summary = "멘티의 멘토링 신청", description = "멘토가 작성한 글을 보고, 멘티는 멘토링 신청을 할 수 있다.") - public ResponseEntity createContact(@PathVariable int id, @RequestBody @Valid ContactRequest.CreateDTO createDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity createContact(@PathVariable int id, @RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 API 로직 만들기 - contactService.createContact(id, createDTO, userDetails.getUser()); + contactService.createContact(id, contactCreateDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 70dea5e9..36a8139c 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -33,7 +33,7 @@ public class ContactService { /** * contact - mentee 화면에서 mentor 가 작성한 글에 신청을 누른 게시글들을 가져오는 함수 * **/ - public List findAllByMentee(int userId) { + public List findAllByMentee(int userId) { return mentorPostJPARepository.findAllByMenteeUserId(userId).stream() .map(this::createMenteeContactDTO) @@ -41,14 +41,14 @@ public List findAllByMentee(int userId) { } // contact - mentee 부분 리팩토링 ( DTO 를 만드는 부분 ) - private ContactResponse.MenteeContactDTO createMenteeContactDTO(MentorPost mentorPost) { + private ContactResponse.ContactMenteeDTO createMenteeContactDTO(MentorPost mentorPost) { User mentorUser = userJPARepository.findById(mentorPost.getWriter().getId()) .orElseThrow(() -> new Exception400("해당 사용자가 존재하지 않습니다.")); List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); - return new ContactResponse.MenteeContactDTO(mentorPost, mentorDTO); + return new ContactResponse.ContactMenteeDTO(mentorPost, mentorDTO); } // --------------------------------------------------------------------------------------------- @@ -89,43 +89,43 @@ private ContactResponse.MenteeDTO createMenteeDTO(NotConnectedRegisterUser mente } // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 - public ContactResponse.postCountDTO postCountsByMentor(int userId) { + public ContactResponse.PostCountDTO postCountsByMentor(int userId) { // contact 화면에서 게시글을 조회 ( 나중에 where 조건에 state 를 달아야 함 ) int contactCount = mentorPostJPARepository.countContactByMentorId(userId); // done 화면에서 게시글을 조회 int doneCount = mentorPostJPARepository.countDoneByMentorId(userId); - return new ContactResponse.postCountDTO(contactCount, doneCount); + return new ContactResponse.PostCountDTO(contactCount, doneCount); } // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 ( 멘티 ) - public ContactResponse.postCountDTO postCountsMyMentee(int userId) { + public ContactResponse.PostCountDTO postCountsMyMentee(int userId) { // contact 화면에서 게시글을 조회 int contactCount = contactJPARepository.countContactByMenteeId(userId); // done 화면에서 게시글을 조회 int doneCount = doneJPARepository.countDoneByMenteeId(userId); - return new ContactResponse.postCountDTO(contactCount, doneCount); + return new ContactResponse.PostCountDTO(contactCount, doneCount); } @Transactional - public void acceptContact(int userId, ContactRequest.AcceptDTO acceptDTO, User user) { + public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcceptDTO, User user) { // 예외 처리 if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); } // user 체크 - if (userId != user.getId() || acceptDTO.getMentorId() != user.getId() ) { + if (userId != user.getId() || contactAcceptDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } - int mentorPostId = acceptDTO.getMentorPostId(); + int mentorPostId = contactAcceptDTO.getMentorPostId(); // 현재 멘토가 작성한 글인지 체크 MentorPost mentorPost = mentorPostJPARepository.findById(mentorPostId) .orElseThrow(() -> new Exception404("해당 게시글을 찾을 수 없습니다.")); // ConnectedUser 에 추가 - for ( ContactRequest.AcceptDTO.MenteeDTO menteeDTO : acceptDTO.getMentees() ) { + for ( ContactRequest.ContactAcceptDTO.MenteeDTO menteeDTO : contactAcceptDTO.getMentees() ) { // notConnectedRegisterUser 의 state 바꾸기 -> ACCEPT NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, menteeDTO.getMenteeId()) @@ -140,7 +140,7 @@ public void acceptContact(int userId, ContactRequest.AcceptDTO acceptDTO, User u } @Transactional - public void refuseContact(int userId, ContactRequest.RefuseDTO refuseDTO, User user) { + public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRefuseDTO, User user) { // 예외 처리 if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); @@ -150,15 +150,15 @@ public void refuseContact(int userId, ContactRequest.RefuseDTO refuseDTO, User u throw new Exception401("올바른 사용자가 아닙니다."); } - int mentorPostId = refuseDTO.getMentorPostId(); + int mentorPostId = contactRefuseDTO.getMentorPostId(); // 멘토와 현재 유저가 같은지 확인 - if ( refuseDTO.getMentorId() != user.getId() ) { + if ( contactRefuseDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } // notConnectedRegisterUser 의 state 바꾸기 -> REFUSE - for ( ContactRequest.RefuseDTO.MenteeDTO menteeDTO : refuseDTO.getMentees() ) { + for ( ContactRequest.ContactRefuseDTO.MenteeDTO menteeDTO : contactRefuseDTO.getMentees() ) { NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, menteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); @@ -168,7 +168,7 @@ public void refuseContact(int userId, ContactRequest.RefuseDTO refuseDTO, User u } @Transactional - public void createContact(int userId, ContactRequest.CreateDTO createDTO, User user) { + public void createContact(int userId, ContactRequest.ContactCreateDTO contactCreateDTO, User user) { // 예외 처리 if ( user.getRole() != Role.MENTEE ) { throw new Exception401("해당 사용자는 멘티가 아닙니다."); @@ -178,7 +178,7 @@ public void createContact(int userId, ContactRequest.CreateDTO createDTO, User u throw new Exception401("올바른 사용자가 아닙니다."); } - int mentorPostId = createDTO.getMentorPostId(); + int mentorPostId = contactCreateDTO.getMentorPostId(); // 현재 멘토가 작성한 글인지 체크 MentorPost mentorPost = mentorPostJPARepository.findById(mentorPostId) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 3fc80077..eb4ef0e1 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithUserDetails; import org.springframework.test.context.ActiveProfiles; @@ -121,12 +120,12 @@ void countByMenteeTest() throws Exception { @DisplayName("멘토 : 신청 거부 기능 테스트 코드") void contactRefuseTest() throws Exception { // given - ContactRequest.RefuseDTO requestDTOs = new ContactRequest.RefuseDTO(); + ContactRequest.ContactRefuseDTO requestDTOs = new ContactRequest.ContactRefuseDTO(); requestDTOs.setMentorPostId(1); requestDTOs.setMentorId(1); - List menteeDTOs = new ArrayList<>(); - menteeDTOs.add(new ContactRequest.RefuseDTO.MenteeDTO(3)); + List menteeDTOs = new ArrayList<>(); + menteeDTOs.add(new ContactRequest.ContactRefuseDTO.MenteeDTO(3)); requestDTOs.setMentees(menteeDTOs); @@ -160,13 +159,13 @@ void contactRefuseTest() throws Exception { @DisplayName("멘토 : 신청 수락 테스트 코드") void contactAccpetTest() throws Exception { // given - ContactRequest.AcceptDTO requestDTOs = new ContactRequest.AcceptDTO(); + ContactRequest.ContactAcceptDTO requestDTOs = new ContactRequest.ContactAcceptDTO(); requestDTOs.setMentorPostId(1); requestDTOs.setMentorId(1); - List menteeDTOs = new ArrayList<>(); - menteeDTOs.add(new ContactRequest.AcceptDTO.MenteeDTO(3)); + List menteeDTOs = new ArrayList<>(); + menteeDTOs.add(new ContactRequest.ContactAcceptDTO.MenteeDTO(3)); requestDTOs.setMentees(menteeDTOs); @@ -207,13 +206,13 @@ void contactAccpetTest() throws Exception { @DisplayName("멘티 : 신청 생성 테스트 코드") void createTest() throws Exception { // given - ContactRequest.CreateDTO createDTO = new ContactRequest.CreateDTO(); + ContactRequest.ContactCreateDTO contactCreateDTO = new ContactRequest.ContactCreateDTO(); // mentor, mentorPost, mentee id 지정 - createDTO.setMentorPostId(3); - createDTO.setMentorId(2); - createDTO.setMenteeId(4); + contactCreateDTO.setMentorPostId(3); + contactCreateDTO.setMentorId(2); + contactCreateDTO.setMenteeId(4); - String requestBody = om.writeValueAsString(createDTO); + String requestBody = om.writeValueAsString(contactCreateDTO); System.out.println("테스트 requestBody : "+requestBody); From 307efbb099516d9031e2bda163d61c418a0ae78f Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 22:39:14 +0900 Subject: [PATCH 26/84] =?UTF-8?q?fix=20:=20DTO=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EC=97=90=20=EC=9D=98=ED=95=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactRequest.java | 12 +++---- .../mentoring/contact/ContactResponse.java | 22 ++++++------- .../contact/ContactRestController.java | 4 +-- .../mentoring/contact/ContactService.java | 32 +++++++++---------- .../java/com/example/demo/contactTest.java | 12 +++---- 5 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java index 2787de2f..51cb056c 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java @@ -20,12 +20,12 @@ public static class ContactCreateDTO { public static class ContactRefuseDTO { private int mentorPostId; private int mentorId; - private List mentees; + private List mentees; @Getter @Setter @NoArgsConstructor - public static class MenteeDTO { + public static class RefuseMenteeDTO { @NotNull private int menteeId; - public MenteeDTO(int menteeId) { + public RefuseMenteeDTO(int menteeId) { this.menteeId = menteeId; } } @@ -35,12 +35,12 @@ public MenteeDTO(int menteeId) { public static class ContactAcceptDTO { private int mentorPostId; private int mentorId; - private List mentees; + private List mentees; @Getter @Setter @NoArgsConstructor - public static class MenteeDTO { + public static class AcceptMenteeDTO { @NotNull private int menteeId; - public MenteeDTO(int menteeId) { + public AcceptMenteeDTO(int menteeId) { this.menteeId = menteeId; } } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index 3840a443..cf3de475 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -24,12 +24,12 @@ public PostCountDTO(int contactCount, int doneCount) { } @Getter @Setter - public static class ContactMenteeDTO { + public static class ContactDashBoardMenteeDTO { private int postId; private String title; - private MentorDTO mentor; + private ContactMentorDTO mentor; - public ContactMenteeDTO(MentorPost mentorPost, MentorDTO mentor) { + public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.mentor = mentor; @@ -45,13 +45,13 @@ public ContactMenteeDTO(MentorPost mentorPost, MentorDTO mentor) { * * **/ @Getter @Setter - public static class MentorPostDTO { + public static class ContactMentorPostDTO { private int postId; private String title; - private MentorDTO mentor; - private List mentees; + private ContactMentorDTO mentor; + private List mentees; - public MentorPostDTO(MentorPost mentorPost, MentorDTO mentor, List mentees) { + public ContactMentorPostDTO(MentorPost mentorPost, ContactMentorDTO mentor, List mentees) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.mentor = mentor; @@ -60,7 +60,7 @@ public MentorPostDTO(MentorPost mentorPost, MentorDTO mentor, List me } @Getter @Setter - public static class MentorDTO { + public static class ContactMentorDTO { private int mentorId; private String profileImage; private String name; @@ -69,7 +69,7 @@ public static class MentorDTO { private Role role; private List favorites; - public MentorDTO(User user, List userInterests) { + public ContactMentorDTO(User user, List userInterests) { this.mentorId = user.getId(); this.profileImage = user.getProfileImage(); this.name = user.getFirstName() + " " + user.getLastName(); @@ -83,7 +83,7 @@ public MentorDTO(User user, List userInterests) { } } @Getter @Setter - public static class MenteeDTO { + public static class ContactMenteeDTO { private int menteeId; private String profileImage; private String name; @@ -100,7 +100,7 @@ public static class MenteeDTO { * 그럴 경우에만 tag 값들을 가져오기 * **/ - public MenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { + public ContactMenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { this.menteeId = notConnectedRegisterUser.getMenteeUser().getId(); this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage(); this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName(); diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index a3e48660..27e59a04 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -23,10 +23,10 @@ public class ContactRestController { @Operation(summary = "contact 화면 조회", description = "멘토, 멘티 화면에 따라 적절한 화면을 보여준다.") public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { if ( userDetails.getUser().getRole() == Role.MENTEE ) { - List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); + List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); + List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 36a8139c..043961b4 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -33,7 +33,7 @@ public class ContactService { /** * contact - mentee 화면에서 mentor 가 작성한 글에 신청을 누른 게시글들을 가져오는 함수 * **/ - public List findAllByMentee(int userId) { + public List findAllByMentee(int userId) { return mentorPostJPARepository.findAllByMenteeUserId(userId).stream() .map(this::createMenteeContactDTO) @@ -41,14 +41,14 @@ public List findAllByMentee(int userId) { } // contact - mentee 부분 리팩토링 ( DTO 를 만드는 부분 ) - private ContactResponse.ContactMenteeDTO createMenteeContactDTO(MentorPost mentorPost) { + private ContactResponse.ContactDashBoardMenteeDTO createMenteeContactDTO(MentorPost mentorPost) { User mentorUser = userJPARepository.findById(mentorPost.getWriter().getId()) .orElseThrow(() -> new Exception400("해당 사용자가 존재하지 않습니다.")); List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); - ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); + ContactResponse.ContactMentorDTO contactMentorDTO = new ContactResponse.ContactMentorDTO(mentorUser, mentorInterests); - return new ContactResponse.ContactMenteeDTO(mentorPost, mentorDTO); + return new ContactResponse.ContactDashBoardMenteeDTO(mentorPost, contactMentorDTO); } // --------------------------------------------------------------------------------------------- @@ -56,36 +56,36 @@ private ContactResponse.ContactMenteeDTO createMenteeContactDTO(MentorPost mento /** * contact - mentor 화면에서 post 와 mentee 간 엮인 정보들을 조회해서 가져오는 함수 * **/ - public List findAllByMentor(int userId) { + public List findAllByMentor(int userId) { User mentorUser = userJPARepository.findById(userId) .orElseThrow(() -> new Exception404("해당 사용자가 존재하지 않습니다.")); List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); - ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); + ContactResponse.ContactMentorDTO contactMentorDTO = new ContactResponse.ContactMentorDTO(mentorUser, mentorInterests); return mentorPostJPARepository.findAllByWriter(userId).stream() - .map(mentorPost -> createMentorPostDTO(mentorPost, mentorDTO)) + .map(mentorPost -> createMentorPostDTO(mentorPost, contactMentorDTO)) .collect(Collectors.toList()); } // MentorPostDTO 생성 로직 - private ContactResponse.MentorPostDTO createMentorPostDTO(MentorPost mentorPost, ContactResponse.MentorDTO mentorDTO) { - List menteeDTOs = contactJPARepository.findAllByMentorPostId(mentorPost.getId()) + private ContactResponse.ContactMentorPostDTO createMentorPostDTO(MentorPost mentorPost, ContactResponse.ContactMentorDTO contactMentorDTO) { + List contactMenteeDTOS = contactJPARepository.findAllByMentorPostId(mentorPost.getId()) .stream() .map(this::createMenteeDTO) .collect(Collectors.toList()); - return new ContactResponse.MentorPostDTO(mentorPost, mentorDTO, menteeDTOs); + return new ContactResponse.ContactMentorPostDTO(mentorPost, contactMentorDTO, contactMenteeDTOS); } // 매핑 로직 분리 ( menteeDTO 생성 로직 ) - private ContactResponse.MenteeDTO createMenteeDTO(NotConnectedRegisterUser mentee) { + private ContactResponse.ContactMenteeDTO createMenteeDTO(NotConnectedRegisterUser mentee) { List menteeInterests = userInterestJPARepository .findAllById(mentee.getMenteeUser().getId()); - return new ContactResponse.MenteeDTO(mentee, menteeInterests); + return new ContactResponse.ContactMenteeDTO(mentee, menteeInterests); } // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 @@ -125,10 +125,10 @@ public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcc .orElseThrow(() -> new Exception404("해당 게시글을 찾을 수 없습니다.")); // ConnectedUser 에 추가 - for ( ContactRequest.ContactAcceptDTO.MenteeDTO menteeDTO : contactAcceptDTO.getMentees() ) { + for ( ContactRequest.ContactAcceptDTO.AcceptMenteeDTO acceptMenteeDTO : contactAcceptDTO.getMentees() ) { // notConnectedRegisterUser 의 state 바꾸기 -> ACCEPT - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, menteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, acceptMenteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.ACCEPT); @@ -158,9 +158,9 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef } // notConnectedRegisterUser 의 state 바꾸기 -> REFUSE - for ( ContactRequest.ContactRefuseDTO.MenteeDTO menteeDTO : contactRefuseDTO.getMentees() ) { + for ( ContactRequest.ContactRefuseDTO.RefuseMenteeDTO refuseMenteeDTO : contactRefuseDTO.getMentees() ) { - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, menteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, refuseMenteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.REFUSE); diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index eb4ef0e1..ade42838 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -124,10 +124,10 @@ void contactRefuseTest() throws Exception { requestDTOs.setMentorPostId(1); requestDTOs.setMentorId(1); - List menteeDTOs = new ArrayList<>(); - menteeDTOs.add(new ContactRequest.ContactRefuseDTO.MenteeDTO(3)); + List refuseMenteeDTOS = new ArrayList<>(); + refuseMenteeDTOS.add(new ContactRequest.ContactRefuseDTO.RefuseMenteeDTO(3)); - requestDTOs.setMentees(menteeDTOs); + requestDTOs.setMentees(refuseMenteeDTOS); String requestBody = om.writeValueAsString(requestDTOs); @@ -164,10 +164,10 @@ void contactAccpetTest() throws Exception { requestDTOs.setMentorPostId(1); requestDTOs.setMentorId(1); - List menteeDTOs = new ArrayList<>(); - menteeDTOs.add(new ContactRequest.ContactAcceptDTO.MenteeDTO(3)); + List acceptMenteeDTOS = new ArrayList<>(); + acceptMenteeDTOS.add(new ContactRequest.ContactAcceptDTO.AcceptMenteeDTO(3)); - requestDTOs.setMentees(menteeDTOs); + requestDTOs.setMentees(acceptMenteeDTOS); String requestBody = om.writeValueAsString(requestDTOs); From 5b66af81bbd18963aaa126bc31bbb8900c147656 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Sun, 29 Oct 2023 22:41:51 +0900 Subject: [PATCH 27/84] =?UTF-8?q?fix=20:=20DTO=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../com/example/demo/mentoring/contact/ContactResponse.java | 4 ++-- .../demo/mentoring/contact/ContactRestController.java | 2 +- .../com/example/demo/mentoring/contact/ContactService.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index cf3de475..3910c199 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -45,13 +45,13 @@ public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor) * * **/ @Getter @Setter - public static class ContactMentorPostDTO { + public static class ContactDashboardMentorDTO { private int postId; private String title; private ContactMentorDTO mentor; private List mentees; - public ContactMentorPostDTO(MentorPost mentorPost, ContactMentorDTO mentor, List mentees) { + public ContactDashboardMentorDTO(MentorPost mentorPost, ContactMentorDTO mentor, List mentees) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.mentor = mentor; diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 27e59a04..77ae2ea4 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -26,7 +26,7 @@ public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails user List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); + List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 043961b4..ce745aac 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -56,7 +56,7 @@ private ContactResponse.ContactDashBoardMenteeDTO createMenteeContactDTO(MentorP /** * contact - mentor 화면에서 post 와 mentee 간 엮인 정보들을 조회해서 가져오는 함수 * **/ - public List findAllByMentor(int userId) { + public List findAllByMentor(int userId) { User mentorUser = userJPARepository.findById(userId) .orElseThrow(() -> new Exception404("해당 사용자가 존재하지 않습니다.")); @@ -70,13 +70,13 @@ public List findAllByMentor(int userId) { } // MentorPostDTO 생성 로직 - private ContactResponse.ContactMentorPostDTO createMentorPostDTO(MentorPost mentorPost, ContactResponse.ContactMentorDTO contactMentorDTO) { + private ContactResponse.ContactDashboardMentorDTO createMentorPostDTO(MentorPost mentorPost, ContactResponse.ContactMentorDTO contactMentorDTO) { List contactMenteeDTOS = contactJPARepository.findAllByMentorPostId(mentorPost.getId()) .stream() .map(this::createMenteeDTO) .collect(Collectors.toList()); - return new ContactResponse.ContactMentorPostDTO(mentorPost, contactMentorDTO, contactMenteeDTOS); + return new ContactResponse.ContactDashboardMentorDTO(mentorPost, contactMentorDTO, contactMenteeDTOS); } // 매핑 로직 분리 ( menteeDTO 생성 로직 ) From 431047d37d64c46222bc37ec5ebb8471c8b117b2 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 22:49:51 +0900 Subject: [PATCH 28/84] =?UTF-8?q?fix=20:=20contact=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/MentorPostJPARepostiory.java | 2 - .../demo/mentoring/MentorPostService.java | 3 + .../contact/ContactJPARepository.java | 8 +++ .../mentoring/contact/ContactResponse.java | 22 ++++--- .../contact/ContactRestController.java | 28 ++++---- .../mentoring/contact/ContactService.java | 65 +++++++------------ 6 files changed, 60 insertions(+), 68 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index 5f5aad56..1d450ca0 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -32,6 +32,4 @@ public interface MentorPostJPARepostiory extends JpaRepository findAllByMenteeUserId(@Param("menteeUserId") int menteeUserId); } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index 774f9f6e..0f01bb25 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -38,8 +38,11 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) if(createDTO.getContent().length() > 300){ throw new Exception404("글자수가 300자를 넘어갑니다."); } + System.out.println("writer id" + writer.getId()); + System.out.println("writer email" + writer.getEmail()); MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent()); + try { mentorPostJPARepository.save(mentorPost); } catch (Exception e) { diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java b/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java index 35080934..a6a4d29c 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactJPARepository.java @@ -1,9 +1,11 @@ package com.example.demo.mentoring.contact; +import com.example.demo.mentoring.MentorPost; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.Collection; import java.util.List; import java.util.Optional; @@ -17,4 +19,10 @@ public interface ContactJPARepository extends JpaRepository findAllByMenteeId(int menteeId); + + @Query("SELECT ncru FROM NotConnectedRegisterUser ncru WHERE ncru.mentorPost.writer.id = :mentorId") + List findAllByMentorId(int mentorId); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index 3910c199..521b58d4 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -28,11 +28,13 @@ public static class ContactDashBoardMenteeDTO { private int postId; private String title; private ContactMentorDTO mentor; + private int menteeId; - public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor) { + public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor, NotConnectedRegisterUser notConnectedRegisterUser) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.mentor = mentor; + this.menteeId = notConnectedRegisterUser.getId(); } } /** @@ -69,15 +71,15 @@ public static class ContactMentorDTO { private Role role; private List favorites; - public ContactMentorDTO(User user, List userInterests) { - this.mentorId = user.getId(); - this.profileImage = user.getProfileImage(); - this.name = user.getFirstName() + " " + user.getLastName(); - this.country = user.getCountry(); - this.age = user.getAge(); - this.role = user.getRole(); + public ContactMentorDTO(User mentor, List userInterests) { + this.mentorId = mentor.getId(); + this.profileImage = mentor.getProfileImage(); + this.name = mentor.getFirstName() + " " + mentor.getLastName(); + this.country = mentor.getCountry(); + this.age = mentor.getAge(); + this.role = mentor.getRole(); this.favorites = userInterests.stream() - .filter(userInterest -> userInterest.getUser().getId() == user.getId()) + .filter(userInterest -> userInterest.getUser().getId() == mentor.getId()) .map(userInterest -> userInterest.getInterest().getCategory()) .collect(Collectors.toList()); } @@ -101,7 +103,7 @@ public static class ContactMenteeDTO { * **/ public ContactMenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { - this.menteeId = notConnectedRegisterUser.getMenteeUser().getId(); + this.menteeId = notConnectedRegisterUser.getId(); this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage(); this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName(); this.country = notConnectedRegisterUser.getMenteeUser().getCountry(); diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 77ae2ea4..29ba82ab 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -23,10 +23,10 @@ public class ContactRestController { @Operation(summary = "contact 화면 조회", description = "멘토, 멘티 화면에 따라 적절한 화면을 보여준다.") public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { if ( userDetails.getUser().getRole() == Role.MENTEE ) { - List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); + List responseDTO = contactService.findAllByMentee(userDetails.getUser()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); + List responseDTO = contactService.findAllByMentor(userDetails.getUser()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } @@ -48,35 +48,35 @@ public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails u return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - @PostMapping(value = "/contacts/{id}/accept") + @PostMapping(value = "/contacts/{userId}/accept") @Operation(summary = "멘토링 신청 수락", description = "멘토링 신청을 수락한다.") - public ResponseEntity acceptContact(@PathVariable int id, @RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity acceptContact(@PathVariable int userId, @RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 수락 API 로직 만들기 - contactService.acceptContact(id, contactAcceptDTO, userDetails.getUser()); + contactService.acceptContact(userId, contactAcceptDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @PatchMapping(value = "/contacts/{id}/refuse") + @PatchMapping(value = "/contacts/{userId}/refuse") @Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.") - public ResponseEntity refuseContact(@PathVariable int id, @RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity refuseContact(@PathVariable int userId, @RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 거절 API 로직 만들기 - contactService.refuseContact(id, contactRefuseDTO, userDetails.getUser()); + contactService.refuseContact(userId, contactRefuseDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @PostMapping(value = "/contacts/{id}") + @PostMapping(value = "/contacts/{userId}") @Operation(summary = "멘티의 멘토링 신청", description = "멘토가 작성한 글을 보고, 멘티는 멘토링 신청을 할 수 있다.") - public ResponseEntity createContact(@PathVariable int id, @RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity createContact(@PathVariable int userId, @RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 API 로직 만들기 - contactService.createContact(id, contactCreateDTO, userDetails.getUser()); + contactService.createContact(userId, contactCreateDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @DeleteMapping(value = "/contacts/{id}") + @DeleteMapping(value = "/contacts/{contactId}") @Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.") - public ResponseEntity deleteContact(@PathVariable int id, @RequestParam("mentorPostId") int mentorPostId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity deleteContact(@PathVariable int contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 취소 API 로직 만들기 - contactService.deleteContact(id, mentorPostId, userDetails.getUser()); + contactService.deleteContact(contactId, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index ce745aac..1be187a6 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -33,22 +33,21 @@ public class ContactService { /** * contact - mentee 화면에서 mentor 가 작성한 글에 신청을 누른 게시글들을 가져오는 함수 * **/ - public List findAllByMentee(int userId) { + public List findAllByMentee(User mentee) { - return mentorPostJPARepository.findAllByMenteeUserId(userId).stream() - .map(this::createMenteeContactDTO) + return contactJPARepository.findAllByMenteeId(mentee.getId()).stream() + .map(notConnectedRegisterUser -> createMenteeContactDTO(notConnectedRegisterUser.getMentorPost(), notConnectedRegisterUser)) .collect(Collectors.toList()); } // contact - mentee 부분 리팩토링 ( DTO 를 만드는 부분 ) - private ContactResponse.ContactDashBoardMenteeDTO createMenteeContactDTO(MentorPost mentorPost) { - User mentorUser = userJPARepository.findById(mentorPost.getWriter().getId()) - .orElseThrow(() -> new Exception400("해당 사용자가 존재하지 않습니다.")); - List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); + private ContactResponse.ContactDashBoardMenteeDTO createMenteeContactDTO(MentorPost mentorPost, NotConnectedRegisterUser mentee) { - ContactResponse.ContactMentorDTO contactMentorDTO = new ContactResponse.ContactMentorDTO(mentorUser, mentorInterests); + List mentorInterests = userInterestJPARepository.findAllById(mentee.getMenteeUser().getId()); - return new ContactResponse.ContactDashBoardMenteeDTO(mentorPost, contactMentorDTO); + ContactResponse.ContactMentorDTO contactMentorDTO = new ContactResponse.ContactMentorDTO(mentee.getMenteeUser(), mentorInterests); + + return new ContactResponse.ContactDashBoardMenteeDTO(mentorPost, contactMentorDTO, mentee); } // --------------------------------------------------------------------------------------------- @@ -56,14 +55,11 @@ private ContactResponse.ContactDashBoardMenteeDTO createMenteeContactDTO(MentorP /** * contact - mentor 화면에서 post 와 mentee 간 엮인 정보들을 조회해서 가져오는 함수 * **/ - public List findAllByMentor(int userId) { - - User mentorUser = userJPARepository.findById(userId) - .orElseThrow(() -> new Exception404("해당 사용자가 존재하지 않습니다.")); - List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); - ContactResponse.ContactMentorDTO contactMentorDTO = new ContactResponse.ContactMentorDTO(mentorUser, mentorInterests); + public List findAllByMentor(User mentor) { + List mentorInterests = userInterestJPARepository.findAllById(mentor.getId()); + ContactResponse.ContactMentorDTO contactMentorDTO = new ContactResponse.ContactMentorDTO(mentor, mentorInterests); - return mentorPostJPARepository.findAllByWriter(userId).stream() + return mentorPostJPARepository.findAllByWriter(mentor.getId()).stream() .map(mentorPost -> createMentorPostDTO(mentorPost, contactMentorDTO)) .collect(Collectors.toList()); @@ -128,7 +124,7 @@ public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcc for ( ContactRequest.ContactAcceptDTO.AcceptMenteeDTO acceptMenteeDTO : contactAcceptDTO.getMentees() ) { // notConnectedRegisterUser 의 state 바꾸기 -> ACCEPT - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, acceptMenteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(acceptMenteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.ACCEPT); @@ -145,13 +141,9 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); } - if (userId != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } - - int mentorPostId = contactRefuseDTO.getMentorPostId(); - // 멘토와 현재 유저가 같은지 확인 if ( contactRefuseDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); @@ -160,7 +152,7 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef // notConnectedRegisterUser 의 state 바꾸기 -> REFUSE for ( ContactRequest.ContactRefuseDTO.RefuseMenteeDTO refuseMenteeDTO : contactRefuseDTO.getMentees() ) { - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, refuseMenteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(refuseMenteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.REFUSE); @@ -168,13 +160,13 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef } @Transactional - public void createContact(int userId, ContactRequest.ContactCreateDTO contactCreateDTO, User user) { + public void createContact(int userId, ContactRequest.ContactCreateDTO contactCreateDTO, User mentee) { // 예외 처리 - if ( user.getRole() != Role.MENTEE ) { + if ( mentee.getRole() != Role.MENTEE ) { throw new Exception401("해당 사용자는 멘티가 아닙니다."); } - if (userId != user.getId() ) { + if (userId != mentee.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -184,31 +176,20 @@ public void createContact(int userId, ContactRequest.ContactCreateDTO contactCre MentorPost mentorPost = mentorPostJPARepository.findById(mentorPostId) .orElseThrow(() -> new Exception404("해당 게시글을 찾을 수 없습니다.")); - // 이미 신청한 글인지 체크하기 - if ( contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, userId).isPresent() ) { - throw new Exception401("이미 신청한 글입니다."); - } - // notConnectedRegisterUser 에 save 하기 - contactJPARepository.save(new NotConnectedRegisterUser(mentorPost, user, NotConnectedRegisterUser.State.AWAIT)); + contactJPARepository.save(new NotConnectedRegisterUser(mentorPost, mentee, NotConnectedRegisterUser.State.AWAIT)); } @Transactional - public void deleteContact(int userId, int mentorPostId, User user) { + public void deleteContact(int contactId, User mentee) { + // 해당하는 NotConnectedRegisterUser 가져오기 + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(contactId) + .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다." )); // 예외 처리 - if ( user.getRole() != Role.MENTEE ) { + if ( mentee.getRole() != Role.MENTEE || notConnectedRegisterUser.getMenteeUser().getId() != mentee.getId() ) { throw new Exception401("해당 사용자는 멘티가 아닙니다."); } - - // 현재 유저와 userId 값이 일치하는지 확인 - if ( user.getId() != userId ) { - throw new Exception401("올바른 사용자가 아닙니다."); - } - // 해당하는 NotConnectedRegisterUser 가져오기 - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findByMentorPostIdAndMenteeUserId(mentorPostId, userId) - .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다." )); - // notConnectedRegisterUser delete 요청 보내기 contactJPARepository.deleteById(notConnectedRegisterUser.getId()); } From 7801dbd6e65a9d9d9707958625af456344592976 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 22:50:14 +0900 Subject: [PATCH 29/84] =?UTF-8?q?test=20:=20=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81=20=ED=9B=84=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- src/test/java/com/example/demo/contactTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index ade42838..68f5785d 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -125,7 +125,7 @@ void contactRefuseTest() throws Exception { requestDTOs.setMentorId(1); List refuseMenteeDTOS = new ArrayList<>(); - refuseMenteeDTOS.add(new ContactRequest.ContactRefuseDTO.RefuseMenteeDTO(3)); + refuseMenteeDTOS.add(new ContactRequest.ContactRefuseDTO.RefuseMenteeDTO(1)); requestDTOs.setMentees(refuseMenteeDTOS); @@ -165,7 +165,7 @@ void contactAccpetTest() throws Exception { requestDTOs.setMentorId(1); List acceptMenteeDTOS = new ArrayList<>(); - acceptMenteeDTOS.add(new ContactRequest.ContactAcceptDTO.AcceptMenteeDTO(3)); + acceptMenteeDTOS.add(new ContactRequest.ContactAcceptDTO.AcceptMenteeDTO(1)); requestDTOs.setMentees(acceptMenteeDTOS); @@ -242,13 +242,11 @@ void createTest() throws Exception { @DisplayName("멘티 : 신청 취소 테스트 코드") void deleteTest() throws Exception { // given - int id = 3; - int mentorPostId = 1; + int id = 1; // when ResultActions result = mvc.perform( MockMvcRequestBuilders.delete("/contacts/" + id) - .param("mentorPostId", String.valueOf(mentorPostId)) .contentType(MediaType.APPLICATION_JSON) ); String responseBody = result.andReturn().getResponse().getContentAsString(); From 481a33e25b2805ef3fcf212b7501b13e3f4908fe Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 22:53:25 +0900 Subject: [PATCH 30/84] =?UTF-8?q?fix=20:=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=ED=95=A0=20=EB=95=8C=20=EC=9E=91=EC=84=B1=ED=96=88=EB=8D=98=20?= =?UTF-8?q?print=EB=AC=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- src/main/java/com/example/demo/mentoring/MentorPostService.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index 0f01bb25..39a486ca 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -38,8 +38,6 @@ public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) if(createDTO.getContent().length() > 300){ throw new Exception404("글자수가 300자를 넘어갑니다."); } - System.out.println("writer id" + writer.getId()); - System.out.println("writer email" + writer.getEmail()); MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent()); From e18b69e171140bd01fb98c1314b2f2ce936abd3c Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 23:26:30 +0900 Subject: [PATCH 31/84] =?UTF-8?q?feat=20:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactService.java | 53 ++++++++++++------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 1be187a6..62d51f51 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -25,7 +25,6 @@ public class ContactService { private final MentorPostJPARepostiory mentorPostJPARepository; - private final UserJPARepository userJPARepository; private final ContactJPARepository contactJPARepository; private final UserInterestJPARepository userInterestJPARepository; private final DoneJPARepository doneJPARepository; @@ -105,12 +104,10 @@ public ContactResponse.PostCountDTO postCountsMyMentee(int userId) { @Transactional public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcceptDTO, User user) { - // 예외 처리 - if ( user.getRole() != Role.MENTOR ) { - throw new Exception401("해당 사용자는 멘토가 아닙니다."); - } - // user 체크 - if (userId != user.getId() || contactAcceptDTO.getMentorId() != user.getId() ) { + isMentor(userId, user); + + // dto 예외 처리 + if ( contactAcceptDTO.getMentorId() != userId ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -138,14 +135,10 @@ public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcc @Transactional public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRefuseDTO, User user) { // 예외 처리 - if ( user.getRole() != Role.MENTOR ) { - throw new Exception401("해당 사용자는 멘토가 아닙니다."); - } - if (userId != user.getId() ) { - throw new Exception401("올바른 사용자가 아닙니다."); - } - // 멘토와 현재 유저가 같은지 확인 - if ( contactRefuseDTO.getMentorId() != user.getId() ) { + isMentor(userId, user); + + // dto 예외 처리 + if ( contactRefuseDTO.getMentorId() != userId ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -162,9 +155,7 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef @Transactional public void createContact(int userId, ContactRequest.ContactCreateDTO contactCreateDTO, User mentee) { // 예외 처리 - if ( mentee.getRole() != Role.MENTEE ) { - throw new Exception401("해당 사용자는 멘티가 아닙니다."); - } + isMentee(mentee); if (userId != mentee.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); @@ -183,14 +174,36 @@ public void createContact(int userId, ContactRequest.ContactCreateDTO contactCre @Transactional public void deleteContact(int contactId, User mentee) { + // 해당하는 NotConnectedRegisterUser 가져오기 NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(contactId) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다." )); // 예외 처리 - if ( mentee.getRole() != Role.MENTEE || notConnectedRegisterUser.getMenteeUser().getId() != mentee.getId() ) { - throw new Exception401("해당 사용자는 멘티가 아닙니다."); + isMentee(mentee); + + if ( notConnectedRegisterUser.getMenteeUser().getId() != mentee.getId() ) { + throw new Exception401("올바른 사용자가 아닙니다."); } // notConnectedRegisterUser delete 요청 보내기 contactJPARepository.deleteById(notConnectedRegisterUser.getId()); } + + // 멘토 인증을 위한 메소드 + private void isMentor(int userId, User user) { + // 예외 처리 + if ( user.getRole() != Role.MENTOR ) { + throw new Exception401("해당 사용자는 멘토가 아닙니다."); + } + // user 체크 + if (userId != user.getId() ) { + throw new Exception401("올바른 사용자가 아닙니다."); + } + } + + // 멘티 인증을 위한 메소드 + private void isMentee(User mentee) { + if ( mentee.getRole() != Role.MENTEE ) { + throw new Exception401("해당 사용자는 멘티가 아닙니다."); + } + } } From dee658a4baae7511df782c98800e748dfe314d84 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 23:33:57 +0900 Subject: [PATCH 32/84] =?UTF-8?q?feat=20:=20NotConnectedRegisterUser=20?= =?UTF-8?q?=EC=9D=B8=EB=8D=B1=EC=8B=B1=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../demo/mentoring/contact/NotConnectedRegisterUser.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java index 1a191d2d..3759b40b 100644 --- a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java +++ b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java @@ -17,7 +17,14 @@ @Entity @Where(clause = "deleted_at IS NULL") @SQLDelete(sql = "UPDATE not_connected_register_users SET deleted_at = CURRENT_TIMESTAMP, is_deleted = TRUE where id = ?") -@Table(name = "not_connected_register_users") +@Table(name = "not_connected_register_users", + indexes = { + @Index(name = "not_connected_register_users_mentor_post_id_idx", columnList = "mentor_post_id"), + @Index(name = "not_connected_register_users_mentee_user_id_idx", columnList = "mentee_user_id") + }, + uniqueConstraints = { + @UniqueConstraint(name = "uk_not_connected_register_user_mentor_post_mentee_user", columnNames = {"mentor_post_id", "mentee_user_id"}) + }) public class NotConnectedRegisterUser extends BaseTime { @Id From 26bfcbabfa3c56116fdbe8515d5cda9312587d0a Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 23:45:27 +0900 Subject: [PATCH 33/84] =?UTF-8?q?feat=20:=20AttributeConverter=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactResponse.java | 2 +- .../mentoring/contact/ContactService.java | 6 ++-- .../contact/ContactStateConverter.java | 20 ++++++++++++ .../mentoring/contact/ContactStateEnum.java | 32 +++++++++++++++++++ .../contact/NotConnectedRegisterUser.java | 15 ++++----- 5 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/example/demo/mentoring/contact/ContactStateConverter.java create mode 100644 src/main/java/com/example/demo/mentoring/contact/ContactStateEnum.java diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index 521b58d4..e9aced68 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -92,7 +92,7 @@ public static class ContactMenteeDTO { private String country; private int age; private Role role; - private NotConnectedRegisterUser.State state; + private ContactStateEnum state; private List favorites; // 고민할 부분 : 유저의 favorite List 를 어떻게 가져올 것 인가? /** diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 62d51f51..e40bec9e 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -124,7 +124,7 @@ public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcc NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(acceptMenteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); - notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.ACCEPT); + notConnectedRegisterUser.updateStatus(ContactStateEnum.ACCEPT); // ConnectedUser 에 save 하기 doneJPARepository.save(new ConnectedUser(mentorPost, notConnectedRegisterUser.getMenteeUser())); @@ -148,7 +148,7 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(refuseMenteeDTO.getMenteeId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); - notConnectedRegisterUser.updateStatus(NotConnectedRegisterUser.State.REFUSE); + notConnectedRegisterUser.updateStatus(ContactStateEnum.REFUSE); } } @@ -168,7 +168,7 @@ public void createContact(int userId, ContactRequest.ContactCreateDTO contactCre .orElseThrow(() -> new Exception404("해당 게시글을 찾을 수 없습니다.")); // notConnectedRegisterUser 에 save 하기 - contactJPARepository.save(new NotConnectedRegisterUser(mentorPost, mentee, NotConnectedRegisterUser.State.AWAIT)); + contactJPARepository.save(new NotConnectedRegisterUser(mentorPost, mentee, ContactStateEnum.AWAIT)); } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactStateConverter.java b/src/main/java/com/example/demo/mentoring/contact/ContactStateConverter.java new file mode 100644 index 00000000..205a995f --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/contact/ContactStateConverter.java @@ -0,0 +1,20 @@ +package com.example.demo.mentoring.contact; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import javax.persistence.AttributeConverter; + +@RequiredArgsConstructor +@Component +public class ContactStateConverter implements AttributeConverter { + @Override + public String convertToDatabaseColumn(ContactStateEnum attribute) { + return attribute.getValue(); + } + + @Override + public ContactStateEnum convertToEntityAttribute(String dbData) { + return ContactStateEnum.findOf(dbData); + } +} diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactStateEnum.java b/src/main/java/com/example/demo/mentoring/contact/ContactStateEnum.java new file mode 100644 index 00000000..7a34e35e --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/contact/ContactStateEnum.java @@ -0,0 +1,32 @@ +package com.example.demo.mentoring.contact; + +import com.example.demo.mentoring.MentorPostStateEnum; +import io.swagger.models.Contact; +import lombok.Getter; + +import java.util.Collections; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +public enum ContactStateEnum { + ACCEPT("ACCEPT", "ACCEPT"), + REFUSE("REFUSE", "REFUSE"), + AWAIT("AWAIT", "AWAIT"); + + private final String desc; + private final String value; + + ContactStateEnum(String desc, String value) { + this.desc = desc; + this.value = value; + } + + private static final Map descriptions = Collections.unmodifiableMap(Stream.of(values()).collect(Collectors.toMap(ContactStateEnum::getValue, Function.identity()))); + + public static ContactStateEnum findOf(String findValue) { + return descriptions.get(findValue); + } +} diff --git a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java index 3759b40b..e76c4b98 100644 --- a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java +++ b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java @@ -2,6 +2,7 @@ import com.example.demo.config.utils.BaseTime; import com.example.demo.mentoring.MentorPost; +import com.example.demo.mentoring.MentorPostStateConverter; import com.example.demo.user.User; import lombok.AccessLevel; import lombok.Builder; @@ -37,20 +38,16 @@ public class NotConnectedRegisterUser extends BaseTime { @ManyToOne(fetch = FetchType.LAZY) private User menteeUser; - @Column(nullable = false) - @Enumerated(value = EnumType.STRING) - private State state; + @Convert(converter = ContactStateConverter.class) + @Column(name = "state", nullable = false) + private ContactStateEnum state; - public void updateStatus(State state) { + public void updateStatus(ContactStateEnum state) { this.state = state; } - public enum State { - ACCEPT, REFUSE, AWAIT - } - @Builder - public NotConnectedRegisterUser(MentorPost mentorPost, User menteeUser, State state) { + public NotConnectedRegisterUser(MentorPost mentorPost, User menteeUser, ContactStateEnum state) { this.mentorPost = mentorPost; this.menteeUser = menteeUser; this.state = state; From 5724d425bec5c2311646f2e2946005786e08d336 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 2 Nov 2023 23:45:34 +0900 Subject: [PATCH 34/84] =?UTF-8?q?test=20:=20AttributeConverter=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/example/demo/contactTest.java | 6 +++--- .../java/com/example/demo/mentoringtest/MentoringTest.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 68f5785d..22ed327f 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -151,7 +151,7 @@ void contactRefuseTest() throws Exception { // verify result.andExpect(jsonPath("$.status").value("success")); // 성공 테스트 확인 // 값이 잘 들어가는지 확인 - Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.REFUSE); + Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(ContactStateEnum.REFUSE); } @Test @@ -197,7 +197,7 @@ void contactAccpetTest() throws Exception { // verify result.andExpect(jsonPath("$.status").value("success")); // 성공 테스트 확인 // 값이 잘 들어가는지 확인 - Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.ACCEPT); + Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(ContactStateEnum.ACCEPT); Assertions.assertThat(connectedUser.getId()).isEqualTo(4); } @@ -233,7 +233,7 @@ void createTest() throws Exception { // verify result.andExpect(jsonPath("$.status").value("success")); // 성공 테스트 확인 // 값이 잘 들어가는지 확인 - Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(NotConnectedRegisterUser.State.AWAIT); + Assertions.assertThat(notConnectedRegisterUser.getState()).isEqualTo(ContactStateEnum.AWAIT); } diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java index 66fb3290..900dddd4 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest.java @@ -8,6 +8,7 @@ import com.example.demo.interest.InterestJPARepository; import com.example.demo.mentoring.*; import com.example.demo.mentoring.contact.ContactJPARepository; +import com.example.demo.mentoring.contact.ContactStateEnum; import com.example.demo.mentoring.contact.NotConnectedRegisterUser; import com.example.demo.user.Role; import com.example.demo.user.User; @@ -253,13 +254,13 @@ void findMentorPostSaveTest() { NotConnectedRegisterUser menteeNotConnected1 = NotConnectedRegisterUser.builder() .mentorPost(mentorPost3) .menteeUser(mentee_One) - .state(NotConnectedRegisterUser.State.AWAIT) + .state(ContactStateEnum.AWAIT) .build(); NotConnectedRegisterUser menteeNotConnected2 = NotConnectedRegisterUser.builder() .mentorPost(mentorPost3) .menteeUser(mentee_Two) - .state(NotConnectedRegisterUser.State.AWAIT) + .state(ContactStateEnum.AWAIT) .build(); //when From db466711119199b84105982ac9deafdb4a1d1300 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Fri, 3 Nov 2023 16:10:32 +0900 Subject: [PATCH 35/84] =?UTF-8?q?fix=20:=20FE=20=EC=9A=94=EC=B2=AD?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EB=A9=94=EC=86=8C=EB=93=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../mentoring/contact/ContactResponse.java | 98 +++++++++---------- .../contact/ContactRestController.java | 25 ++--- .../mentoring/contact/ContactService.java | 47 ++++----- .../demo/mentoring/done/DoneResponse.java | 2 + .../mentoring/done/DoneRestController.java | 2 + .../demo/mentoring/done/DoneService.java | 2 + 6 files changed, 87 insertions(+), 89 deletions(-) create mode 100644 src/main/java/com/example/demo/mentoring/done/DoneResponse.java create mode 100644 src/main/java/com/example/demo/mentoring/done/DoneRestController.java create mode 100644 src/main/java/com/example/demo/mentoring/done/DoneService.java diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java index e9aced68..ff83058c 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -61,59 +61,57 @@ public ContactDashboardMentorDTO(MentorPost mentorPost, ContactMentorDTO mentor, } } - @Getter @Setter - public static class ContactMentorDTO { - private int mentorId; - private String profileImage; - private String name; - private String country; - private int age; - private Role role; - private List favorites; + @Getter @Setter + public static class ContactMentorDTO { + private int mentorId; + private String profileImage; + private String name; + private String country; + private int age; + private Role role; + private List favorites; - public ContactMentorDTO(User mentor, List userInterests) { - this.mentorId = mentor.getId(); - this.profileImage = mentor.getProfileImage(); - this.name = mentor.getFirstName() + " " + mentor.getLastName(); - this.country = mentor.getCountry(); - this.age = mentor.getAge(); - this.role = mentor.getRole(); - this.favorites = userInterests.stream() - .filter(userInterest -> userInterest.getUser().getId() == mentor.getId()) - .map(userInterest -> userInterest.getInterest().getCategory()) - .collect(Collectors.toList()); - } + public ContactMentorDTO(User mentor, List userInterests) { + this.mentorId = mentor.getId(); + this.profileImage = mentor.getProfileImage(); + this.name = mentor.getFirstName() + " " + mentor.getLastName(); + this.country = mentor.getCountry(); + this.age = mentor.getAge(); + this.role = mentor.getRole(); + this.favorites = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); } - @Getter @Setter - public static class ContactMenteeDTO { - private int menteeId; - private String profileImage; - private String name; - private String country; - private int age; - private Role role; - private ContactStateEnum state; - private List favorites; // 고민할 부분 : 유저의 favorite List 를 어떻게 가져올 것 인가? + } + @Getter @Setter + public static class ContactMenteeDTO { + private int menteeId; + private String profileImage; + private String name; + private String country; + private int age; + private Role role; + private ContactStateEnum state; + private List favorites; // 고민할 부분 : 유저의 favorite List 를 어떻게 가져올 것 인가? - /** - * 유저의 favorite List 를 가져오기 위해 - * userInterest 를 입력으로 받음 - * userInterest 의 userId 와 현재 신청한 멘티 ( notConnectedRegitserUser ) 의 id 값이 일치하는 경우 - * 그럴 경우에만 tag 값들을 가져오기 - * **/ + /** + * 유저의 favorite List 를 가져오기 위해 + * userInterest 를 입력으로 받음 + * userInterest 의 userId 와 현재 신청한 멘티 ( notConnectedRegitserUser ) 의 id 값이 일치하는 경우 + * 그럴 경우에만 tag 값들을 가져오기 + * **/ - public ContactMenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { - this.menteeId = notConnectedRegisterUser.getId(); - this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage(); - this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName(); - this.country = notConnectedRegisterUser.getMenteeUser().getCountry(); - this.age = notConnectedRegisterUser.getMenteeUser().getAge(); - this.role = notConnectedRegisterUser.getMenteeUser().getRole(); - this.state = notConnectedRegisterUser.getState(); - this.favorites = userInterests.stream() - .filter(userInterest -> userInterest.getUser().getId() == notConnectedRegisterUser.getMenteeUser().getId()) - .map(userInterest -> userInterest.getInterest().getCategory()) - .collect(Collectors.toList()); - } + public ContactMenteeDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { + this.menteeId = notConnectedRegisterUser.getId(); + this.profileImage = notConnectedRegisterUser.getMenteeUser().getProfileImage(); + this.name = notConnectedRegisterUser.getMenteeUser().getFirstName() + " " + notConnectedRegisterUser.getMenteeUser().getLastName(); + this.country = notConnectedRegisterUser.getMenteeUser().getCountry(); + this.age = notConnectedRegisterUser.getMenteeUser().getAge(); + this.role = notConnectedRegisterUser.getMenteeUser().getRole(); + this.state = notConnectedRegisterUser.getState(); + this.favorites = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); } + } } diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java index 29ba82ab..2cfbc08c 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -2,6 +2,7 @@ import com.example.demo.config.auth.CustomUserDetails; import com.example.demo.config.utils.ApiUtils; +import com.example.demo.mentoring.done.DoneService; import com.example.demo.user.Role; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; @@ -21,7 +22,7 @@ public class ContactRestController { @GetMapping(value = "/contacts") @Operation(summary = "contact 화면 조회", description = "멘토, 멘티 화면에 따라 적절한 화면을 보여준다.") - public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) { if ( userDetails.getUser().getRole() == Role.MENTEE ) { List responseDTO = contactService.findAllByMentee(userDetails.getUser()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); @@ -48,33 +49,33 @@ public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails u return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - @PostMapping(value = "/contacts/{userId}/accept") + @PostMapping(value = "/contacts/accept") @Operation(summary = "멘토링 신청 수락", description = "멘토링 신청을 수락한다.") - public ResponseEntity acceptContact(@PathVariable int userId, @RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity acceptContact(@RequestBody @Valid ContactRequest.ContactAcceptDTO contactAcceptDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 수락 API 로직 만들기 - contactService.acceptContact(userId, contactAcceptDTO, userDetails.getUser()); + contactService.acceptContact(contactAcceptDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @PatchMapping(value = "/contacts/{userId}/refuse") + @PatchMapping(value = "/contacts/refuse") @Operation(summary = "멘토링 신청 거절", description = "멘토링 신청을 거절한다.") - public ResponseEntity refuseContact(@PathVariable int userId, @RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity refuseContact(@RequestBody @Valid ContactRequest.ContactRefuseDTO contactRefuseDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 거절 API 로직 만들기 - contactService.refuseContact(userId, contactRefuseDTO, userDetails.getUser()); + contactService.refuseContact(contactRefuseDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @PostMapping(value = "/contacts/{userId}") + @PostMapping(value = "/contacts") @Operation(summary = "멘티의 멘토링 신청", description = "멘토가 작성한 글을 보고, 멘티는 멘토링 신청을 할 수 있다.") - public ResponseEntity createContact(@PathVariable int userId, @RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity createContact(@RequestBody @Valid ContactRequest.ContactCreateDTO contactCreateDTO, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 API 로직 만들기 - contactService.createContact(userId, contactCreateDTO, userDetails.getUser()); + contactService.createContact(contactCreateDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); } - @DeleteMapping(value = "/contacts/{contactId}") + @DeleteMapping(value = "/contacts") @Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.") - public ResponseEntity deleteContact(@PathVariable int contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity deleteContact(@RequestHeader("contactId") List contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 취소 API 로직 만들기 contactService.deleteContact(contactId, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiUtils.successWithNoContent()); diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index e40bec9e..621175ed 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -1,6 +1,5 @@ package com.example.demo.mentoring.contact; -import com.example.demo.config.errors.exception.Exception400; import com.example.demo.config.errors.exception.Exception401; import com.example.demo.config.errors.exception.Exception404; import com.example.demo.mentoring.MentorPost; @@ -9,7 +8,6 @@ import com.example.demo.mentoring.done.DoneJPARepository; import com.example.demo.user.Role; import com.example.demo.user.User; -import com.example.demo.user.UserJPARepository; import com.example.demo.user.userInterest.UserInterest; import com.example.demo.user.userInterest.UserInterestJPARepository; import lombok.RequiredArgsConstructor; @@ -103,11 +101,11 @@ public ContactResponse.PostCountDTO postCountsMyMentee(int userId) { } @Transactional - public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcceptDTO, User user) { - isMentor(userId, user); + public void acceptContact(ContactRequest.ContactAcceptDTO contactAcceptDTO, User user) { + isMentor(user); // dto 예외 처리 - if ( contactAcceptDTO.getMentorId() != userId ) { + if ( contactAcceptDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -133,12 +131,12 @@ public void acceptContact(int userId, ContactRequest.ContactAcceptDTO contactAcc } @Transactional - public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRefuseDTO, User user) { + public void refuseContact(ContactRequest.ContactRefuseDTO contactRefuseDTO, User user) { // 예외 처리 - isMentor(userId, user); + isMentor(user); // dto 예외 처리 - if ( contactRefuseDTO.getMentorId() != userId ) { + if ( contactRefuseDTO.getMentorId() != user.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -153,14 +151,10 @@ public void refuseContact(int userId, ContactRequest.ContactRefuseDTO contactRef } @Transactional - public void createContact(int userId, ContactRequest.ContactCreateDTO contactCreateDTO, User mentee) { + public void createContact(ContactRequest.ContactCreateDTO contactCreateDTO, User mentee) { // 예외 처리 isMentee(mentee); - if (userId != mentee.getId() ) { - throw new Exception401("올바른 사용자가 아닙니다."); - } - int mentorPostId = contactCreateDTO.getMentorPostId(); // 현재 멘토가 작성한 글인지 체크 @@ -173,31 +167,30 @@ public void createContact(int userId, ContactRequest.ContactCreateDTO contactCre } @Transactional - public void deleteContact(int contactId, User mentee) { - - // 해당하는 NotConnectedRegisterUser 가져오기 - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(contactId) - .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다." )); + public void deleteContact(List contactId, User mentee) { // 예외 처리 isMentee(mentee); - if ( notConnectedRegisterUser.getMenteeUser().getId() != mentee.getId() ) { - throw new Exception401("올바른 사용자가 아닙니다."); + // 해당하는 NotConnectedRegisterUser 가져오기 + for (int contact : contactId) { + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(contact) + .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다." )); + + if ( notConnectedRegisterUser.getMenteeUser().getId() != mentee.getId() ) { + throw new Exception401("올바른 사용자가 아닙니다."); + } + // notConnectedRegisterUser delete 요청 보내기 + contactJPARepository.deleteById(notConnectedRegisterUser.getId()); } - // notConnectedRegisterUser delete 요청 보내기 - contactJPARepository.deleteById(notConnectedRegisterUser.getId()); + } // 멘토 인증을 위한 메소드 - private void isMentor(int userId, User user) { + private void isMentor(User user) { // 예외 처리 if ( user.getRole() != Role.MENTOR ) { throw new Exception401("해당 사용자는 멘토가 아닙니다."); } - // user 체크 - if (userId != user.getId() ) { - throw new Exception401("올바른 사용자가 아닙니다."); - } } // 멘티 인증을 위한 메소드 diff --git a/src/main/java/com/example/demo/mentoring/done/DoneResponse.java b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java new file mode 100644 index 00000000..b64af754 --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java @@ -0,0 +1,2 @@ +package com.example.demo.mentoring.done;public class DoneResponse { +} diff --git a/src/main/java/com/example/demo/mentoring/done/DoneRestController.java b/src/main/java/com/example/demo/mentoring/done/DoneRestController.java new file mode 100644 index 00000000..588d90d9 --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/done/DoneRestController.java @@ -0,0 +1,2 @@ +package com.example.demo.mentoring.done;public class DoneRestController { +} diff --git a/src/main/java/com/example/demo/mentoring/done/DoneService.java b/src/main/java/com/example/demo/mentoring/done/DoneService.java new file mode 100644 index 00000000..c9e9ad4a --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/done/DoneService.java @@ -0,0 +1,2 @@ +package com.example.demo.mentoring.done;public class DoneService { +} From d2917503f986ea8f2304e87a441570db13184897 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Fri, 3 Nov 2023 16:10:58 +0900 Subject: [PATCH 36/84] =?UTF-8?q?test=20:=20method=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- src/test/java/com/example/demo/contactTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 22ed327f..95dcc20a 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -135,7 +135,7 @@ void contactRefuseTest() throws Exception { // when ResultActions result = mvc.perform( - MockMvcRequestBuilders.patch("/contacts/1/refuse") + MockMvcRequestBuilders.patch("/contacts/refuse") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); @@ -175,7 +175,7 @@ void contactAccpetTest() throws Exception { // when ResultActions result = mvc.perform( - MockMvcRequestBuilders.post("/contacts/1/accept") + MockMvcRequestBuilders.post("/contacts/accept") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); @@ -218,7 +218,7 @@ void createTest() throws Exception { // when ResultActions result = mvc.perform( - MockMvcRequestBuilders.post("/contacts/4") + MockMvcRequestBuilders.post("/contacts") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); @@ -242,11 +242,11 @@ void createTest() throws Exception { @DisplayName("멘티 : 신청 취소 테스트 코드") void deleteTest() throws Exception { // given - int id = 1; // when ResultActions result = mvc.perform( - MockMvcRequestBuilders.delete("/contacts/" + id) + MockMvcRequestBuilders.delete("/contacts") + .header("contactId", 1,2) .contentType(MediaType.APPLICATION_JSON) ); String responseBody = result.andReturn().getResponse().getContentAsString(); From 1a41dcf0fc2ec280e06f621d1ca8816e43efc8b4 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Fri, 3 Nov 2023 16:15:21 +0900 Subject: [PATCH 37/84] =?UTF-8?q?fix=20:=20service=20method=20=ED=8C=8C?= =?UTF-8?q?=EB=9D=BC=EB=AF=B8=ED=84=B0=20=EC=9D=B4=EB=A6=84=20user=20->=20?= =?UTF-8?q?mentor=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../demo/mentoring/contact/ContactService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/contact/ContactService.java b/src/main/java/com/example/demo/mentoring/contact/ContactService.java index 621175ed..cd451699 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -101,11 +101,11 @@ public ContactResponse.PostCountDTO postCountsMyMentee(int userId) { } @Transactional - public void acceptContact(ContactRequest.ContactAcceptDTO contactAcceptDTO, User user) { - isMentor(user); + public void acceptContact(ContactRequest.ContactAcceptDTO contactAcceptDTO, User mentor) { + isMentor(mentor); // dto 예외 처리 - if ( contactAcceptDTO.getMentorId() != user.getId() ) { + if ( contactAcceptDTO.getMentorId() != mentor.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } @@ -131,12 +131,12 @@ public void acceptContact(ContactRequest.ContactAcceptDTO contactAcceptDTO, User } @Transactional - public void refuseContact(ContactRequest.ContactRefuseDTO contactRefuseDTO, User user) { + public void refuseContact(ContactRequest.ContactRefuseDTO contactRefuseDTO, User mentor) { // 예외 처리 - isMentor(user); + isMentor(mentor); // dto 예외 처리 - if ( contactRefuseDTO.getMentorId() != user.getId() ) { + if ( contactRefuseDTO.getMentorId() != mentor.getId() ) { throw new Exception401("올바른 사용자가 아닙니다."); } From f6c3e390da74a903c87bf5ba765ba400320c8a34 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Fri, 3 Nov 2023 16:20:59 +0900 Subject: [PATCH 38/84] =?UTF-8?q?feat=20:=20done=20=ED=99=94=EB=A9=B4=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20response=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jin_00 --- .../demo/mentoring/done/DoneResponse.java | 74 ++++++++++++++++++- .../mentoring/done/DoneRestController.java | 31 +++++++- .../demo/mentoring/done/DoneService.java | 20 ++++- 3 files changed, 122 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/done/DoneResponse.java b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java index b64af754..85dabc77 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneResponse.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java @@ -1,2 +1,74 @@ -package com.example.demo.mentoring.done;public class DoneResponse { +package com.example.demo.mentoring.done; + +import com.example.demo.mentoring.MentorPost; +import com.example.demo.mentoring.contact.ContactResponse; +import com.example.demo.user.Role; +import com.example.demo.user.User; +import com.example.demo.user.userInterest.UserInterest; +import lombok.Getter; +import lombok.Setter; + +import java.util.List; +import java.util.stream.Collectors; + +public class DoneResponse { + @Getter + @Setter + public static class DoneDashBoardDTO { + private int postId; + private String title; + private DoneMentorDTO mentor; + private List mentees; + + public DoneDashBoardDTO(MentorPost mentorPost, DoneMentorDTO mentor, List mentees) { + this.postId = mentorPost.getId(); + this.title = mentorPost.getTitle(); + this.mentor = mentor; + this.mentees = mentees; + } + } + + @Getter @Setter + public static class DoneMentorDTO { + private int mentorId; + private String profileImage; + private String name; + private String country; + private int age; + private Role role; + private List favorites; + + public DoneMentorDTO(User mentor, List userInterests) { + this.mentorId = mentor.getId(); + this.profileImage = mentor.getProfileImage(); + this.name = mentor.getFirstName() + " " + mentor.getLastName(); + this.country = mentor.getCountry(); + this.age = mentor.getAge(); + this.role = mentor.getRole(); + this.favorites = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } + } + @Getter @Setter + public static class DoneMenteeDTO { + private int menteeId; + private String profileImage; + private String name; + private String country; + private int age; + private Role role; + private List favorites; + public DoneMenteeDTO(ConnectedUser connectedUser, List userInterests) { + this.menteeId = connectedUser.getId(); + this.profileImage = connectedUser.getMenteeUser().getProfileImage(); + this.name = connectedUser.getMenteeUser().getFirstName() + " " + connectedUser.getMenteeUser().getLastName(); + this.country = connectedUser.getMenteeUser().getCountry(); + this.age = connectedUser.getMenteeUser().getAge(); + this.role = connectedUser.getMenteeUser().getRole(); + this.favorites = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } + } } diff --git a/src/main/java/com/example/demo/mentoring/done/DoneRestController.java b/src/main/java/com/example/demo/mentoring/done/DoneRestController.java index 588d90d9..c4add08c 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneRestController.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneRestController.java @@ -1,2 +1,31 @@ -package com.example.demo.mentoring.done;public class DoneRestController { +package com.example.demo.mentoring.done; + +import com.example.demo.config.auth.CustomUserDetails; +import com.example.demo.config.utils.ApiUtils; +import com.example.demo.mentoring.contact.ContactResponse; +import com.example.demo.user.Role; +import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RequiredArgsConstructor +@RestController +public class DoneRestController { + + private final DoneService doneService; + + @GetMapping(value = "/contacts/done") + @Operation(summary = "contact 화면 조회", description = "멘토, 멘티 화면에 따라 적절한 화면을 보여준다.") + public ResponseEntity findAllContacts(@AuthenticationPrincipal CustomUserDetails userDetails) { + // TO-DO : done 화면 조회 API 로직 만들기 ( 멘토, 멘티 나눠서 ) + if ( userDetails.getUser().getRole() == Role.MENTEE ) { + return null; + } + return null; + } } diff --git a/src/main/java/com/example/demo/mentoring/done/DoneService.java b/src/main/java/com/example/demo/mentoring/done/DoneService.java index c9e9ad4a..bc566d27 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneService.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneService.java @@ -1,2 +1,20 @@ -package com.example.demo.mentoring.done;public class DoneService { +package com.example.demo.mentoring.done; + +import com.example.demo.mentoring.MentorPost; +import com.example.demo.mentoring.contact.ContactResponse; +import com.example.demo.mentoring.contact.NotConnectedRegisterUser; +import com.example.demo.user.User; +import com.example.demo.user.userInterest.UserInterest; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Transactional(readOnly = true) +@RequiredArgsConstructor +@Service +public class DoneService { + } From 1c9af4acec2b3f55f0726adfc5be623ccecf7fd8 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Fri, 3 Nov 2023 17:28:16 +0900 Subject: [PATCH 39/84] =?UTF-8?q?feat=20:=20video=20find=20all=20service?= =?UTF-8?q?=20video=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=B3=84=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/video/Subtitle.java | 2 +- .../demo/video/SubtitleJPARepository.java | 12 +++++++ .../java/com/example/demo/video/Video.java | 2 +- .../com/example/demo/video/VideoInterest.java | 2 +- .../video/VideoInterestJPARepository.java | 12 +++++++ .../demo/video/VideoJPARepostiory.java | 3 +- .../com/example/demo/video/VideoResponse.java | 6 ++-- .../demo/video/VideoRestController.java | 2 +- .../com/example/demo/video/VideoService.java | 36 +++++++++++++++++++ 9 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/example/demo/video/SubtitleJPARepository.java create mode 100644 src/main/java/com/example/demo/video/VideoInterestJPARepository.java diff --git a/src/main/java/com/example/demo/video/Subtitle.java b/src/main/java/com/example/demo/video/Subtitle.java index b2107b85..9fc06413 100644 --- a/src/main/java/com/example/demo/video/Subtitle.java +++ b/src/main/java/com/example/demo/video/Subtitle.java @@ -12,7 +12,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "subtitle_tb") +@Table(name = "subtitles") public class Subtitle extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/SubtitleJPARepository.java b/src/main/java/com/example/demo/video/SubtitleJPARepository.java new file mode 100644 index 00000000..4a12d9d2 --- /dev/null +++ b/src/main/java/com/example/demo/video/SubtitleJPARepository.java @@ -0,0 +1,12 @@ +package com.example.demo.video; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.Optional; + +public interface SubtitleJPARepository extends JpaRepository { + @Query("select m from Subtitle m where m.video.id = :video") + Optional findSubtitleByVideoId(@Param("video") int video); +} diff --git a/src/main/java/com/example/demo/video/Video.java b/src/main/java/com/example/demo/video/Video.java index e96598d2..20af093b 100644 --- a/src/main/java/com/example/demo/video/Video.java +++ b/src/main/java/com/example/demo/video/Video.java @@ -12,7 +12,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "video_tb") +@Table(name = "videos") public class Video extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/VideoInterest.java b/src/main/java/com/example/demo/video/VideoInterest.java index 11a58b0f..1bbf4842 100644 --- a/src/main/java/com/example/demo/video/VideoInterest.java +++ b/src/main/java/com/example/demo/video/VideoInterest.java @@ -13,7 +13,7 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity -@Table(name = "videoInterest_tb") +@Table(name = "video_interests") public class VideoInterest extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) @Id diff --git a/src/main/java/com/example/demo/video/VideoInterestJPARepository.java b/src/main/java/com/example/demo/video/VideoInterestJPARepository.java new file mode 100644 index 00000000..34d41250 --- /dev/null +++ b/src/main/java/com/example/demo/video/VideoInterestJPARepository.java @@ -0,0 +1,12 @@ +package com.example.demo.video; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface VideoInterestJPARepository extends JpaRepository { + @Query("select m from VideoInterest m where m.video.id = :video") + List findVideoInterestByVideoId(@Param("video") int video); +} diff --git a/src/main/java/com/example/demo/video/VideoJPARepostiory.java b/src/main/java/com/example/demo/video/VideoJPARepostiory.java index 2da192ef..8d72b874 100644 --- a/src/main/java/com/example/demo/video/VideoJPARepostiory.java +++ b/src/main/java/com/example/demo/video/VideoJPARepostiory.java @@ -1,7 +1,6 @@ package com.example.demo.video; -import com.example.demo.user.User; import org.springframework.data.jpa.repository.JpaRepository; -public interface VideoJPARepostiory extends JpaRepository { +public interface VideoJPARepostiory extends JpaRepository { } diff --git a/src/main/java/com/example/demo/video/VideoResponse.java b/src/main/java/com/example/demo/video/VideoResponse.java index 8a99dcd2..885826fa 100644 --- a/src/main/java/com/example/demo/video/VideoResponse.java +++ b/src/main/java/com/example/demo/video/VideoResponse.java @@ -11,14 +11,15 @@ public class VideoResponse { @Getter @Setter - public class UserCategoryVideoResponseDTO { + public static class VideoResponseDTO { private int videoID; private String videoUrl; private String videoInfoKorean; private String videoInfoEng; private List interests; + private Subtitle subtitle; - public UserCategoryVideoResponseDTO(Video video, List videoInterests) + public VideoResponseDTO(Video video, List videoInterests, Subtitle subtitle) { this.videoID = video.getId(); this.videoUrl = video.getVideoUrl(); @@ -27,6 +28,7 @@ public UserCategoryVideoResponseDTO(Video video, List videoIntere this.interests = videoInterests.stream() .map(videoInterest -> videoInterest.getInterest().getCategory()) .collect(Collectors.toList()); + this.subtitle = subtitle; } } } diff --git a/src/main/java/com/example/demo/video/VideoRestController.java b/src/main/java/com/example/demo/video/VideoRestController.java index cb4e880f..89c90780 100644 --- a/src/main/java/com/example/demo/video/VideoRestController.java +++ b/src/main/java/com/example/demo/video/VideoRestController.java @@ -21,7 +21,7 @@ public class VideoRestController { @GetMapping("/videos/main") public ResponseEntity getUserCategoryVideo(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { - List responseDTOs = videoService.findUserCategoryVideo(page); + List responseDTOs = videoService.findUserCategoryVideo(page); return ResponseEntity.ok(ApiUtils.success(responseDTOs)); } } diff --git a/src/main/java/com/example/demo/video/VideoService.java b/src/main/java/com/example/demo/video/VideoService.java index e7af806c..4a5bd975 100644 --- a/src/main/java/com/example/demo/video/VideoService.java +++ b/src/main/java/com/example/demo/video/VideoService.java @@ -1,12 +1,48 @@ package com.example.demo.video; +import com.example.demo.config.errors.exception.Exception404; +import com.example.demo.mentoring.MentorPostResponse; +import com.example.demo.user.userInterest.UserInterest; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; +import java.util.stream.Collectors; + @Transactional @RequiredArgsConstructor @Service public class VideoService { + private final VideoJPARepostiory videoJPARepostiory; + private final VideoInterestJPARepository videoInterestJPARepository; + private final SubtitleJPARepository subtitleJPARepository; + + public List findAllVideo(Integer page) { + Pageable pageable = PageRequest.of(page,4); + + Page