From b5d5d026788f9de8b0807b23e21bf2c913f60a50 Mon Sep 17 00:00:00 2001 From: Khyojun Date: Tue, 15 Oct 2024 23:42:50 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20#211=20-=20myPage=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EB=B3=80=EA=B2=BD:=EC=9D=B4=EC=A0=9C=EB=8A=94=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=EB=A7=8C=20=EB=93=A4=EC=96=B4=EA=B0=80?= =?UTF-8?q?=EB=8A=94=EA=B2=83=EC=9D=B4=20=EC=95=84=EB=8B=8C=20=EB=AA=A8?= =?UTF-8?q?=EB=91=90=EA=B0=80=20=ED=99=95=EC=9D=B8=20=EB=B0=8F=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=ED=8E=98=EC=9D=B4=EC=A7=80=EC=9D=98=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A0=9C=EA=B3=B5=20api=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ontroller.java => UserPageController.java} | 40 ++++++++++++------- .../controller/UserRankContorller.java | 4 +- .../api/userPage/dto/UserInfoResponseDto.java | 11 +++++ ...yPageService.java => UserPageService.java} | 9 ++++- .../backend/domain/user/UserService.java | 10 +++-- 5 files changed, 53 insertions(+), 21 deletions(-) rename src/main/java/gitbal/backend/api/userPage/controller/{MyPageController.java => UserPageController.java} (72%) create mode 100644 src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java rename src/main/java/gitbal/backend/api/userPage/service/{MyPageService.java => UserPageService.java} (94%) diff --git a/src/main/java/gitbal/backend/api/userPage/controller/MyPageController.java b/src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java similarity index 72% rename from src/main/java/gitbal/backend/api/userPage/controller/MyPageController.java rename to src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java index d451392..7b2cf47 100644 --- a/src/main/java/gitbal/backend/api/userPage/controller/MyPageController.java +++ b/src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java @@ -3,7 +3,8 @@ import gitbal.backend.api.userPage.dto.FriendSuggestDto; import gitbal.backend.api.userPage.dto.IntroductionResponseDto; import gitbal.backend.api.userPage.dto.IntroductionupdateRequestDto; -import gitbal.backend.api.userPage.service.MyPageService; +import gitbal.backend.api.userPage.dto.UserInfoResponseDto; +import gitbal.backend.api.userPage.service.UserPageService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; @@ -20,34 +21,34 @@ import org.springframework.web.bind.annotation.RestController; -// TODO : 이거 이름이 myPage가 맞을지 고민을 조금 해봐야함. + @RestController -@RequestMapping("/api/v1/my") +@RequestMapping("/api/v1/userPage") @RequiredArgsConstructor -@Tag(name = "마이페이지 API", description = "마이페이지에 필요한 정보를 위한 api입니다.") -public class MyPageController { +@Tag(name = "유저페이지 API", description = "유저 페이지에 필요한 정보를 위한 api입니다.") +public class UserPageController { - private final MyPageService myPageService; + private final UserPageService userPageService; - @PutMapping("/config/school") + @PutMapping("/my/config/school") @Operation(summary = "학교 수정(헤더에 토큰 필요 Authorization: Bearer {토큰 값 넣기})", description = "학교 수정을 위한 api입니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "학교 수정에 성공했습니다."), @ApiResponse(responseCode = "5xx", description = "학교 수정에 실패했습니다.") }) public ResponseEntity modifySchool(Authentication authentication, @RequestParam String modifySchoolName){ - myPageService.modifySchoolName(authentication, modifySchoolName); + userPageService.modifySchoolName(authentication, modifySchoolName); return ResponseEntity.ok("학교 수정에 성공했습니다."); } - @PutMapping("/config/region") + @PutMapping("/my/config/region") @Operation(summary = "지역 수정(헤더에 토큰 필요 Authorization: Bearer {토큰 값 넣기})", description = "지역 수정을 위한 api입니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "지역 수정에 성공했습니다."), @ApiResponse(responseCode = "5xx", description = "지역 수정에 실패했습니다.") }) public ResponseEntity modifyRegion(Authentication authentication, @RequestParam String modifyRegionName){ - myPageService.modifyRegionName(authentication, modifyRegionName); + userPageService.modifyRegionName(authentication, modifyRegionName); return ResponseEntity.ok("지역 수정에 성공했습니다."); } @@ -58,7 +59,7 @@ public ResponseEntity modifyRegion(Authentication authentication, @Reque @ApiResponse(responseCode = "5xx", description = "친구 추천 리스트를 가져오기 실패했습니다.") }) public ResponseEntity> suggestFreinds(Authentication authentication){ - return ResponseEntity.ok(myPageService.getFriendSuggestionList(authentication)); + return ResponseEntity.ok(userPageService.getFriendSuggestionList(authentication)); } @GetMapping("/get/introduction") @@ -68,10 +69,10 @@ public ResponseEntity> suggestFreinds(Authentication auth @ApiResponse(responseCode = "5xx", description = "user 소개글을 가져오기 실패했습니다.") }) public ResponseEntity getIntroduction(String username){ - return ResponseEntity.ok(myPageService.getIntroduction(username)); + return ResponseEntity.ok(userPageService.getIntroduction(username)); } - @PutMapping("/update/introduction") + @PutMapping("/my/update/introduction") @Operation(summary = "user 소개글 수정하기(헤더에 토큰 필요 Authorization: Bearer {토큰 값 넣기})", description = "user 소개글을 수정하기 위한 api입니다.") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "user 소개글을 수정하기 성공했습니다."), @@ -79,10 +80,21 @@ public ResponseEntity getIntroduction(String username){ @ApiResponse(responseCode = "5xx", description = "user 소개글을 수정하기 실패했습니다.") }) public ResponseEntity updateIntroduction(Authentication authentication, @RequestBody IntroductionupdateRequestDto introductionpdateRequestDto){ - myPageService.updateIntroduction(authentication, introductionpdateRequestDto); + userPageService.updateIntroduction(authentication, introductionpdateRequestDto); return ResponseEntity.ok("수정이 완료 되었습니다."); } + @GetMapping("/userInfo") + @Operation(summary = "유저페이지에 필요한 유저 정보를 불러온다.", description = "유저의 페이지에 필요한 정보를 가져오는 api 입니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "유저페이지에 필요한 유저 개인 정보 로딩을 성공했습니다."), + @ApiResponse(responseCode = "5xx", description = "유저페이지에 필요한 유저 개인 정보 로딩을 실패했습니다.") + }) + public ResponseEntity userInfo(String username){ + return ResponseEntity.ok(userPageService.makeUserInfoResponse(username)); + } + + } diff --git a/src/main/java/gitbal/backend/api/userPage/controller/UserRankContorller.java b/src/main/java/gitbal/backend/api/userPage/controller/UserRankContorller.java index 6ba2254..32b222a 100644 --- a/src/main/java/gitbal/backend/api/userPage/controller/UserRankContorller.java +++ b/src/main/java/gitbal/backend/api/userPage/controller/UserRankContorller.java @@ -21,9 +21,9 @@ @RestController -@RequestMapping("/api/v1/userRank") +@RequestMapping("/api/v1/userPage/rank") @RequiredArgsConstructor -@Tag(name = "유저 순위 API", description = "유저 페이지의 랭킹 관련 api 입니다.") +@Tag(name = "유저 페이지의 랭킹 API", description = "유저 페이지의 랭킹 관련 api 입니다.") public class UserRankContorller { private final UserRankService userRankService; diff --git a/src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java b/src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java new file mode 100644 index 0000000..d461839 --- /dev/null +++ b/src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java @@ -0,0 +1,11 @@ +package gitbal.backend.api.userPage.dto; + +import gitbal.backend.global.constant.Grade; + +public record UserInfoResponseDto(String username, Grade grade, String profileImg) { + + public static UserInfoResponseDto of(String username, Grade grade, String profileImg) { + return new UserInfoResponseDto(username, grade, profileImg); + } + +} diff --git a/src/main/java/gitbal/backend/api/userPage/service/MyPageService.java b/src/main/java/gitbal/backend/api/userPage/service/UserPageService.java similarity index 94% rename from src/main/java/gitbal/backend/api/userPage/service/MyPageService.java rename to src/main/java/gitbal/backend/api/userPage/service/UserPageService.java index c392017..38e2bb2 100644 --- a/src/main/java/gitbal/backend/api/userPage/service/MyPageService.java +++ b/src/main/java/gitbal/backend/api/userPage/service/UserPageService.java @@ -4,6 +4,7 @@ import gitbal.backend.api.userPage.dto.FriendSuggestDto; import gitbal.backend.api.userPage.dto.IntroductionResponseDto; import gitbal.backend.api.userPage.dto.IntroductionupdateRequestDto; +import gitbal.backend.api.userPage.dto.UserInfoResponseDto; import gitbal.backend.domain.introduction.Introduction; import gitbal.backend.domain.introduction.application.repository.IntroductionRepository; import gitbal.backend.domain.region.application.RegionService; @@ -11,7 +12,6 @@ import gitbal.backend.domain.user.User; import gitbal.backend.domain.user.UserService; import gitbal.backend.global.exception.NotLoginedException; -import gitbal.backend.global.exception.NotUserPermissionException; import gitbal.backend.global.security.CustomUserDetails; import java.util.ArrayList; import java.util.Collections; @@ -25,7 +25,7 @@ @Service @RequiredArgsConstructor -public class MyPageService { +public class UserPageService { private final UserService userService; private final SchoolService schoolService; private final RegionService regionService; @@ -114,4 +114,9 @@ private void updateUserSchool(User user, String schoolName) { private void updateUserRegion(User user, String regionName) { userService.updateUserRegion(user, regionService.findByRegionName(regionName)); } + + @Transactional(readOnly = true) + public UserInfoResponseDto makeUserInfoResponse(String username) { + return userService.makeUserInfoResponse(username); + } } diff --git a/src/main/java/gitbal/backend/domain/user/UserService.java b/src/main/java/gitbal/backend/domain/user/UserService.java index c6f7219..b76c826 100644 --- a/src/main/java/gitbal/backend/domain/user/UserService.java +++ b/src/main/java/gitbal/backend/domain/user/UserService.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import gitbal.backend.api.userPage.dto.UserInfoResponseDto; import gitbal.backend.domain.region.Region; import gitbal.backend.domain.school.School; import gitbal.backend.global.constant.Grade; @@ -27,7 +28,6 @@ public class UserService { private final UserScoreCalculator userScoreCalculator; private final UserInfoService userInfoService; private final UserRepository userRepository; - private final int USER_AROUND_RANGE = 2; @@ -237,7 +237,11 @@ public int calculateExp(User findUser) { } + public UserInfoResponseDto makeUserInfoResponse(String username) { + User findUser = userRepository.findByNickname(username) + .orElseThrow(NotFoundUserException::new); - - + return UserInfoResponseDto.of(findUser.getNickname(), findUser.getGrade() + ,findUser.getProfile_img()); + } } From 9f2c2d5d8af0eab6ac136c543a97ef3823e04748 Mon Sep 17 00:00:00 2001 From: Khyojun Date: Wed, 16 Oct 2024 00:13:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[refactor]=20#211=20-=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20UserInfoDto=EB=9E=91=20=EA=B2=B9=EC=B9=98=EB=8A=94=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=EC=9D=B4=20=EB=B0=9C=EC=83=9D=ED=95=98?= =?UTF-8?q?=EC=97=AC=20responseDto=20=EC=9D=B4=EB=A6=84=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존의 UserInfoDto는 나중에 어느 페이지든 접속한 유저의 정보가 필요할 때 사용할 api - 현재 추가한 api는 유저 페이지 전용 api --- .../api/userPage/controller/UserPageController.java | 4 ++-- .../backend/api/userPage/dto/UserInfoResponseDto.java | 11 ----------- .../api/userPage/dto/UserPageUserInfoResponseDto.java | 11 +++++++++++ .../backend/api/userPage/service/UserPageService.java | 4 ++-- .../java/gitbal/backend/domain/user/UserService.java | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java create mode 100644 src/main/java/gitbal/backend/api/userPage/dto/UserPageUserInfoResponseDto.java diff --git a/src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java b/src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java index 7b2cf47..f92963f 100644 --- a/src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java +++ b/src/main/java/gitbal/backend/api/userPage/controller/UserPageController.java @@ -3,7 +3,7 @@ import gitbal.backend.api.userPage.dto.FriendSuggestDto; import gitbal.backend.api.userPage.dto.IntroductionResponseDto; import gitbal.backend.api.userPage.dto.IntroductionupdateRequestDto; -import gitbal.backend.api.userPage.dto.UserInfoResponseDto; +import gitbal.backend.api.userPage.dto.UserPageUserInfoResponseDto; import gitbal.backend.api.userPage.service.UserPageService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -91,7 +91,7 @@ public ResponseEntity updateIntroduction(Authentication authentication, @ApiResponse(responseCode = "200", description = "유저페이지에 필요한 유저 개인 정보 로딩을 성공했습니다."), @ApiResponse(responseCode = "5xx", description = "유저페이지에 필요한 유저 개인 정보 로딩을 실패했습니다.") }) - public ResponseEntity userInfo(String username){ + public ResponseEntity userInfo(String username){ return ResponseEntity.ok(userPageService.makeUserInfoResponse(username)); } diff --git a/src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java b/src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java deleted file mode 100644 index d461839..0000000 --- a/src/main/java/gitbal/backend/api/userPage/dto/UserInfoResponseDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package gitbal.backend.api.userPage.dto; - -import gitbal.backend.global.constant.Grade; - -public record UserInfoResponseDto(String username, Grade grade, String profileImg) { - - public static UserInfoResponseDto of(String username, Grade grade, String profileImg) { - return new UserInfoResponseDto(username, grade, profileImg); - } - -} diff --git a/src/main/java/gitbal/backend/api/userPage/dto/UserPageUserInfoResponseDto.java b/src/main/java/gitbal/backend/api/userPage/dto/UserPageUserInfoResponseDto.java new file mode 100644 index 0000000..4950329 --- /dev/null +++ b/src/main/java/gitbal/backend/api/userPage/dto/UserPageUserInfoResponseDto.java @@ -0,0 +1,11 @@ +package gitbal.backend.api.userPage.dto; + +import gitbal.backend.global.constant.Grade; + +public record UserPageUserInfoResponseDto(String username, Grade grade, String profileImg) { + + public static UserPageUserInfoResponseDto of(String username, Grade grade, String profileImg) { + return new UserPageUserInfoResponseDto(username, grade, profileImg); + } + +} diff --git a/src/main/java/gitbal/backend/api/userPage/service/UserPageService.java b/src/main/java/gitbal/backend/api/userPage/service/UserPageService.java index 38e2bb2..08dcaeb 100644 --- a/src/main/java/gitbal/backend/api/userPage/service/UserPageService.java +++ b/src/main/java/gitbal/backend/api/userPage/service/UserPageService.java @@ -4,7 +4,7 @@ import gitbal.backend.api.userPage.dto.FriendSuggestDto; import gitbal.backend.api.userPage.dto.IntroductionResponseDto; import gitbal.backend.api.userPage.dto.IntroductionupdateRequestDto; -import gitbal.backend.api.userPage.dto.UserInfoResponseDto; +import gitbal.backend.api.userPage.dto.UserPageUserInfoResponseDto; import gitbal.backend.domain.introduction.Introduction; import gitbal.backend.domain.introduction.application.repository.IntroductionRepository; import gitbal.backend.domain.region.application.RegionService; @@ -116,7 +116,7 @@ private void updateUserRegion(User user, String regionName) { } @Transactional(readOnly = true) - public UserInfoResponseDto makeUserInfoResponse(String username) { + public UserPageUserInfoResponseDto makeUserInfoResponse(String username) { return userService.makeUserInfoResponse(username); } } diff --git a/src/main/java/gitbal/backend/domain/user/UserService.java b/src/main/java/gitbal/backend/domain/user/UserService.java index b76c826..e2eeffa 100644 --- a/src/main/java/gitbal/backend/domain/user/UserService.java +++ b/src/main/java/gitbal/backend/domain/user/UserService.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import gitbal.backend.api.userPage.dto.UserInfoResponseDto; +import gitbal.backend.api.userPage.dto.UserPageUserInfoResponseDto; import gitbal.backend.domain.region.Region; import gitbal.backend.domain.school.School; import gitbal.backend.global.constant.Grade; @@ -237,11 +237,11 @@ public int calculateExp(User findUser) { } - public UserInfoResponseDto makeUserInfoResponse(String username) { + public UserPageUserInfoResponseDto makeUserInfoResponse(String username) { User findUser = userRepository.findByNickname(username) .orElseThrow(NotFoundUserException::new); - return UserInfoResponseDto.of(findUser.getNickname(), findUser.getGrade() + return UserPageUserInfoResponseDto.of(findUser.getNickname(), findUser.getGrade() ,findUser.getProfile_img()); } }