From c9cd11cdd43e1b4f37a6ca986945a6d7ed9b661c Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 11 Oct 2023 22:52:21 +0900 Subject: [PATCH 01/12] =?UTF-8?q?feat=20:=20postCountDTO=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(=20contact,=20done=20=EC=98=86=20=EC=88=AB?= =?UTF-8?q?=EC=9E=90=20=ED=91=9C=EC=8B=9C=ED=95=B4=EC=A3=BC=EB=8A=94=20DTO?= =?UTF-8?q?=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/mentoring/contact/ContactResponse.java | 11 +++++++++++ .../demo/mentoring/contact/ContactRestController.java | 9 +++++++++ 2 files changed, 20 insertions(+) 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 a6daaf6b..ea139eaa 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -11,6 +11,17 @@ import java.util.stream.Collectors; public class ContactResponse { + + @Getter @Setter + public static class postCountDTO { + private int contactCount; + private int doneCount; + + public postCountDTO(int contactCount, int doneCount) { + this.contactCount = contactCount; + this.doneCount = doneCount; + } + } /** * * DTO 담는 순서 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 1827c26f..2ea7cc6f 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -23,5 +23,14 @@ public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails user List responseDTO = contactService.findAll(userDetails.getUser()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } + + @GetMapping(value = "/contacts/postCounts") + @Operation(summary = "", description = "") + public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails userDetails) { + // TO-DO : contact, done 옆 숫자를 띄우는 API 로직 만들기 ( 멘토, 멘티 나눠서 ) + + + return null; + } } From 13bfbd812e51e579690719a19f266bb931c3c958 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 22:18:52 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat=20:=20[=20=EB=A9=98=ED=86=A0=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80=20]=20contact,=20done=20=EA=B2=8C=EC=8B=9C?= =?UTF-8?q?=EA=B8=80=EC=9D=98=20=EA=B0=AF=EC=88=98=EB=A5=BC=20=EC=84=B8?= =?UTF-8?q?=EB=8A=94=20=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 --- .../mentoring/MentorPostJPARepostiory.java | 3 + .../contact/ContactRestController.java | 12 +- .../mentoring/contact/ContactService.java | 107 +++++++++--------- .../contact/NotConnectedRegisterUser.java | 4 + .../demo/mentoring/done/ConnectedUser.java | 7 +- .../mentoring/done/DoneJPARepository.java | 12 ++ 6 files changed, 89 insertions(+), 56 deletions(-) create mode 100644 src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index 766bcc6e..ceefeb24 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -14,4 +14,7 @@ public interface MentorPostJPARepostiory extends JpaRepository findAllByWriter(@Param("writer") int writer); MentorPost findById(int id); + + @Query("select count(*) from MentorPost m where m.writer.id = :userId") + int countByMentorId(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 2ea7cc6f..0cabc7b0 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.user.Role; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -20,7 +21,7 @@ public class ContactRestController { @GetMapping(value = "/contacts") @Operation(summary = "", description = "") public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { - List responseDTO = contactService.findAll(userDetails.getUser()); + List responseDTO = contactService.findAll(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } @@ -29,8 +30,15 @@ public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails user public ResponseEntity postCounts(@AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : contact, done 옆 숫자를 띄우는 API 로직 만들기 ( 멘토, 멘티 나눠서 ) + // 멘토, 멘티 구분 + Role role = userDetails.getUser().getRole(); - return null; + if ( role == Role.MENTEE ) { + return null; + } + + ContactResponse.postCountDTO responseDTO = contactService.postCountsByMentor(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 69ed6bd8..b9e1f6f3 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -2,6 +2,8 @@ import com.example.demo.mentoring.MentorPost; import com.example.demo.mentoring.MentorPostJPARepostiory; +import com.example.demo.mentoring.done.ConnectedUser; +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; @@ -24,65 +26,55 @@ public class ContactService { private final UserJPARepository userJPARepository; private final ContactJPARepository contactJPARepository; private final UserInterestJPARepository userInterestJPARepository; + private final DoneJPARepository doneJPARepository; /** * findAll : dashboard - contact 부분 화면에 필요한 DTO를 응답해주는 함수 * parameter : Account ( 유저의 계정 ) * **/ - public List findAll(User user) { - // user 의 id 값 - int id = user.getId(); - - // 분기 - 유저가 멘토인지, 멘티인지 - if ( user.getRole() == Role.MENTEE ) { - // TO-DO : Mentee 입장에서 조회하는 부분 작성하기 - return null; - } - else { - /** - * 흐름 ( 멘토 입장 ) - * 1. 내가 작성한 게시글 ( mentorPosts ) 들을 조회해서 가져온다. - * 2. 멘토의 정보는 mentorPosts 와 별개로 한번에 조회되는 값이니, for문 밖으로 빼서 조회한다. - * - 멘토의 정보를 만들기 위해 필요한 값 : mentor 의 user, mentor 의 interests - * - user 는 조회하면 되니, 바로 구할 수 있다. - * - userInterest 에서 멘토의 interest 값들을 가져올 수 있기 때문에, userInterest 와 interest 를 join 후 tag 들을 가져온다. - * 3. mentorPosts 를 활용하여 for문을 돌면서 mentorPost 1개 + mentor 정보 1개 + mentee 정보 여러개 의 꼴로 DTO 를 만든다. - * - mentee 의 정보를 만들기 위해 필요한 값 : notConnectedRegisterUser 에서 mentee 의 정보, mentee 의 interests - * - 신청한 멘티들의 정보를 가져오기 위해 notConnectedRegisterUser 의 테이블과 , 각 멘티에 해당하는 interests 들을 묶어서 DTO 로 만들기 ( 그래서 List 를 만듬 ) - * - 싹다 묶어서 reponseDTOs 로 전달 - * **/ - // Return 할 객체 - List responseDTOs = new ArrayList<>(); - - // 멘토의 id 에 해당하는 mentorPost 다 가져오기 - List mentorPosts = mentorPostJPARepostiory.findAllByWriter(id); - - // 멘토 정보 가져오기 ( 나중에 User 로 바꿔야 함 ) - User mentorUser = userJPARepository.findById(id); - // List 가져오기 ( 멘토꺼 tag 목록 ) - List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); - - // MentorDTO 담기 - ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); - - // 만약 3개의 글을 썼을 경우, 현재 mentorPosts 에는 3개의 글 목록이 존재함 - for ( MentorPost mentorPost : mentorPosts ) { - // List 만들기 - // 신청한 멘티의 목록 ( postId 로 조회 ) - List mentees = contactJPARepository.findAllByMentorPostId(mentorPost.getId()); - - // List 생성 - List menteeDTOs = mentees - .stream() - .map(this::createMenteeDTO) - .collect(Collectors.toList()); - // responseDTO 에 담기 - responseDTOs.add(new ContactResponse.MentorPostDTO(mentorPost, mentorDTO, menteeDTOs)); - - } - return responseDTOs; - } + public List findAll(int id) { + /** + * 흐름 ( 멘토 입장 ) + * 1. 내가 작성한 게시글 ( mentorPosts ) 들을 조회해서 가져온다. + * 2. 멘토의 정보는 mentorPosts 와 별개로 한번에 조회되는 값이니, for문 밖으로 빼서 조회한다. + * - 멘토의 정보를 만들기 위해 필요한 값 : mentor 의 user, mentor 의 interests + * - user 는 조회하면 되니, 바로 구할 수 있다. + * - userInterest 에서 멘토의 interest 값들을 가져올 수 있기 때문에, userInterest 와 interest 를 join 후 tag 들을 가져온다. + * 3. mentorPosts 를 활용하여 for문을 돌면서 mentorPost 1개 + mentor 정보 1개 + mentee 정보 여러개 의 꼴로 DTO 를 만든다. + * - mentee 의 정보를 만들기 위해 필요한 값 : notConnectedRegisterUser 에서 mentee 의 정보, mentee 의 interests + * - 신청한 멘티들의 정보를 가져오기 위해 notConnectedRegisterUser 의 테이블과 , 각 멘티에 해당하는 interests 들을 묶어서 DTO 로 만들기 ( 그래서 List 를 만듬 ) + * - 싹다 묶어서 reponseDTOs 로 전달 + * **/ + // Return 할 객체 + List responseDTOs = new ArrayList<>(); + + // 멘토의 id 에 해당하는 mentorPost 다 가져오기 + List mentorPosts = mentorPostJPARepostiory.findAllByWriter(id); + + // 멘토 정보 가져오기 ( 나중에 User 로 바꿔야 함 ) + User mentorUser = userJPARepository.findById(id); + // List 가져오기 ( 멘토꺼 tag 목록 ) + List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); + + // MentorDTO 담기 + ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); + + // 만약 3개의 글을 썼을 경우, 현재 mentorPosts 에는 3개의 글 목록이 존재함 + for ( MentorPost mentorPost : mentorPosts ) { + // List 만들기 + // 신청한 멘티의 목록 ( postId 로 조회 ) + List mentees = contactJPARepository.findAllByMentorPostId(mentorPost.getId()); + + // List 생성 + List menteeDTOs = mentees + .stream() + .map(this::createMenteeDTO) + .collect(Collectors.toList()); + // responseDTO 에 담기 + responseDTOs.add(new ContactResponse.MentorPostDTO(mentorPost, mentorDTO, menteeDTOs)); + } + return responseDTOs; } // 매핑 로직 분리 ( menteeDTO 생성 로직 ) @@ -94,4 +86,13 @@ private ContactResponse.MenteeDTO createMenteeDTO(NotConnectedRegisterUser mente return new ContactResponse.MenteeDTO(mentee, menteeInterests); } + // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 + public ContactResponse.postCountDTO postCountsByMentor(int userId) { + // contact 화면에서 게시글을 조회 ( 나중에 where 조건에 state 를 달아야 함 ) + int contactCount = mentorPostJPARepostiory.countByMentorId(userId); + // done 화면에서 게시글을 조회 + int doneCount = doneJPARepository.countByMentorId(userId); + + return new ContactResponse.postCountDTO(contactCount, doneCount); + } } 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 b4537021..1ed18dfb 100644 --- a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java +++ b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java @@ -7,12 +7,16 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity +@Where(clause = "deleted_at IS NULL") +@SQLDelete(sql = "UPDATE not_connected_register_user SET deleted_at = CURRENT_TIMESTAMP, isDeleted = TRUE where id = ?") @Table(name = "notConnectedRegisterUser_tb") 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 46f4bca2..b84ba0c7 100644 --- a/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java +++ b/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java @@ -1,18 +1,23 @@ package com.example.demo.mentoring.done; +import com.example.demo.config.utils.BaseTime; import com.example.demo.user.User; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity +@Where(clause = "deleted_at IS NULL") +@SQLDelete(sql = "UPDATE connected_user_tb SET deleted_at = CURRENT_TIMESTAMP, isDeleted = TRUE where id = ?") @Table(name = "connectedUser_tb") -public class ConnectedUser { +public class ConnectedUser extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java b/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java new file mode 100644 index 00000000..ff86e054 --- /dev/null +++ b/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java @@ -0,0 +1,12 @@ +package com.example.demo.mentoring.done; + +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 DoneJPARepository extends JpaRepository { + @Query("select count(*) from ConnectedUser cu where cu.mentorUser.id = :userId") + int countByMentorId(@Param("userId") int userId); +} From 3d525011ab677cad611b89545d46296b54bea857 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 22:19:41 +0900 Subject: [PATCH 03/12] test : /contacts, /contacts/countPosts API Test --- src/main/resources/db/teardown.sql | 18 ++- .../java/com/example/demo/contactTest.java | 148 ++++++------------ 2 files changed, 58 insertions(+), 108 deletions(-) diff --git a/src/main/resources/db/teardown.sql b/src/main/resources/db/teardown.sql index 949b96e4..f20d62d4 100644 --- a/src/main/resources/db/teardown.sql +++ b/src/main/resources/db/teardown.sql @@ -4,6 +4,7 @@ TRUNCATE TABLE interest_tb; TRUNCATE TABLE mentor_post_tb; TRUNCATE TABLE user_interest_tb; TRUNCATE TABLE not_connected_register_user_tb; +TRUNCATE TABLE connected_user_tb; SET REFERENTIAL_INTEGRITY TRUE; -- user Table @@ -12,7 +13,8 @@ INSERT INTO user_tb (created_at, first_name, last_name, email, password, country (NOW(), 'Alice', 'Smith', 'alice.smith@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'Canada', 'I love painting.', 25, 'image2.jpg', 'MENTOR'), (NOW(), 'Admin', 'Admin', 'admin@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am an admin user.', 35, 'admin.jpg', 'MENTEE'), (NOW(), 'Jane', 'Smith', 'jane@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'Canada', 'I love coding.', 30, 'profile.jpg', 'MENTEE'), - (NOW(), 'Admin', 'Adminson', 'admin22222@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am the admin.', 35, 'admin.jpg', 'MENTEE'); + (NOW(), 'Admin', 'Adminson', 'admin22222@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am the admin.', 35, 'admin.jpg', 'MENTEE'), + (NOW(), 'Adminnnn', 'Adminsonnnnn', 'admin33333@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am the admin.', 35, 'admin.jpg', 'MENTEE'); -- interst Table INSERT INTO interest_tb (created_at, category) VALUES @@ -36,7 +38,7 @@ INSERT INTO mentor_post_tb (created_at, writer_id, title, content) VALUES (NOW(), 1, 'Graphic Design Mentorship', 'Create stunning graphics and designs.'), (NOW(), 1, 'Yoga and Mindfulness Mentorship', 'Find inner peace and balance through yoga.'), (NOW(), 1, 'Photography Mentorship', 'Capture amazing moments with your camera.'), - (NOW(), 2, 'Mathematics Tutoring', 'I can help you understand and excel in math.');; + (NOW(), 2, 'Mathematics Tutoring', 'I can help you understand and excel in math.'); -- notConnectedRegisterUser Table @@ -45,6 +47,13 @@ INSERT INTO not_connected_register_user_tb (created_at, mentor_post_id, mentee_u (NOW(), 1, 4, 'ACCEPT'), (NOW(), 2, 5, 'AWAIT'); +-- connectedUser Table +INSERT INTO connected_user_tb (created_at, mentor_user_id, mentee_user_id) +VALUES + (NOW(), 1, 5), + (NOW(), 1, 6), + (NOW(), 2, 3); + -- userInterest Table INSERT INTO user_interest_tb (created_at, user_id, interest_id) VALUES (NOW(), 1, 1), @@ -56,5 +65,6 @@ INSERT INTO user_interest_tb (created_at, user_id, interest_id) VALUES (NOW(), 4, 1), (NOW(), 4, 3), (NOW(), 5, 3), - (NOW(), 5, 4) -; \ No newline at end of file + (NOW(), 5, 4), + (NOW(), 5, 3), + (NOW(), 5, 4); diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 18c072e0..bb761da9 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -14,28 +14,28 @@ import com.example.demo.user.userInterest.UserInterest; import com.example.demo.user.userInterest.UserInterestJPARepository; import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.models.Contact; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +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; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import java.util.List; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; + @SpringBootTest @ActiveProfiles("test") -public class contactTest { - - @Autowired - private MentorPostJPARepostiory mentorPostJPARepostiory; - @Autowired - private UserJPARepository userJPARepository; - @Autowired - private ContactJPARepository contactJPARepository; - @Autowired - private UserInterestJPARepository userInterestJPARepository; - @Autowired - private InterestJPARepository interestJPARepository; +@Sql("classpath:db/teardown.sql") +public class contactTest extends RestDoc { @Autowired private ContactService contactService; @@ -43,104 +43,44 @@ public class contactTest { @Autowired private ObjectMapper om; - User user1; - - @BeforeEach - void setUp() { - user1 = User.builder() - .email("anjdal65@gmail.com") - .password("asdf1234!") - .firstName("aaa") - .lastName("Seung") - .country("Korea") - .age(21) - .role(Role.MENTOR) - .build(); - User user2 = User.builder() - .email("anjdal44@gmail.com") - .password("asdf1234!") - .firstName("bbb") - .lastName("Seung") - .country("Korea") - .age(21) - .role(Role.MENTEE) - .build(); - User user3 = User.builder() - .email("anjdal66@gmail.com") - .password("asdf1234!") - .firstName("ccc") - .lastName("Seung") - .country("Korea") - .age(21) - .role(Role.MENTEE) - .build(); - - userJPARepository.save(user1); - userJPARepository.save(user2); - userJPARepository.save(user3); - - Interest interest = Interest.builder() - .category("K-POP") - .build(); - - interestJPARepository.save(interest); - - - UserInterest userInterest1 = UserInterest.builder() - .user(user1) - .interest(interest) - .build(); - UserInterest userInterest2 = UserInterest.builder() - .user(user2) - .interest(interest) - .build(); - UserInterest userInterest3 = UserInterest.builder() - .user(user3) - .interest(interest) - .build(); - - userInterestJPARepository.save(userInterest1); - userInterestJPARepository.save(userInterest2); - userInterestJPARepository.save(userInterest3); - - MentorPost mentorPost = MentorPost.builder() - .writer(user1) - .title("가나다라마바사") - .build(); - - MentorPost mentorPost2 = MentorPost.builder() - .writer(user1) - .title("아자차카타파하") - .build(); - - mentorPostJPARepostiory.save(mentorPost); - mentorPostJPARepostiory.save(mentorPost2); - - - NotConnectedRegisterUser mentee1 = NotConnectedRegisterUser.builder() - .mentorPost(mentorPost) - .menteeUser(user2) - .state(NotConnectedRegisterUser.State.AWAIT) - .build(); - NotConnectedRegisterUser mentee2 = NotConnectedRegisterUser.builder() - .mentorPost(mentorPost) - .menteeUser(user3) - .state(NotConnectedRegisterUser.State.AWAIT) - .build(); - // 문제점 : save 를 하기 위해 notConnected~ table 을 조회, mentorPost table 을 조회, account table 을 조회함 - // 나중에 고쳐야할 듯 하다. - contactJPARepository.save(mentee1); - contactJPARepository.save(mentee2); + @Test + @WithUserDetails("john@example.com") + @DisplayName("contact - mentor") + void contactTest() 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 - void test() throws Exception { + @WithUserDetails("john@example.com") + @DisplayName("contact, done - count") + void countTest() throws Exception { + + // when + ResultActions resultActions = mvc.perform( + get("/contacts/postCounts") + ); - List responseDTOs = contactService.findAll(user1); + // console + String responseBody = resultActions.andReturn().getResponse().getContentAsString(); + System.out.println("테스트 : "+responseBody); - String responseBody = om.writeValueAsString(responseDTOs); + // verify + resultActions.andExpect(jsonPath("$.status").value("success")); - System.out.println("test : " + responseBody); } } From 4b92acfe9379e1cbede1e7ce975592cb56a23fae Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 22:21:52 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat=20:=20/contacts=20mentor,=20mentee?= =?UTF-8?q?=20=ED=99=94=EB=A9=B4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/mentoring/contact/ContactRestController.java | 7 ++++++- 1 file changed, 6 insertions(+), 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 0cabc7b0..4f9b4e9d 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -21,9 +21,14 @@ public class ContactRestController { @GetMapping(value = "/contacts") @Operation(summary = "", description = "") public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { - List responseDTO = contactService.findAll(userDetails.getUser().getId()); + if ( userDetails.getUser().getRole() == Role.MENTEE ) { + List responseDTO = contactService.findAllByMentee(userDetails.getUser()); + return ResponseEntity.ok(ApiUtils.success(responseDTO)); + } + List responseDTO = contactService.findAllByMentor(userDetails.getUser()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } +} @GetMapping(value = "/contacts/postCounts") @Operation(summary = "", description = "") From 4c197e55cd285974df5fea1c16d53b3170fa5fb6 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 22:22:32 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat=20:=20mentee=20-=20contact=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=9D=84=20=EC=9C=84=ED=95=9C=20DTO=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 --- .../demo/mentoring/contact/ContactResponse.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 ea139eaa..74923a0c 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -22,6 +22,19 @@ public postCountDTO(int contactCount, int doneCount) { this.doneCount = doneCount; } } + + @Getter @Setter + public static class MenteeContactDTO { + private int postId; + private String title; + private MentorDTO mentor; + + public MenteeContactDTO(MentorPost mentorPost, MentorDTO mentor) { + this.postId = mentorPost.getId(); + this.title = mentorPost.getTitle(); + this.mentor = mentor; + } + } /** * * DTO 담는 순서 From 2630e3320dbc5921ada49517574a04a3df832d51 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:03:02 +0900 Subject: [PATCH 06/12] =?UTF-8?q?fix=20:=20conntectedUser=20=EC=9D=98=20me?= =?UTF-8?q?ntorUserId=20->=20mentorPostId=20=EB=B3=80=EA=B2=BD=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20=EC=BD=94=EB=93=9C=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/mentoring/done/ConnectedUser.java | 10 +++++----- .../example/demo/mentoring/done/DoneJPARepository.java | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) 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 b84ba0c7..a6ff7f78 100644 --- a/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java +++ b/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java @@ -1,6 +1,7 @@ package com.example.demo.mentoring.done; import com.example.demo.config.utils.BaseTime; +import com.example.demo.mentoring.MentorPost; import com.example.demo.user.User; import lombok.AccessLevel; import lombok.Builder; @@ -23,16 +24,15 @@ public class ConnectedUser extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; - @ManyToOne - private User mentorUser; + @ManyToOne(fetch = FetchType.LAZY) + private MentorPost mentorPost; @ManyToOne private User menteeUser; @Builder - public ConnectedUser(int id, User mentorUser, User menteeUser) { - this.id = id; - this.mentorUser = mentorUser; + public ConnectedUser(MentorPost mentorPost, User menteeUser) { + this.mentorPost = mentorPost; this.menteeUser = menteeUser; } 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 ff86e054..ba5c2626 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneJPARepository.java @@ -7,6 +7,5 @@ import java.util.List; public interface DoneJPARepository extends JpaRepository { - @Query("select count(*) from ConnectedUser cu where cu.mentorUser.id = :userId") - int countByMentorId(@Param("userId") int userId); + } From f148c7f95ba006ab9b5599b34c95d755d008db9a Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:04:49 +0900 Subject: [PATCH 07/12] =?UTF-8?q?fix=20:=20mentorPost=20=EA=B0=84=20?= =?UTF-8?q?=EA=B4=80=EA=B3=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/mentoring/contact/NotConnectedRegisterUser.java | 5 ++--- 1 file changed, 2 insertions(+), 3 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 1ed18dfb..94014f15 100644 --- a/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java +++ b/src/main/java/com/example/demo/mentoring/contact/NotConnectedRegisterUser.java @@ -24,7 +24,7 @@ public class NotConnectedRegisterUser extends BaseTime { @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; - @OneToOne(fetch = FetchType.LAZY) + @ManyToOne(fetch = FetchType.LAZY) private MentorPost mentorPost; @ManyToOne(fetch = FetchType.LAZY) @@ -39,8 +39,7 @@ public enum State { } @Builder - public NotConnectedRegisterUser(int id, MentorPost mentorPost, User menteeUser, State state) { - this.id = id; + public NotConnectedRegisterUser(MentorPost mentorPost, User menteeUser, State state) { this.mentorPost = mentorPost; this.menteeUser = menteeUser; this.state = state; From 93740aab4df87195dbda207bac5b2c0b2bb44f62 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:05:41 +0900 Subject: [PATCH 08/12] =?UTF-8?q?fix=20:=20Lazy=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/mentoring/done/ConnectedUser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a6ff7f78..010926e5 100644 --- a/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java +++ b/src/main/java/com/example/demo/mentoring/done/ConnectedUser.java @@ -27,7 +27,7 @@ public class ConnectedUser extends BaseTime { @ManyToOne(fetch = FetchType.LAZY) private MentorPost mentorPost; - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) private User menteeUser; @Builder From 78b86147f474f5233fde1187f39b74e335ab987c Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:06:14 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat=20:=20=EB=A9=98=ED=86=A0,=20?= =?UTF-8?q?=EB=A9=98=ED=8B=B0=20contact=20=ED=99=94=EB=A9=B4=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=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 --- .../mentoring/MentorPostJPARepostiory.java | 11 ++- .../contact/ContactRestController.java | 6 +- .../mentoring/contact/ContactService.java | 89 +++++++++---------- 3 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index ceefeb24..74b95746 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -2,7 +2,6 @@ import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -15,6 +14,12 @@ public interface MentorPostJPARepostiory extends JpaRepository findAllByMenteeUserId(@Param("menteeUserId") int menteeUserId); } 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 4f9b4e9d..4470be70 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -22,13 +22,13 @@ public class ContactRestController { @Operation(summary = "", description = "") public ResponseEntity findAll(@AuthenticationPrincipal CustomUserDetails userDetails) { if ( userDetails.getUser().getRole() == Role.MENTEE ) { - List responseDTO = contactService.findAllByMentee(userDetails.getUser()); + List responseDTO = contactService.findAllByMentee(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - List responseDTO = contactService.findAllByMentor(userDetails.getUser()); + List responseDTO = contactService.findAllByMentor(userDetails.getUser().getId()); return ResponseEntity.ok(ApiUtils.success(responseDTO)); } -} + @GetMapping(value = "/contacts/postCounts") @Operation(summary = "", description = "") 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 b9e1f6f3..ab36bcef 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -2,9 +2,7 @@ import com.example.demo.mentoring.MentorPost; import com.example.demo.mentoring.MentorPostJPARepostiory; -import com.example.demo.mentoring.done.ConnectedUser; 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; @@ -13,7 +11,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -22,59 +19,57 @@ @Service public class ContactService { - private final MentorPostJPARepostiory mentorPostJPARepostiory; + private final MentorPostJPARepostiory mentorPostJPARepository; private final UserJPARepository userJPARepository; private final ContactJPARepository contactJPARepository; private final UserInterestJPARepository userInterestJPARepository; private final DoneJPARepository doneJPARepository; /** - * findAll : dashboard - contact 부분 화면에 필요한 DTO를 응답해주는 함수 - * parameter : Account ( 유저의 계정 ) + * contact - mentee 화면에서 mentor 가 작성한 글에 신청을 누른 게시글들을 가져오는 함수 * **/ - public List findAll(int id) { - /** - * 흐름 ( 멘토 입장 ) - * 1. 내가 작성한 게시글 ( mentorPosts ) 들을 조회해서 가져온다. - * 2. 멘토의 정보는 mentorPosts 와 별개로 한번에 조회되는 값이니, for문 밖으로 빼서 조회한다. - * - 멘토의 정보를 만들기 위해 필요한 값 : mentor 의 user, mentor 의 interests - * - user 는 조회하면 되니, 바로 구할 수 있다. - * - userInterest 에서 멘토의 interest 값들을 가져올 수 있기 때문에, userInterest 와 interest 를 join 후 tag 들을 가져온다. - * 3. mentorPosts 를 활용하여 for문을 돌면서 mentorPost 1개 + mentor 정보 1개 + mentee 정보 여러개 의 꼴로 DTO 를 만든다. - * - mentee 의 정보를 만들기 위해 필요한 값 : notConnectedRegisterUser 에서 mentee 의 정보, mentee 의 interests - * - 신청한 멘티들의 정보를 가져오기 위해 notConnectedRegisterUser 의 테이블과 , 각 멘티에 해당하는 interests 들을 묶어서 DTO 로 만들기 ( 그래서 List 를 만듬 ) - * - 싹다 묶어서 reponseDTOs 로 전달 - * **/ - // Return 할 객체 - List responseDTOs = new ArrayList<>(); - - // 멘토의 id 에 해당하는 mentorPost 다 가져오기 - List mentorPosts = mentorPostJPARepostiory.findAllByWriter(id); - - // 멘토 정보 가져오기 ( 나중에 User 로 바꿔야 함 ) - User mentorUser = userJPARepository.findById(id); - // List 가져오기 ( 멘토꺼 tag 목록 ) + public List findAllByMentee(int userId) { + + return mentorPostJPARepository.findAllByMenteeUserId(userId).stream() + .map(this::createMenteeContactDTO) + .collect(Collectors.toList()); + } + + // contact - mentee 부분 리팩토링 ( DTO 를 만드는 부분 ) + private ContactResponse.MenteeContactDTO createMenteeContactDTO(MentorPost mentorPost) { + User mentorUser = userJPARepository.findById(mentorPost.getWriter().getId()); List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); - // MentorDTO 담기 ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); - // 만약 3개의 글을 썼을 경우, 현재 mentorPosts 에는 3개의 글 목록이 존재함 - for ( MentorPost mentorPost : mentorPosts ) { - // List 만들기 - // 신청한 멘티의 목록 ( postId 로 조회 ) - List mentees = contactJPARepository.findAllByMentorPostId(mentorPost.getId()); - - // List 생성 - List menteeDTOs = mentees - .stream() - .map(this::createMenteeDTO) - .collect(Collectors.toList()); - // responseDTO 에 담기 - responseDTOs.add(new ContactResponse.MentorPostDTO(mentorPost, mentorDTO, menteeDTOs)); - - } - return responseDTOs; + return new ContactResponse.MenteeContactDTO(mentorPost, mentorDTO); + } + + // --------------------------------------------------------------------------------------------- + + /** + * contact - mentor 화면에서 post 와 mentee 간 엮인 정보들을 조회해서 가져오는 함수 + * **/ + public List findAllByMentor(int userId) { + + User mentorUser = userJPARepository.findById(userId); + List mentorInterests = userInterestJPARepository.findAllById(mentorUser.getId()); + ContactResponse.MentorDTO mentorDTO = new ContactResponse.MentorDTO(mentorUser, mentorInterests); + + return mentorPostJPARepository.findAllByWriter(userId).stream() + .map(mentorPost -> createMentorPostDTO(mentorPost, mentorDTO)) + .collect(Collectors.toList()); + + } + + // MentorPostDTO 생성 로직 + private ContactResponse.MentorPostDTO createMentorPostDTO(MentorPost mentorPost, ContactResponse.MentorDTO mentorDTO) { + List menteeDTOs = contactJPARepository.findAllByMentorPostId(mentorPost.getId()) + .stream() + .map(this::createMenteeDTO) + .collect(Collectors.toList()); + + return new ContactResponse.MentorPostDTO(mentorPost, mentorDTO, menteeDTOs); } // 매핑 로직 분리 ( menteeDTO 생성 로직 ) @@ -89,9 +84,9 @@ private ContactResponse.MenteeDTO createMenteeDTO(NotConnectedRegisterUser mente // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 public ContactResponse.postCountDTO postCountsByMentor(int userId) { // contact 화면에서 게시글을 조회 ( 나중에 where 조건에 state 를 달아야 함 ) - int contactCount = mentorPostJPARepostiory.countByMentorId(userId); + int contactCount = mentorPostJPARepository.countContactByMentorId(userId); // done 화면에서 게시글을 조회 - int doneCount = doneJPARepository.countByMentorId(userId); + int doneCount = mentorPostJPARepository.countDoneByMentorId(userId); return new ContactResponse.postCountDTO(contactCount, doneCount); } From 1f3931d3e2472551e9526a78a84399643cf54415 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:06:39 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat=20:=20connectedUser=20table=20?= =?UTF-8?q?=EC=97=90=20=EB=8D=94=EB=AF=B8=EB=8D=B0=EC=9D=B4=ED=84=B0=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 --- src/main/resources/db/teardown.sql | 41 +++++++++++++++--------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/main/resources/db/teardown.sql b/src/main/resources/db/teardown.sql index f20d62d4..76d0c4a3 100644 --- a/src/main/resources/db/teardown.sql +++ b/src/main/resources/db/teardown.sql @@ -24,35 +24,34 @@ INSERT INTO interest_tb (created_at, category) VALUES (NOW(), 'Sports'); -- mentorPost Table -INSERT INTO mentor_post_tb (created_at, writer_id, title, content) VALUES - (NOW(), 1, 'Teaching Programming', 'I can teach you how to code.'), - (NOW(), 1, 'Art Workshop', 'Let''s create beautiful art together.'), - (NOW(), 2, 'Software Development Mentorship', 'I can mentor you in software development.'), - (NOW(), 2, 'Art and Painting Mentorship', 'Learn the art of painting with me.'), - (NOW(), 1, 'Web Development Mentorship', 'I can teach you web development from scratch.'), - (NOW(), 2, 'Fitness and Health Mentorship', 'Get in shape and stay healthy with my guidance.'), - (NOW(), 1, 'Data Science Mentorship', 'Learn data science and machine learning with me.'), - (NOW(), 2, 'Music Production Mentorship', 'Produce your own music with professional tips.'), - (NOW(), 2, 'Cooking and Culinary Arts Mentorship', 'Master the art of cooking and culinary skills.'), - (NOW(), 2, 'Entrepreneurship Mentorship', 'Start and grow your own business.'), - (NOW(), 1, 'Graphic Design Mentorship', 'Create stunning graphics and designs.'), - (NOW(), 1, 'Yoga and Mindfulness Mentorship', 'Find inner peace and balance through yoga.'), - (NOW(), 1, 'Photography Mentorship', 'Capture amazing moments with your camera.'), - (NOW(), 2, 'Mathematics Tutoring', 'I can help you understand and excel in math.'); +INSERT INTO mentor_post_tb (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'), + (NOW(), 2, 'Art and Painting Mentorship', 'Learn the art of painting with me.', 'ACTIVE'), + (NOW(), 1, 'Web Development Mentorship', 'I can teach you web development from scratch.', 'ACTIVE'), + (NOW(), 2, 'Fitness and Health Mentorship', 'Get in shape and stay healthy with my guidance.', 'ACTIVE'), + (NOW(), 1, 'Data Science Mentorship', 'Learn data science and machine learning with me.', 'ACTIVE'), + (NOW(), 2, 'Music Production Mentorship', 'Produce your own music with professional tips.', 'ACTIVE'), + (NOW(), 2, 'Cooking and Culinary Arts Mentorship', 'Master the art of cooking and culinary skills.', 'ACTIVE'), + (NOW(), 2, 'Entrepreneurship Mentorship', 'Start and grow your own business.', 'ACTIVE'), + (NOW(), 1, 'Graphic Design Mentorship', 'Create stunning graphics and designs.', 'ACTIVE'), + (NOW(), 1, 'Yoga and Mindfulness Mentorship', 'Find inner peace and balance through yoga.', 'ACTIVE'), + (NOW(), 1, 'Photography Mentorship', 'Capture amazing moments with your camera.', 'ACTIVE'), + (NOW(), 2, 'Mathematics Tutoring', 'I can help you understand and excel in math.', 'ACTIVE'); -- notConnectedRegisterUser Table INSERT INTO not_connected_register_user_tb (created_at, mentor_post_id, mentee_user_id, state) VALUES (NOW(), 1, 3, 'AWAIT'), (NOW(), 1, 4, 'ACCEPT'), - (NOW(), 2, 5, 'AWAIT'); + (NOW(), 3, 5, 'AWAIT'); -- connectedUser Table -INSERT INTO connected_user_tb (created_at, mentor_user_id, mentee_user_id) -VALUES - (NOW(), 1, 5), - (NOW(), 1, 6), - (NOW(), 2, 3); +INSERT INTO connected_user_tb (created_at, mentor_post_id, mentee_user_id) VALUES + (NOW(), 2, 3), + (NOW(), 2, 5), + (NOW(), 2, 6); -- userInterest Table INSERT INTO user_interest_tb (created_at, user_id, interest_id) VALUES From 02edc88304237dbd31f1b1c3459ebcde6238bc18 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:12:07 +0900 Subject: [PATCH 11/12] =?UTF-8?q?fix=20:=20mentor=20=EA=B8=B0=EC=A4=80=20c?= =?UTF-8?q?ontact=20=ED=99=94=EB=A9=B4=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/mentoring/MentorPostJPARepostiory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index 74b95746..8e7579ff 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -9,7 +9,7 @@ public interface MentorPostJPARepostiory extends JpaRepository { - @Query("select m from MentorPost m where m.writer.id = :writer") + @Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'ACTIVE'") List findAllByWriter(@Param("writer") int writer); MentorPost findById(int id); From 312e155e7e65137b8d2872918e593cc20676e9a0 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Thu, 12 Oct 2023 23:25:30 +0900 Subject: [PATCH 12/12] =?UTF-8?q?fix=20:=20=EC=97=90=EB=84=88=ED=85=8C?= =?UTF-8?q?=EC=9D=B4=EC=85=98=20=EC=86=8D=20=EC=BD=94=EB=93=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 --- .../demo/mentoring/contact/NotConnectedRegisterUser.java | 2 +- 1 file changed, 1 insertion(+), 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 94014f15..c1e686f0 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_user SET deleted_at = CURRENT_TIMESTAMP, isDeleted = TRUE where id = ?") +@SQLDelete(sql = "UPDATE not_connected_register_user_tb SET deleted_at = CURRENT_TIMESTAMP, isDeleted = TRUE where id = ?") @Table(name = "notConnectedRegisterUser_tb") public class NotConnectedRegisterUser extends BaseTime {