From 816bdf61ba8ed2a28fab80fe32b074739ea81c50 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Tue, 7 Nov 2023 17:20:38 +0900 Subject: [PATCH 01/26] =?UTF-8?q?fix=20:=20testcode=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/main/resources/db/teardown.sql | 14 ++++++++------ src/test/java/com/example/demo/contactTest.java | 16 ++++++++-------- src/test/java/com/example/demo/doneTest.java | 4 ++-- .../demo/mentoringtest/MentoringTest2.java | 8 ++++---- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/main/resources/db/teardown.sql b/src/main/resources/db/teardown.sql index 6d7b49ae..9d62b99f 100644 --- a/src/main/resources/db/teardown.sql +++ b/src/main/resources/db/teardown.sql @@ -9,12 +9,14 @@ SET REFERENTIAL_INTEGRITY TRUE; -- user Table INSERT INTO users (created_at, first_name, last_name, email, password, country, introduction, birth_date, profile_image, role, phone) VALUES - (NOW(), 'John', 'Doe', 'john@example.com', '{bcrypt}$2a$10$...', 'USA', 'Hello, I am John.', '1998-01-01', 'profile.jpg', 'MENTOR', '010-0000-0000'), - (NOW(), 'Alice', 'Smith', 'alice.smith@example.com', '{bcrypt}$2a$10$...', 'Canada', 'I love painting.', '1998-01-01', 'image2.jpg', 'MENTOR', '010-0000-0000'), - (NOW(), 'Admin', 'Admin', 'admin@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am an admin user.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), - (NOW(), 'Jane', 'Smith', 'jane@example.com', '{bcrypt}$2a$10$...', 'Canada', 'I love coding.', '1993-01-01', 'profile.jpg', 'MENTEE', '010-0000-0000'), - (NOW(), 'Admin', 'Adminson', 'admin22222@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the admin.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), - (NOW(), 'Adminnnn', 'Adminsonnnnn', 'admin33333@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the admin.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'); + (NOW(), 'John', 'Doe', 'test1@example.com', '{bcrypt}$2a$10$...', 'USA', 'Hello, I am John.', '1998-01-01', 'profile.jpg', 'MENTOR', '010-0000-0000'), + (NOW(), 'Alice', 'Smith', 'test2@example.com', '{bcrypt}$2a$10$...', 'Canada', 'I love painting.', '1998-01-01', 'image2.jpg', 'MENTOR', '010-0000-0000'), + (NOW(), 'Admin', 'Admin', 'test3@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am an admin user.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'Jane', 'Smith', 'test4@example.com', '{bcrypt}$2a$10$...', 'Canada', 'I love coding.', '1993-01-01', 'profile.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'Adccczczmin', 'qwdasd', 'test5@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the qwdad.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'adadad', 'adaddddd', 'test6@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the adadad.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), +(NOW(), 'admin', 'admin', 'admin@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the admin.', '1988-01-01', 'admin.jpg', 'ADMIN', '010-0000-0000'); + -- interst Table INSERT INTO interests (created_at, category) VALUES (NOW(), 'IDOL'), diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 8f73b27f..65c704cc 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -39,7 +39,7 @@ public class contactTest extends RestDoc { private DoneJPARepository doneJPARepository; @Test - @WithUserDetails("admin@example.com") + @WithUserDetails("test3@example.com") @DisplayName("멘티 기준 화면 조회 테스트 코드") void contactMenteeTest() throws Exception { // given @@ -58,7 +58,7 @@ void contactMenteeTest() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("멘토 기준 화면 조회 테스트 코드") void contactMentorTest() throws Exception { @@ -79,7 +79,7 @@ void contactMentorTest() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("멘토 기준 게시글 갯수 조회 테스트 코드") void countTest() throws Exception { @@ -97,7 +97,7 @@ void countTest() throws Exception { } @Test - @WithUserDetails("admin@example.com") + @WithUserDetails("test3@example.com") @DisplayName("멘티 기준 게시글 조회 테스트 코드") void countByMenteeTest() throws Exception { // given @@ -116,7 +116,7 @@ void countByMenteeTest() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("멘토 : 신청 거부 기능 테스트 코드") void contactRefuseTest() throws Exception { // given @@ -155,7 +155,7 @@ void contactRefuseTest() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("멘토 : 신청 수락 테스트 코드") void contactAccpetTest() throws Exception { // given @@ -202,7 +202,7 @@ void contactAccpetTest() throws Exception { } @Test - @WithUserDetails("jane@example.com") + @WithUserDetails("test4@example.com") @DisplayName("멘티 : 신청 생성 테스트 코드") void createTest() throws Exception { // given @@ -238,7 +238,7 @@ void createTest() throws Exception { } @Test - @WithUserDetails("admin@example.com") + @WithUserDetails("test3@example.com") @DisplayName("멘티 : 신청 취소 테스트 코드") void deleteTest() throws Exception { // given diff --git a/src/test/java/com/example/demo/doneTest.java b/src/test/java/com/example/demo/doneTest.java index 9f7d7629..962b49e0 100644 --- a/src/test/java/com/example/demo/doneTest.java +++ b/src/test/java/com/example/demo/doneTest.java @@ -16,7 +16,7 @@ @Sql("classpath:db/teardown.sql") public class doneTest extends RestDoc { @Test - @WithUserDetails("admin@example.com") + @WithUserDetails("test3@example.com") @DisplayName("멘티 기준 화면 조회 테스트 코드") void contactMenteeTest() throws Exception { // given @@ -35,7 +35,7 @@ void contactMenteeTest() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("멘토 기준 화면 조회 테스트 코드") void contactMentorTest() throws Exception { diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java index 2bfdf0dd..5fae30f6 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java @@ -129,7 +129,7 @@ void MentoringTestUpdate() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("게시글 수정 테스트") void MentoringTestDetails() throws Exception { // given @@ -169,7 +169,7 @@ void MentoringTestDetails() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("게시글 삭제 테스트 코드") void MentoringTestDelete() throws Exception { // given @@ -193,7 +193,7 @@ void MentoringTestDelete() throws Exception { } @Test - @WithUserDetails("john@example.com") + @WithUserDetails("test1@example.com") @DisplayName("게시글 Done 테스트 코드") void MentoringTestDone() throws Exception { // given @@ -229,7 +229,7 @@ void MentoringTestDone() throws Exception { } @Test - @WithUserDetails("admin@example.com") + @WithUserDetails("test3@example.com") @DisplayName("멘티가 게시글을 수정하려고 하는 경우 테스트") void MentoringTest2() throws Exception { int pid = 1; From 90bc459048189b60e5c8d2bc016d2aeb37e9aa1b Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Tue, 7 Nov 2023 23:51:04 +0900 Subject: [PATCH 02/26] =?UTF-8?q?fix=20:=20user=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/main/resources/db/teardown.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/resources/db/teardown.sql b/src/main/resources/db/teardown.sql index 9d62b99f..3cd65337 100644 --- a/src/main/resources/db/teardown.sql +++ b/src/main/resources/db/teardown.sql @@ -9,13 +9,13 @@ SET REFERENTIAL_INTEGRITY TRUE; -- user Table INSERT INTO users (created_at, first_name, last_name, email, password, country, introduction, birth_date, profile_image, role, phone) VALUES - (NOW(), 'John', 'Doe', 'test1@example.com', '{bcrypt}$2a$10$...', 'USA', 'Hello, I am John.', '1998-01-01', 'profile.jpg', 'MENTOR', '010-0000-0000'), - (NOW(), 'Alice', 'Smith', 'test2@example.com', '{bcrypt}$2a$10$...', 'Canada', 'I love painting.', '1998-01-01', 'image2.jpg', 'MENTOR', '010-0000-0000'), - (NOW(), 'Admin', 'Admin', 'test3@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am an admin user.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), - (NOW(), 'Jane', 'Smith', 'test4@example.com', '{bcrypt}$2a$10$...', 'Canada', 'I love coding.', '1993-01-01', 'profile.jpg', 'MENTEE', '010-0000-0000'), - (NOW(), 'Adccczczmin', 'qwdasd', 'test5@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the qwdad.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), - (NOW(), 'adadad', 'adaddddd', 'test6@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the adadad.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), -(NOW(), 'admin', 'admin', 'admin@example.com', '{bcrypt}$2a$10$...', 'USA', 'I am the admin.', '1988-01-01', 'admin.jpg', 'ADMIN', '010-0000-0000'); + (NOW(), 'John', 'Doe', 'test1@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'Hello, I am John.', '1998-01-01', 'profile.jpg', 'MENTOR', '010-0000-0000'), + (NOW(), 'Alice', 'Smith', 'test2@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'Canada', 'I love painting.', '1998-01-01', 'image2.jpg', 'MENTOR', '010-0000-0000'), + (NOW(), 'Admin', 'Admin', 'test3@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am an admin user.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'Jane', 'Smith', 'test4@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'Canada', 'I love coding.', '1993-01-01', 'profile.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'Adccczczmin', 'qwdasd', 'test5@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am the qwdad.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'adadad', 'adaddddd', 'test6@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am the adadad.', '1988-01-01', 'admin.jpg', 'MENTEE', '010-0000-0000'), + (NOW(), 'admin', 'admin', 'admin@example.com', '{bcrypt}$2a$10$8H0OT8wgtALJkig6fmypi.Y7jzI5Y7W9PGgRKqnVeS2cLWGifwHF2', 'USA', 'I am the admin.', '1988-01-01', 'admin.jpg', 'ADMIN', '010-0000-0000'); -- interst Table INSERT INTO interests (created_at, category) VALUES From 946fdeb129b7fb3eabf70032841410b6ef4b14af Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Tue, 7 Nov 2023 23:52:14 +0900 Subject: [PATCH 03/26] =?UTF-8?q?feat=20:=20swagger=20jwt=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EC=9D=B4=EC=83=81=ED=95=9C=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=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 --- .../demo/config/swagger/SwaggerConfig.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/demo/config/swagger/SwaggerConfig.java b/src/main/java/com/example/demo/config/swagger/SwaggerConfig.java index 2859ddda..5f5969eb 100644 --- a/src/main/java/com/example/demo/config/swagger/SwaggerConfig.java +++ b/src/main/java/com/example/demo/config/swagger/SwaggerConfig.java @@ -1,17 +1,21 @@ package com.example.demo.config.swagger; +import com.example.demo.config.auth.CustomUserDetails; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.bind.annotation.RestController; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.service.Contact; +import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; +import java.util.Arrays; +import java.util.List; + @Configuration public class SwaggerConfig { private static final String SERVICE_NAME = "Garden"; @@ -21,13 +25,31 @@ public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2) + .ignoredParameterTypes(CustomUserDetails.class) .apiInfo(apiInfo()) + .securityContexts(Arrays.asList(securityContext())) + .securitySchemes(Arrays.asList(apiKey())) .select() .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class)) - .paths(PathSelectors.any()) + .paths(PathSelectors.regex("/.*")) .build(); } + private ApiKey apiKey() { + return new ApiKey("JWT", "Authorization", "header"); + } + + private SecurityContext securityContext() { + return SecurityContext.builder().securityReferences(defaultAuth()).build(); + } + + private List defaultAuth() { + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + return Arrays.asList(new SecurityReference("JWT", authorizationScopes)); + } + private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(SERVICE_NAME) From 13680bee35ee25e20eb3b34a975d83a3f558b764 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Tue, 7 Nov 2023 23:59:32 +0900 Subject: [PATCH 04/26] =?UTF-8?q?refactor=20:=20mentorpost=20url=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/MentorPostRestController.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java index db11c5e5..23a0e4d0 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java @@ -18,14 +18,14 @@ public class MentorPostRestController { private final MentorPostService mentorPostService; - @PostMapping(value = "/mentorings/post") + @PostMapping(value = "/mentorings") @Operation(summary = "mentorpost 생성") public ResponseEntity createMentorPost(@RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.createMentorPost(requestDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } - @GetMapping("/mentorings/post") + @GetMapping("/mentorings") @Operation(summary = "mentorpost 가져오기", description = "category, search로 필터링, pagination 적용") public ResponseEntity getMentorPost( @RequestParam(value = "category", defaultValue = "NULL") String category, @@ -36,28 +36,28 @@ public ResponseEntity getMentorPost( return ResponseEntity.ok(ApiResponseBuilder.success(responseDTOs)); } - @GetMapping("/mentorings/post/{id}") + @GetMapping("/mentorings/{id}") @Operation(summary = "mentorpost 개별 페이지 불러오기") public ResponseEntity getMentorPostId(@PathVariable int id) { MentorPostResponse.MentorPostDTO responseDTO = mentorPostService.findMentorPost(id); return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } - @PutMapping(value = "/mentorings/post/{id}") + @PutMapping(value = "/mentorings/{id}") @Operation(summary = "mentorpost 수정 요청") public ResponseEntity updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.updateMentorPost(requestDTO, id, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } - @DeleteMapping(value = "/mentorings/post/{id}") + @DeleteMapping(value = "/mentorings/{id}") @Operation(summary = "mentorpost 삭제 요청") public ResponseEntity deleteMentorPost(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.deleteMentorPost(id, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } - @PatchMapping(value = "/mentorings/post/{id}/done") + @PatchMapping(value = "/mentorings/{id}/done") @Operation(summary = "mentorpost 만료 요청") public ResponseEntity changeMentorPostStatus(@PathVariable int id,@RequestBody @Valid MentorPostRequest.StateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.changeMentorPostStatus(requestDTO, id, userDetails.getUser()); From c7e3a6f12a86688d9ce3d9b2ade1985f42843c2a Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 00:20:54 +0900 Subject: [PATCH 05/26] =?UTF-8?q?refactor=20:=20ACTIVE=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=EB=A7=8C=20=EB=82=98=EC=98=A4=EA=B2=8C=EB=81=94=20?= =?UTF-8?q?=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/MentorPostJPARepostiory.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java index 6da3fd3b..495885d6 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostJPARepostiory.java @@ -12,27 +12,46 @@ public interface MentorPostJPARepostiory extends JpaRepository { - @Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'ACTIVE'") + @Query("select m from MentorPost m " + + "where m.writer.id = :writer " + + "and m.state = 'ACTIVE'") List findAllByWriter(@Param("writer") int writer); - @Query("select m from MentorPost m where m.writer.id = :writer and m.state = 'DONE'") + @Query("select m from MentorPost m " + + "where m.writer.id = :writer " + + "and m.state = 'DONE'") List findAllByWriterDone(@Param("writer") int writer); - @Query("select m from MentorPost m where m.title like :keyword") + @Query("select m from MentorPost m where m.title like :keyword " + + "and m.state = 'ACTIVE'") 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") + @Query("select m from MentorPost m " + + "where m.writer.firstName " + + "like :keyword or m.writer.firstName like :keyword " + + "and m.state = 'ACTIVE'") Page findAllByWriterKeyword(@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") + @Query("select m from MentorPost m " + + "inner join UserInterest ui ON m.writer.id = ui.user.id " + + "where ui.interest.category like :keyword " + + "and m.state = 'ACTIVE'") Page findAllByInterestKeyword(@Param("keyword") String keyword, Pageable pageable); + @Query("select m from MentorPost m " + + "where m.state = 'ACTIVE'") + Page findAll(Pageable pageable); + Optional findById(int id); - @Query("select count(*) from MentorPost m where m.writer.id = :userId and m.state = 'ACTIVE'") + @Query("select count(*) from MentorPost m " + + "where m.writer.id = :userId " + + "and m.state = 'ACTIVE'") int countContactByMentorId(int userId); - @Query("select count(*) from MentorPost m where m.writer.id = :userId and m.state = 'DONE'") + @Query("select count(*) from MentorPost m " + + "where m.writer.id = :userId " + + "and m.state = 'DONE'") int countDoneByMentorId(int userId); } From 0d9de10aeab22785fc82b067628f0f2d5ece8328 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 00:52:18 +0900 Subject: [PATCH 06/26] =?UTF-8?q?refactor=20:=20=EC=BF=BC=EB=A6=AC=20?= =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=EB=A1=9C=20id=20=EA=B0=92?= =?UTF-8?q?=EC=9D=84=20=EB=B0=9B=EA=B2=8C=EB=81=94=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 --- .../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 933da7ce..7b11a224 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -74,7 +74,7 @@ public ResponseEntity createContact(@RequestBody @Valid ContactRequest.Contac @DeleteMapping(value = "/contacts") @Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.") - public ResponseEntity deleteContact(@RequestHeader("contactId") List contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity deleteContact(@RequestParam("contactId") List contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 취소 API 로직 만들기 contactService.deleteContact(contactId, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); From d70c91ec3ba46fa2aebc1fdb4f44a578d6b7e2f7 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 01:47:45 +0900 Subject: [PATCH 07/26] =?UTF-8?q?refactor=20:=20mentorpost,=20contact=20re?= =?UTF-8?q?sponse=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/MentorPostResponse.java | 72 +++++++++++------- .../mentoring/contact/ContactResponse.java | 75 ++++++++++--------- .../mentoring/contact/ContactService.java | 8 +- 3 files changed, 88 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostResponse.java b/src/main/java/com/example/demo/mentoring/MentorPostResponse.java index 8458db6d..a33ca0a3 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostResponse.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostResponse.java @@ -28,14 +28,14 @@ public static class MentorPostAllDTO { private int postId; private String title; private String content; - private MentorPostStateEnum mentorPostStateEnum; + private MentorPostStateEnum postState; private WriterDTO writerDTO; public MentorPostAllDTO(MentorPost mentorPost, List userInterests) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.content = mentorPost.getContent(); - this.mentorPostStateEnum = mentorPost.getState(); + this.postState = mentorPost.getState(); WriterDTO writerDTO = new MentorPostAllDTO.WriterDTO(mentorPost.getWriter(), userInterests); this.writerDTO = writerDTO; } @@ -79,31 +79,32 @@ public static class MentorPostDTO { private int postId; private String title; private String content; + private MentorPostStateEnum postState; private WriterDTO writerDTO; - private MentorPostStateEnum mentorPostStateEnum; - private List menteeDTOList; + private List connections; public MentorPostDTO(MentorPost mentorPost, List mentorFavorites, List mentees, List menteeInterest) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); this.content = mentorPost.getContent(); - this.mentorPostStateEnum = mentorPost.getState(); + this.postState = mentorPost.getState(); MentorPostDTO.WriterDTO writerDTO = new MentorPostDTO.WriterDTO(mentorPost.getWriter(), mentorFavorites); this.writerDTO = writerDTO; - List menteeDTOList = mentees.stream() + List connectionDTOList = mentees.stream() .map(mentee -> { List eachMenteeFavorite = menteeInterest.stream().filter( userInterest -> mentee.getMenteeUser().getId() == userInterest.getUser().getId() ).collect(Collectors.toList()); - MentorPostDTO.MenteeDTO menteeDTO = new MentorPostDTO.MenteeDTO(mentee, eachMenteeFavorite); - return menteeDTO; + ConnectionDTO connectionDTO = new ConnectionDTO(mentee, eachMenteeFavorite); + return connectionDTO; }) .collect(Collectors.toList()); - this.menteeDTOList = menteeDTOList; + this.connections = connectionDTOList; } - @Getter @Setter + @Getter + @Setter public static class WriterDTO { private int mentorId; private String profileImage; @@ -124,28 +125,41 @@ public WriterDTO(User user, List userInterests) { } } - @Getter @Setter - public static class MenteeDTO{ - private int menteeId; - private String profileImage; - private String name; - private String country; - private Role role; - private LocalDate birthDate; + @Getter + @Setter + public static class ConnectionDTO { + private int connectionId; private ContactStateEnum state; - private List interests; + private MenteeDTO mentee; - public MenteeDTO(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.role = notConnectedRegisterUser.getMenteeUser().getRole(); - this.birthDate = notConnectedRegisterUser.getMenteeUser().getBirthDate(); + public ConnectionDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { + this.connectionId = notConnectedRegisterUser.getId(); this.state = notConnectedRegisterUser.getState(); - this.interests = userInterests.stream() - .map(userInterest -> userInterest.getInterest().getCategory()) - .collect(Collectors.toList()); + this.mentee = new MenteeDTO(notConnectedRegisterUser.getMenteeUser(), userInterests); + } + + @Getter + @Setter + public static class MenteeDTO { + private int menteeId; + private String profileImage; + private String name; + private String country; + private Role role; + private LocalDate birthDate; + private List interests; + + public MenteeDTO(User menteeUser, List userInterests) { + this.menteeId = menteeUser.getId(); + this.profileImage = menteeUser.getProfileImage(); + this.name = menteeUser.getFirstName() + " " + menteeUser.getLastName(); + this.country = menteeUser.getCountry(); + this.role = menteeUser.getRole(); + this.birthDate = menteeUser.getBirthDate(); + this.interests = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } } } } 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 f996918d..cbf67006 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactResponse.java @@ -28,14 +28,14 @@ public PostCountDTO(int contactCount, int doneCount) { public static class ContactDashBoardMenteeDTO { private int postId; private String title; - private ContactMentorDTO mentor; - private int menteeId; + private ContactMentorDTO writerDTO; + private int connectionId; - public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor, NotConnectedRegisterUser notConnectedRegisterUser) { + public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO writerDTO, NotConnectedRegisterUser notConnectedRegisterUser) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); - this.mentor = mentor; - this.menteeId = notConnectedRegisterUser.getId(); + this.writerDTO = writerDTO; + this.connectionId = notConnectedRegisterUser.getId(); } } /** @@ -51,13 +51,13 @@ public ContactDashBoardMenteeDTO(MentorPost mentorPost, ContactMentorDTO mentor, public static class ContactDashboardMentorDTO { private int postId; private String title; - private ContactMentorDTO mentor; - private List mentees; + private ContactMentorDTO writerDTO; + private List mentees; - public ContactDashboardMentorDTO(MentorPost mentorPost, ContactMentorDTO mentor, List mentees) { + public ContactDashboardMentorDTO(MentorPost mentorPost, ContactMentorDTO writerDTO, List mentees) { this.postId = mentorPost.getId(); this.title = mentorPost.getTitle(); - this.mentor = mentor; + this.writerDTO = writerDTO; this.mentees = mentees; } } @@ -85,34 +85,41 @@ public ContactMentorDTO(User mentor, List userInterests) { } } @Getter @Setter - public static class ContactMenteeDTO { - private int menteeId; - private String profileImage; - private String name; - private String country; - private LocalDate birthDate; - private Role role; + public static class ConnectionDTO { + private int connectionId; private ContactStateEnum state; - private List favorites; // 고민할 부분 : 유저의 favorite List 를 어떻게 가져올 것 인가? - - /** - * 유저의 favorite List 를 가져오기 위해 - * userInterest 를 입력으로 받음 - * userInterest 의 userId 와 현재 신청한 멘티 ( notConnectedRegitserUser ) 의 id 값이 일치하는 경우 - * 그럴 경우에만 tag 값들을 가져오기 - * **/ + private MenteeDTO mentee; - 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.birthDate = notConnectedRegisterUser.getMenteeUser().getBirthDate(); - this.role = notConnectedRegisterUser.getMenteeUser().getRole(); + // ConnectionDTO 생성자 + public ConnectionDTO(NotConnectedRegisterUser notConnectedRegisterUser, List userInterests) { + this.connectionId = notConnectedRegisterUser.getId(); this.state = notConnectedRegisterUser.getState(); - this.favorites = userInterests.stream() - .map(userInterest -> userInterest.getInterest().getCategory()) - .collect(Collectors.toList()); + this.mentee = new MenteeDTO(notConnectedRegisterUser.getMenteeUser(), userInterests); + } + + // MenteeDTO 내부 클래스 + @Getter @Setter + public static class MenteeDTO { + private int menteeId; + private String profileImage; + private String name; + private String country; + private LocalDate birthDate; + private Role role; + private List favorites; + + // MenteeDTO 생성자 + public MenteeDTO(User menteeUser, List userInterests) { + this.menteeId = menteeUser.getId(); + this.profileImage = menteeUser.getProfileImage(); + this.name = menteeUser.getFirstName() + " " + menteeUser.getLastName(); + this.country = menteeUser.getCountry(); + this.birthDate = menteeUser.getBirthDate(); + this.role = menteeUser.getRole(); + this.favorites = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } } } } 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 f377e130..ef90048b 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -64,21 +64,21 @@ public List findAllByMentor(User ment // MentorPostDTO 생성 로직 private ContactResponse.ContactDashboardMentorDTO createMentorPostDTO(MentorPost mentorPost, ContactResponse.ContactMentorDTO contactMentorDTO) { - List contactMenteeDTOS = contactJPARepository.findAllByMentorPostId(mentorPost.getId()) + List connectionDTOS = contactJPARepository.findAllByMentorPostId(mentorPost.getId()) .stream() .map(this::createMenteeDTO) .collect(Collectors.toList()); - return new ContactResponse.ContactDashboardMentorDTO(mentorPost, contactMentorDTO, contactMenteeDTOS); + return new ContactResponse.ContactDashboardMentorDTO(mentorPost, contactMentorDTO, connectionDTOS); } // 매핑 로직 분리 ( menteeDTO 생성 로직 ) - private ContactResponse.ContactMenteeDTO createMenteeDTO(NotConnectedRegisterUser contactUser) { + private ContactResponse.ConnectionDTO createMenteeDTO(NotConnectedRegisterUser contactUser) { List menteeInterests = userInterestJPARepository .findAllById(contactUser.getMenteeUser().getId()); - return new ContactResponse.ContactMenteeDTO(contactUser, menteeInterests); + return new ContactResponse.ConnectionDTO(contactUser, menteeInterests); } // contact, done 화면에서 게시글을 조회해서 갯수를 전달해주는 함수 From b2cf481d98b30a5f4a1a84ffd60f363961470028 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 01:52:26 +0900 Subject: [PATCH 08/26] =?UTF-8?q?refactor=20:=20request=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 --- .../example/demo/mentoring/MentorPostRequest.java | 2 +- .../demo/mentoring/MentorPostRestController.java | 4 ++-- .../example/demo/mentoring/MentorPostService.java | 12 ++++++------ .../demo/mentoring/contact/ContactRequest.java | 12 ++++++------ .../demo/mentoring/contact/ContactService.java | 4 ++-- .../example/demo/mentoringtest/MentoringTest2.java | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRequest.java b/src/main/java/com/example/demo/mentoring/MentorPostRequest.java index a2fd23c9..0cc83443 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRequest.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRequest.java @@ -8,7 +8,7 @@ public class MentorPostRequest { @Getter @Setter - public static class CreateDTO { + public static class CreateMentorPostDTO { @NotNull private String title; diff --git a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java index 23a0e4d0..e3aae5f7 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostRestController.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostRestController.java @@ -20,7 +20,7 @@ public class MentorPostRestController { @PostMapping(value = "/mentorings") @Operation(summary = "mentorpost 생성") - public ResponseEntity createMentorPost(@RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity createMentorPost(@RequestBody @Valid MentorPostRequest.CreateMentorPostDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.createMentorPost(requestDTO, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } @@ -45,7 +45,7 @@ public ResponseEntity getMentorPostId(@PathVariable int id) { @PutMapping(value = "/mentorings/{id}") @Operation(summary = "mentorpost 수정 요청") - public ResponseEntity updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity updateMentorPost(@PathVariable int id, @RequestBody @Valid MentorPostRequest.CreateMentorPostDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { mentorPostService.updateMentorPost(requestDTO, id, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } diff --git a/src/main/java/com/example/demo/mentoring/MentorPostService.java b/src/main/java/com/example/demo/mentoring/MentorPostService.java index a86aac5a..91114002 100644 --- a/src/main/java/com/example/demo/mentoring/MentorPostService.java +++ b/src/main/java/com/example/demo/mentoring/MentorPostService.java @@ -30,17 +30,17 @@ public class MentorPostService { //mentorPost생성 @Transactional - public void createMentorPost(MentorPostRequest.CreateDTO createDTO, User writer) { + public void createMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorPostDTO, User writer) { if ( writer.getRole() == Role.MENTEE ) { throw new Exception401("해당 사용자는 멘티입니다."); } //글자수 확인 - if(createDTO.getContent().length() > 300){ + if(createMentorPostDTO.getContent().length() > 300){ throw new Exception404("글자수가 300자를 넘어갑니다."); } - MentorPost mentorPost = new MentorPost( writer, createDTO.getTitle(), createDTO.getContent()); + MentorPost mentorPost = new MentorPost( writer, createMentorPostDTO.getTitle(), createMentorPostDTO.getContent()); try { mentorPostJPARepository.save(mentorPost); @@ -87,19 +87,19 @@ public MentorPostResponse.MentorPostDTO findMentorPost(int id){ return mentorPostDTO; } @Transactional - public void updateMentorPost(MentorPostRequest.CreateDTO createDTO, int id, User writer) { + public void updateMentorPost(MentorPostRequest.CreateMentorPostDTO createMentorPostDTO, int id, User writer) { isMentor(writer); MentorPost mentorPost = mentorPostJPARepository.findById(id). orElseThrow(() -> new Exception404("해당 글이 존재하지 않습니다.")); //글자수 확인 - if(createDTO.getContent().length() > 300){ + if(createMentorPostDTO.getContent().length() > 300){ throw new Exception404("글자수가 300자를 넘어갑니다."); } try { - mentorPost.update(createDTO.getTitle(), createDTO.getContent()); + mentorPost.update(createMentorPostDTO.getTitle(), createMentorPostDTO.getContent()); } catch (Exception e) { throw new Exception500("unknown server error"); } 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 51cb056c..12bc6c2b 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRequest.java @@ -24,9 +24,9 @@ public static class ContactRefuseDTO { @Getter @Setter @NoArgsConstructor public static class RefuseMenteeDTO { @NotNull - private int menteeId; - public RefuseMenteeDTO(int menteeId) { - this.menteeId = menteeId; + private int connectionId; + public RefuseMenteeDTO(int connectionId) { + this.connectionId = connectionId; } } } @@ -39,9 +39,9 @@ public static class ContactAcceptDTO { @Getter @Setter @NoArgsConstructor public static class AcceptMenteeDTO { @NotNull - private int menteeId; - public AcceptMenteeDTO(int menteeId) { - this.menteeId = menteeId; + private int connectionId; + public AcceptMenteeDTO(int connectionId) { + this.connectionId = connectionId; } } } 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 ef90048b..d05a5d9a 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactService.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactService.java @@ -119,7 +119,7 @@ public void acceptContact(ContactRequest.ContactAcceptDTO contactAcceptDTO, User for ( ContactRequest.ContactAcceptDTO.AcceptMenteeDTO acceptMenteeDTO : contactAcceptDTO.getMentees() ) { // notConnectedRegisterUser 의 state 바꾸기 -> ACCEPT - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(acceptMenteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(acceptMenteeDTO.getConnectionId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(ContactStateEnum.ACCEPT); @@ -143,7 +143,7 @@ public void refuseContact(ContactRequest.ContactRefuseDTO contactRefuseDTO, User // notConnectedRegisterUser 의 state 바꾸기 -> REFUSE for ( ContactRequest.ContactRefuseDTO.RefuseMenteeDTO refuseMenteeDTO : contactRefuseDTO.getMentees() ) { - NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(refuseMenteeDTO.getMenteeId()) + NotConnectedRegisterUser notConnectedRegisterUser = contactJPARepository.findById(refuseMenteeDTO.getConnectionId()) .orElseThrow(() -> new Exception404("해당 사용자를 찾을 수 없습니다.")); notConnectedRegisterUser.updateStatus(ContactStateEnum.REFUSE); diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java index 5fae30f6..f2666241 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java @@ -136,7 +136,7 @@ void MentoringTestDetails() throws Exception { int pid = 1; // requestDTO : title, content - MentorPostRequest.CreateDTO requestDTO = new MentorPostRequest.CreateDTO(); + MentorPostRequest.CreateMentorPostDTO requestDTO = new MentorPostRequest.CreateMentorPostDTO(); requestDTO.setTitle("바뀐 제목111"); requestDTO.setContent("바뀐 내용111"); @@ -235,7 +235,7 @@ void MentoringTest2() throws Exception { int pid = 1; // requestDTO : title, content - MentorPostRequest.CreateDTO requestDTO = new MentorPostRequest.CreateDTO(); + MentorPostRequest.CreateMentorPostDTO requestDTO = new MentorPostRequest.CreateMentorPostDTO(); requestDTO.setTitle("바뀐 제목111"); requestDTO.setContent("바뀐 내용111"); From 26053c98818b8ec794e3e9642b9732917fbca933 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 01:59:16 +0900 Subject: [PATCH 09/26] =?UTF-8?q?refactor=20:=20contacts=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20id=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EA=B0=92=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 --- .../example/demo/mentoring/contact/ContactRestController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7b11a224..42fa320d 100644 --- a/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java +++ b/src/main/java/com/example/demo/mentoring/contact/ContactRestController.java @@ -74,9 +74,9 @@ public ResponseEntity createContact(@RequestBody @Valid ContactRequest.Contac @DeleteMapping(value = "/contacts") @Operation(summary = "멘티의 멘토링 신청 취소", description = "멘티는 신청한 멘토링을 취소할 수 있다.") - public ResponseEntity deleteContact(@RequestParam("contactId") List contactId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { + public ResponseEntity deleteContact(@RequestParam("connectionId") List connectionId, Error errors, @AuthenticationPrincipal CustomUserDetails userDetails) { // TO-DO : 멘토링 신청 취소 API 로직 만들기 - contactService.deleteContact(contactId, userDetails.getUser()); + contactService.deleteContact(connectionId, userDetails.getUser()); return ResponseEntity.status(HttpStatus.OK).body(ApiResponseBuilder.successWithNoContent()); } From 1b95b4c4f9ef37672a645adf495e9054d5e29263 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 02:05:19 +0900 Subject: [PATCH 10/26] =?UTF-8?q?refactor=20:=20done=20response=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/done/DoneResponse.java | 48 ++++++++++++------- 1 file changed, 31 insertions(+), 17 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 8e5e6bca..217b55a9 100644 --- a/src/main/java/com/example/demo/mentoring/done/DoneResponse.java +++ b/src/main/java/com/example/demo/mentoring/done/DoneResponse.java @@ -50,26 +50,40 @@ public DoneMentorDTO(User mentor, List userInterests) { .collect(Collectors.toList()); } } - @Getter @Setter + @Getter + @Setter public static class DoneMenteeDTO { - private int menteeId; - private String profileImage; - private String name; - private String country; - private LocalDate birthDate; - private Role role; - private List favorites; + private int doneId; // 이 필드는 사용되지 않는 것으로 보입니다. 필요하다면 추가하십시오. + private MenteeDTO mentee; 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.birthDate = connectedUser.getMenteeUser().getBirthDate(); - this.role = connectedUser.getMenteeUser().getRole(); - this.favorites = userInterests.stream() - .map(userInterest -> userInterest.getInterest().getCategory()) - .collect(Collectors.toList()); + this.doneId = connectedUser.getId(); + this.mentee = new MenteeDTO(connectedUser, userInterests); + } + + // MenteeDTO 클래스 내부 필드를 직접 사용하지 않고, MenteeDTO 객체를 통해 접근 + @Getter + @Setter + public static class MenteeDTO { + private int menteeId; + private String profileImage; + private String name; + private String country; + private LocalDate birthDate; + private Role role; + private List favorites; + + public MenteeDTO(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.birthDate = connectedUser.getMenteeUser().getBirthDate(); + this.role = connectedUser.getMenteeUser().getRole(); + this.favorites = userInterests.stream() + .map(userInterest -> userInterest.getInterest().getCategory()) + .collect(Collectors.toList()); + } } } } From fc050110feee5ce17d036e7793949a17d433ca01 Mon Sep 17 00:00:00 2001 From: Jin_00 Date: Wed, 8 Nov 2023 02:20:27 +0900 Subject: [PATCH 11/26] =?UTF-8?q?test=20:=20=EC=BD=94=EB=93=9C=EC=88=98?= =?UTF-8?q?=EC=A0=95=EC=97=90=20=EB=94=B0=EB=A5=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=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 --- .../java/com/example/demo/contactTest.java | 4 +++- .../demo/mentoringtest/MentoringTest2.java | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/example/demo/contactTest.java b/src/test/java/com/example/demo/contactTest.java index 65c704cc..fe444c92 100644 --- a/src/test/java/com/example/demo/contactTest.java +++ b/src/test/java/com/example/demo/contactTest.java @@ -18,6 +18,7 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; @@ -242,11 +243,12 @@ void createTest() throws Exception { @DisplayName("멘티 : 신청 취소 테스트 코드") void deleteTest() throws Exception { // given + List connectionIds = Arrays.asList(1, 2); // 실제로 취소할 연결 ID 목록 // when ResultActions result = mvc.perform( MockMvcRequestBuilders.delete("/contacts") - .header("contactId", 1,2) + .param("connectionId", connectionIds.stream().map(String::valueOf).toArray(String[]::new)) // 정수 목록을 문자열 배열로 변환 .contentType(MediaType.APPLICATION_JSON) ); String responseBody = result.andReturn().getResponse().getContentAsString(); diff --git a/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java b/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java index f2666241..60c3d627 100644 --- a/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java +++ b/src/test/java/com/example/demo/mentoringtest/MentoringTest2.java @@ -37,7 +37,7 @@ void MentoringTestByMentor() throws Exception { // when ResultActions resultActions = mvc.perform( - get("/mentorings/post") + get("/mentorings") ); // console @@ -55,7 +55,7 @@ void MentoringTestByCategoryTitle() throws Exception { // when ResultActions resultActions = mvc.perform( - get("/mentorings/post") + get("/mentorings") .param("category", "TITLE") .param("search", "Teaching") ); @@ -75,7 +75,7 @@ void MentoringTestByCategoryWriter() throws Exception { // when ResultActions resultActions = mvc.perform( - get("/mentorings/post") + get("/mentorings") .param("category", "WRITER") .param("search", "John") ); @@ -95,7 +95,7 @@ void MentoringTestByCategoryInterest() throws Exception { // when ResultActions resultActions = mvc.perform( - get("/mentorings/post") + get("/mentorings") .param("category", "INTEREST") .param("search", "K-POP") ); @@ -116,7 +116,7 @@ void MentoringTestUpdate() throws Exception { // when ResultActions resultActions = mvc.perform( - get("/mentorings/post/" + id) + get("/mentorings/" + id) ); // console @@ -146,7 +146,7 @@ void MentoringTestDetails() throws Exception { // when ResultActions resultActions = mvc.perform( - put("/mentorings/post/" + pid) + put("/mentorings/" + pid) .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); @@ -177,7 +177,7 @@ void MentoringTestDelete() throws Exception { // when ResultActions resultActions = mvc.perform( - delete("/mentorings/post/" + pid) + delete("/mentorings/" + pid) ); // console @@ -208,7 +208,7 @@ void MentoringTestDone() throws Exception { // when ResultActions resultActions = mvc.perform( - patch("/mentorings/post/" + pid + "/done") + patch("/mentorings/" + pid + "/done") .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); @@ -245,7 +245,7 @@ void MentoringTest2() throws Exception { // when ResultActions resultActions = mvc.perform( - put("/mentorings/post/" + pid) + put("/mentorings/" + pid) .content(requestBody) .contentType(MediaType.APPLICATION_JSON) ); From facc74ecfc0373c7f42582cd84fe00bc70fcf625 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Wed, 8 Nov 2023 10:35:37 +0900 Subject: [PATCH 12/26] fix : findVideo by Id credential delete --- .../java/com/example/demo/video/VideoRestController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/demo/video/VideoRestController.java b/src/main/java/com/example/demo/video/VideoRestController.java index 095fdaaf..f5ac475f 100644 --- a/src/main/java/com/example/demo/video/VideoRestController.java +++ b/src/main/java/com/example/demo/video/VideoRestController.java @@ -2,6 +2,7 @@ import com.example.demo.config.auth.CustomUserDetails; import com.example.demo.config.utils.ApiResponseBuilder; +import com.example.demo.user.User; import io.swagger.annotations.Api; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; @@ -44,8 +45,8 @@ public ResponseEntity getVideoId(@PathVariable int id, @AuthenticationPrincip @GetMapping("/videos/history") @Operation(summary = "영상 시청기록 요청") - public ResponseEntity getVideoHistory(@RequestParam(value = "page", defaultValue = "0") Integer page, @AuthenticationPrincipal CustomUserDetails userDetails) { - List responseDTO = videoService.findHistoryVideo(page, userDetails.getUser().getId()); + public ResponseEntity getVideoHistory(@RequestParam(value = "page", defaultValue = "0") Integer page, User user) { + List responseDTO = videoService.findHistoryVideo(page, user.getId()); return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } From 868b94627ffe6007997ba7aac35b5091161bca05 Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Wed, 8 Nov 2023 11:59:42 +0900 Subject: [PATCH 13/26] fix : authentification --- .../demo/video/VideoRestController.java | 2 +- .../com/example/demo/video/VideoService.java | 9 ++++++++- src/test/java/com/example/demo/VideoTest.java | 18 +----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/example/demo/video/VideoRestController.java b/src/main/java/com/example/demo/video/VideoRestController.java index 095fdaaf..1213e619 100644 --- a/src/main/java/com/example/demo/video/VideoRestController.java +++ b/src/main/java/com/example/demo/video/VideoRestController.java @@ -38,7 +38,7 @@ public ResponseEntity getCategoryFilterVideo(@RequestParam(value = "category" @GetMapping("/videos/{id}") @Operation(summary = "영상 개인페이지 요청") public ResponseEntity getVideoId(@PathVariable int id, @AuthenticationPrincipal CustomUserDetails userDetails) { - VideoResponse.VideoResponseDTO responseDTO = videoService.findVideo(id, userDetails.getUser()); + VideoResponse.VideoResponseDTO responseDTO = videoService.findVideo(id, userDetails); return ResponseEntity.ok(ApiResponseBuilder.success(responseDTO)); } diff --git a/src/main/java/com/example/demo/video/VideoService.java b/src/main/java/com/example/demo/video/VideoService.java index 88fe3554..0702b8e1 100644 --- a/src/main/java/com/example/demo/video/VideoService.java +++ b/src/main/java/com/example/demo/video/VideoService.java @@ -1,5 +1,6 @@ package com.example.demo.video; +import com.example.demo.config.auth.CustomUserDetails; import com.example.demo.config.errors.exception.Exception401; import com.example.demo.config.errors.exception.Exception404; import com.example.demo.interest.Interest; @@ -17,6 +18,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; @Transactional @@ -79,7 +81,12 @@ public List findAllVideo(int categoryId) { return videoPageResponseDTOS; } - public VideoResponse.VideoResponseDTO findVideo(int id, User user) { + public VideoResponse.VideoResponseDTO findVideo(int id, CustomUserDetails customUserDetails) { + + User user = Optional.ofNullable(customUserDetails) + .map(CustomUserDetails::getUser) + .orElse(null); + Video video = videoJPARepository.findById(id) .orElseThrow(() -> new Exception404("해당 영상이 존재하지 않습니다.\n" + "id : " + id)); diff --git a/src/test/java/com/example/demo/VideoTest.java b/src/test/java/com/example/demo/VideoTest.java index f5bc7541..40b6a3af 100644 --- a/src/test/java/com/example/demo/VideoTest.java +++ b/src/test/java/com/example/demo/VideoTest.java @@ -1,5 +1,6 @@ package com.example.demo; +import com.example.demo.config.auth.CustomUserDetails; import com.example.demo.config.errors.exception.Exception404; import com.example.demo.interest.Interest; import com.example.demo.interest.InterestJPARepository; @@ -291,23 +292,6 @@ void findAllTest() throws Exception{ List videoFind = videoService.findAllVideo(0); } - @Test - @Order(2) - void HistoryTest() throws Exception{ - User user2 = User.builder() - .email("anjfffffdal64@gmail.com") - .password("asdf1234!") - .firstName("Jin") - .lastName("Seung") - .country("Korea") - .age(21) - .role(Role.MENTOR) - .phone("010-0000-0000") - .build(); - - userJPARepository.save(user2); - VideoResponse.VideoResponseDTO videoFind = videoService.findVideo(3,user2); - } @Test @Order(2) From 7d8a78d97f2496083a4c8271ffd2c3cc347d8c9a Mon Sep 17 00:00:00 2001 From: sjmjys954646 Date: Wed, 8 Nov 2023 16:32:50 +0900 Subject: [PATCH 14/26] refactor : service refactoring --- .../com/example/demo/video/VideoService.java | 65 ++-- src/main/resources/db/teardown.sql | 31 ++ src/test/java/com/example/demo/VideoTest.java | 359 ++---------------- 3 files changed, 97 insertions(+), 358 deletions(-) diff --git a/src/main/java/com/example/demo/video/VideoService.java b/src/main/java/com/example/demo/video/VideoService.java index 0702b8e1..262ac402 100644 --- a/src/main/java/com/example/demo/video/VideoService.java +++ b/src/main/java/com/example/demo/video/VideoService.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; +import java.util.stream.IntStream; @Transactional @RequiredArgsConstructor @@ -38,16 +39,7 @@ public class VideoService { public List findAllVideo(int categoryId) { Pageable pageable = PageRequest.of(0 ,MAINVIDEOTOTAL); - Page