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..f92963f 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.UserPageUserInfoResponseDto; +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/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/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..08dcaeb 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.UserPageUserInfoResponseDto; 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 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 c6f7219..e2eeffa 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.UserPageUserInfoResponseDto; 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 UserPageUserInfoResponseDto makeUserInfoResponse(String username) { + User findUser = userRepository.findByNickname(username) + .orElseThrow(NotFoundUserException::new); - - + return UserPageUserInfoResponseDto.of(findUser.getNickname(), findUser.getGrade() + ,findUser.getProfile_img()); + } }