Skip to content

Commit

Permalink
Merge pull request #214 from capstone-kw-jjiggle/feat/#211-userInfoApi
Browse files Browse the repository at this point in the history
[feat] 유저당 페이지 관련하여 api 제작(/api/v1/userInfo?username=~~~) 및 MyPage api 명칭 변경 작업 진행
  • Loading branch information
khyojun authored Oct 15, 2024
2 parents e5f0d86 + 9f2c2d5 commit 6110797
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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<String> modifyRegion(Authentication authentication, @RequestParam String modifyRegionName){
myPageService.modifyRegionName(authentication, modifyRegionName);
userPageService.modifyRegionName(authentication, modifyRegionName);
return ResponseEntity.ok("지역 수정에 성공했습니다.");
}

Expand All @@ -58,7 +59,7 @@ public ResponseEntity<String> modifyRegion(Authentication authentication, @Reque
@ApiResponse(responseCode = "5xx", description = "친구 추천 리스트를 가져오기 실패했습니다.")
})
public ResponseEntity<List<FriendSuggestDto>> suggestFreinds(Authentication authentication){
return ResponseEntity.ok(myPageService.getFriendSuggestionList(authentication));
return ResponseEntity.ok(userPageService.getFriendSuggestionList(authentication));
}

@GetMapping("/get/introduction")
Expand All @@ -68,21 +69,32 @@ public ResponseEntity<List<FriendSuggestDto>> suggestFreinds(Authentication auth
@ApiResponse(responseCode = "5xx", description = "user 소개글을 가져오기 실패했습니다.")
})
public ResponseEntity<IntroductionResponseDto> 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 소개글을 수정하기 성공했습니다."),
@ApiResponse(responseCode = "401", description = "인증된 유저가 없는 상태로 요청하셨습니다. github 로그인을 진행해주세요."),
@ApiResponse(responseCode = "5xx", description = "user 소개글을 수정하기 실패했습니다.")
})
public ResponseEntity<String> 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<UserPageUserInfoResponseDto> userInfo(String username){
return ResponseEntity.ok(userPageService.makeUserInfoResponse(username));
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
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;
import gitbal.backend.domain.school.SchoolService;
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;
Expand All @@ -25,7 +25,7 @@

@Service
@RequiredArgsConstructor
public class MyPageService {
public class UserPageService {
private final UserService userService;
private final SchoolService schoolService;
private final RegionService regionService;
Expand Down Expand Up @@ -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);
}
}
10 changes: 7 additions & 3 deletions src/main/java/gitbal/backend/domain/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;



Expand Down Expand Up @@ -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());
}
}

0 comments on commit 6110797

Please sign in to comment.