From d8d2646cd94af376d78013bd6b8398e1f866c1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A4=80=EC=84=9C?= <99449600+adoo24@users.noreply.github.com> Date: Sat, 19 Aug 2023 19:54:46 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Feature:=20#21=20my-manual=20Dto=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 * feature: CharacterSet, Face, Body, Expression 도메인 추가 * feature: Keyword, UserType, UserKeyword 도메인 추가 * feature: Face, Body, Expression show_case, layout_case 분리 * feature: Answer, Comment, Question 도메인 추가 * refactor: 복합키 camel case화, Entity Class 생성자 제한 * feature: 유저 내적나사 service 추가 * fix: user entity에 userType 추가 * fix: keyword Entity에 percent를 origin과 others로 나눔 * feature: 타인이 키워드 퍼센트 기여를 위한 service 수정 및 테스트 * feature: 타적나사를 위한 service 구현 * fix(#17): 충돌 처리 후 에러 해결 * feature(#18): 타적나사 추가, 삭제 서비스 구현 및 테스트 * feature(#19): 프로필 수정 기능 서비스 작성 및 테스트 코드 작성 * feature(#20): 마이페이지 조회 api 구현 * feature(#20): 마이페이지 수정 api 구현 * fix(#20): User에 nickname 추가, profile 별 캐릭터 존재하도록 변경 * feature(#20): 마이페이지 조회, 수정(닉네임, 내적내사), 타인페이지 조회 구현 * feature(#20): 내 사용 설명서 생성 기능 구현 * feature(#20): 캐릭터 수정 기능 구현 * feature(#20): 타적나사 기능 구현 * feature(#20): 모든 캐릭터 가져오기 기능 구현 * feature(#20): 기능 테스트 코드 갖성 * fix(#20): 코멘트가 질문, 유저 별로 여러개 추가될 수 있도록 수정 * fix(#20): 코멘트 수정으로 인한 테스트 코드 수정 * fix(#20): 타적내사 요구사항 반영(response 변경) * fix(#20): 내적나사 post 요구사항 반영(유저 정보 response에 담음) * fix(#20): Entity lazy 로딩 설정 * fix(#20): 컨트롤러에 유저 인증 추가 * fix(#20): 겹치는 dto 수정 및 삭제 * fix(#21): cors에 로컬 환경 추가 * fix(#20): Comment 요구사항 반영(닉네임 추가) * fix(#21): otherManual 요구사항 반영 * fix(#21): post 응답에 userId, userType 추가 * test(#21): 테스트 코드 작성 * fix(#21): 유저타입, 캐릭터 아이템 가져오기 수정 * fix(#34): prod 환경 ddl auto 수정 * fix(#21): 캐릭터 dto 수정 --------- Co-authored-by: lcomment --- .../domain/user/controller/UserController.java | 16 ++++------------ .../java/com/najasin/domain/user/dto/Manual.java | 2 +- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 69bd76f..6deb072 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -56,14 +56,6 @@ public ResponseEntity> logout(@AccessToken String accessToken, @R ); } - @GetMapping("/test") - public String test(@AuthorizeUser User user) { - System.out.println(user.toString()); - System.out.println(user.getId()); - System.out.println(user.getNickname()); - return "test"; - } - @PutMapping("/{userTypeName}/answers") public ResponseEntity> putAnswers( @PathVariable String userTypeName, @@ -161,9 +153,9 @@ public ResponseEntity> getMyManual( Manual manual = new Manual(); String userId = user.getId(); manual.setNickname(user.getNickname()); - manual.setBaseImage("임시 이미지 url"); + manual.setBaseImage("https://picsum.photos/200/300?random=1"); CharacterItems characterInfoDTO = userUserTypeService.getCharacter(userId, userTypeName); - manual.setCharacterItems(characterService.getAllCharacterItems()); + manual.setCharacterItems(characterService.getAllCharacterItems().getCharacterItems()); manual.setQuestions(questionService.getQuestionByQuestionTypeAndUserType(QuestionType.FOR_USER, userTypeName)); return new ResponseEntity<>( ApiResponse.createSuccessWithData(UserResponse.SUCCESS_GET_PAGE.getMessage(), manual), @@ -179,7 +171,7 @@ public ResponseEntity> getOthersPage(@PathVariable String userTyp page.setQuestions(questionService.getQuestionByQuestionTypeAndUserType(QuestionType.FOR_OTHERS, userTypeName)); page.setNickname(user.getNickname()); - page.setBaseImage("임시 베이스 이미지 url"); + page.setBaseImage("https://picsum.photos/200/300?random=1"); CharacterItems characterInfoDTO = userUserTypeService.getCharacter(userId, userTypeName); page.setCharacterItems(new CharacterItems(characterInfoDTO.getFace(), characterInfoDTO.getBody(), characterInfoDTO.getExpression(), characterInfoDTO.getSet())); page.setMyManualQAPair(userUserTypeService.getQAByUserIdAndUserTypeForUser(userId, userTypeName, QuestionType.FOR_USER)); @@ -208,7 +200,7 @@ public ResponseEntity> getMyPage( page.setUserTypes(userTypes); page.setNickname(user.getNickname()); - page.setBaseImage("임시 베이스 이미지 url"); + page.setBaseImage("https://picsum.photos/200/300?random=1"); CharacterItems characterInfoDTO = userUserTypeService.getCharacter(userId, userTypeName); page.setCharacterItems(new CharacterItems(characterInfoDTO.getFace(), characterInfoDTO.getBody(), characterInfoDTO.getExpression(), characterInfoDTO.getSet())); diff --git a/src/main/java/com/najasin/domain/user/dto/Manual.java b/src/main/java/com/najasin/domain/user/dto/Manual.java index df8c4a5..597fb48 100644 --- a/src/main/java/com/najasin/domain/user/dto/Manual.java +++ b/src/main/java/com/najasin/domain/user/dto/Manual.java @@ -16,7 +16,7 @@ public class Manual { private List userTypes; private String nickname; private String baseImage; - private AllCharacterItems characterItems; + private AllCharacterItems.CharacterItems characterItems; private List myManualQAPair; private List othersManualQAPair; private List questions; From bbfdfd774514b9c2027d4923153ea5d8d41a5c52 Mon Sep 17 00:00:00 2001 From: lcomment Date: Sun, 20 Aug 2023 01:37:52 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix(#34):=20my-manual=20=EA=B6=8C=ED=95=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/najasin/config/SecurityConfig.java | 3 ++- .../user/controller/UserController.java | 20 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/najasin/config/SecurityConfig.java b/src/main/java/com/najasin/config/SecurityConfig.java index cf520d7..ce0c25f 100644 --- a/src/main/java/com/najasin/config/SecurityConfig.java +++ b/src/main/java/com/najasin/config/SecurityConfig.java @@ -60,7 +60,8 @@ private Customizer.AuthorizationMa new AntPathRequestMatcher("/success/**"), new AntPathRequestMatcher("/api/auth"), new AntPathRequestMatcher("/auth2/**"), - new AntPathRequestMatcher("/login/**") + new AntPathRequestMatcher("/login/**"), + new AntPathRequestMatcher("/api/*/my-manual", "GET") ).permitAll() .requestMatchers(new AntPathRequestMatcher("/api/**")).hasAnyRole("ADMIN", "MEMBER") .anyRequest().authenticated(); diff --git a/src/main/java/com/najasin/domain/user/controller/UserController.java b/src/main/java/com/najasin/domain/user/controller/UserController.java index 6deb072..6d842ab 100644 --- a/src/main/java/com/najasin/domain/user/controller/UserController.java +++ b/src/main/java/com/najasin/domain/user/controller/UserController.java @@ -1,5 +1,7 @@ package com.najasin.domain.user.controller; +import static java.util.Objects.*; + import com.najasin.domain.answer.service.AnswerService; import com.najasin.domain.answer.dto.AnswerDTO; import com.najasin.domain.character.CharacterService; @@ -30,8 +32,6 @@ import java.util.ArrayList; import java.util.List; -import static com.najasin.domain.user.entity.QUser.user; - @RequiredArgsConstructor @RestController @RequestMapping("/api") @@ -44,7 +44,6 @@ public class UserController { private final UserUserTypeService userUserTypeService; private final UserKeywordService userKeywordService; private final CharacterService characterService; -// String userId = "63a47bcb-ebb1-4618-b357-fdd6681bd0fc"; @PostMapping("/logout") public ResponseEntity> logout(@AccessToken String accessToken, @RefreshToken String refreshToken) { @@ -149,12 +148,12 @@ public ResponseEntity> getMyManual( @AuthorizeUser User user ) { -// User user = userService.findById(userId); Manual manual = new Manual(); - String userId = user.getId(); - manual.setNickname(user.getNickname()); + + if(!isNull(user)) { + manual.setNickname(user.getId()); + } manual.setBaseImage("https://picsum.photos/200/300?random=1"); - CharacterItems characterInfoDTO = userUserTypeService.getCharacter(userId, userTypeName); manual.setCharacterItems(characterService.getAllCharacterItems().getCharacterItems()); manual.setQuestions(questionService.getQuestionByQuestionTypeAndUserType(QuestionType.FOR_USER, userTypeName)); return new ResponseEntity<>( @@ -189,7 +188,6 @@ public ResponseEntity> getMyPage( @PathVariable String userTypeName, @AuthorizeUser User user ) { -// User user = userService.findById(userId); String userId = user.getId(); Page page = new Page(); @@ -216,10 +214,8 @@ public ResponseEntity> getMyPage( ); } - @GetMapping("/{userTypeName}/characterItems") - public ResponseEntity> getCharacterItems( - @PathVariable String userTypeName - ){ + @GetMapping("/characterItems") + public ResponseEntity> getCharacterItems(){ AllCharacterItems allCharacterItems = characterService.getAllCharacterItems(); return new ResponseEntity<>( ApiResponse.createSuccessWithData(UserResponse.SUCCESS_GET_PAGE.getMessage(), allCharacterItems), From 77de68addfedeafafe6790eda84b73a69e10d288 Mon Sep 17 00:00:00 2001 From: lcomment Date: Sun, 20 Aug 2023 01:48:14 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix(#34):=20AuthroizeUser=20resolver=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 --- .../com/najasin/global/resovler/UserArgumentsResolver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java b/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java index 8932b4d..0708633 100644 --- a/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java +++ b/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java @@ -10,6 +10,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; import com.najasin.domain.user.entity.User; +import com.najasin.domain.user.repository.UserRepository; import com.najasin.domain.user.service.UserService; import com.najasin.global.annotation.AuthorizeUser; import com.najasin.security.model.PrincipalUser; @@ -19,7 +20,7 @@ @Component @RequiredArgsConstructor public class UserArgumentsResolver implements HandlerMethodArgumentResolver { - private final UserService userService; + private final UserRepository userRepository; @Override public boolean supportsParameter(MethodParameter parameter) { @@ -32,6 +33,6 @@ public User resolveArgument(MethodParameter parameter, ModelAndViewContainer mav NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { String authentication = SecurityContextHolder.getContext().getAuthentication().getName(); - return userService.findById(authentication); + return userRepository.findById(authentication).orElse(null); } } From e8dca3f26a3f269e70678c8ac144fb5a7196ead3 Mon Sep 17 00:00:00 2001 From: lcomment Date: Sun, 20 Aug 2023 01:53:01 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix(#34):=20AuthroizeUser=20resolver=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 --- .../global/resovler/UserArgumentsResolver.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java b/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java index 0708633..9dc1705 100644 --- a/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java +++ b/src/main/java/com/najasin/global/resovler/UserArgumentsResolver.java @@ -1,7 +1,10 @@ package com.najasin.global.resovler; +import static java.util.Objects.*; + import org.springframework.core.MethodParameter; import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; import org.springframework.web.bind.support.WebDataBinderFactory; @@ -10,7 +13,6 @@ import org.springframework.web.method.support.ModelAndViewContainer; import com.najasin.domain.user.entity.User; -import com.najasin.domain.user.repository.UserRepository; import com.najasin.domain.user.service.UserService; import com.najasin.global.annotation.AuthorizeUser; import com.najasin.security.model.PrincipalUser; @@ -20,7 +22,7 @@ @Component @RequiredArgsConstructor public class UserArgumentsResolver implements HandlerMethodArgumentResolver { - private final UserRepository userRepository; + private final UserService userService; @Override public boolean supportsParameter(MethodParameter parameter) { @@ -31,8 +33,12 @@ public boolean supportsParameter(MethodParameter parameter) { @Override public User resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { - String authentication = SecurityContextHolder.getContext().getAuthentication().getName(); + SecurityContext securityContext = SecurityContextHolder.getContext(); + if(isNull(securityContext)) { + return null; + } + String authentication = securityContext.getAuthentication().getName(); - return userRepository.findById(authentication).orElse(null); + return userService.findById(authentication); } }