-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat/#20] - 사용자 공개 프로필 조회, 닉네임 수정 기능 구현 #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
SossBar/src/main/java/com/sossbar/user/controller/UserProfileController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package com.sossbar.user.controller; | ||
|
|
||
| import com.sossbar.global.common.code.SuccessCode; | ||
| import com.sossbar.global.common.template.ApiResTemplate; | ||
| import com.sossbar.global.common.template.SwaggerApiResTemplate; | ||
| import com.sossbar.user.dto.request.UserInfoUpdateReqDto; | ||
| import com.sossbar.user.dto.response.UserInfoResDto; | ||
| import com.sossbar.user.dto.response.UserProfileInfoResDto; | ||
| import com.sossbar.user.service.UserProfileService; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.security.Principal; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/users") | ||
| @SwaggerApiResTemplate | ||
| @Tag(name = "User Profile API", description = "사용자 프로필 관련 API") | ||
| public class UserProfileController { | ||
|
|
||
| private final UserProfileService userProfileService; | ||
|
|
||
| @Operation(summary = "사용자 프로필 정보 조회", description = "로그인한 사용자가 userId로 사용자 프로필 정보(실명, 프로필 사진, 한 줄 소개)를 조회합니다.") | ||
| @GetMapping("/profile/{userId}") | ||
| public ApiResTemplate<UserProfileInfoResDto> getUserProfile(@PathVariable("userId") Long userId) { | ||
| UserProfileInfoResDto userProfileInfoResDto = userProfileService.getUserProfile(userId); | ||
| return ApiResTemplate.successResponse(SuccessCode.GET_SUCCESS, userProfileInfoResDto); | ||
| } | ||
|
|
||
| @Operation(summary = "내 프로필 수정", description = "로그인한 사용자가 자신의 프로필 정보를 수정합니다. (실명, 한 줄 소개, 프로필 이미지)" + | ||
| "<br> 이미지를 빈 값으로 보낼 시 기존 프로필 이미지 유지") | ||
| @PatchMapping(value = "/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResTemplate<UserInfoResDto> updateUserInfo(Principal principal, | ||
| @Valid @RequestPart("info") UserInfoUpdateReqDto userInfoUpdateReqDto, | ||
| @RequestPart(value = "profileImage", required = false) MultipartFile profileImage) { | ||
| UserInfoResDto userInfoResDto = userProfileService.updateUserInfo(principal, userInfoUpdateReqDto, profileImage); | ||
| return ApiResTemplate.successResponse(SuccessCode.UPDATE_SUCCESS, userInfoResDto); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
SossBar/src/main/java/com/sossbar/user/dto/request/UserOnboardingReqDto.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
SossBar/src/main/java/com/sossbar/user/dto/response/UserProfileInfoResDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.sossbar.user.dto.response; | ||
|
|
||
| import com.sossbar.user.entity.User; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record UserProfileInfoResDto( | ||
| Long userId, | ||
| String username, | ||
| String bio, | ||
| String profileImageUrl | ||
| ) { | ||
| public static UserProfileInfoResDto from(User user) { | ||
| return UserProfileInfoResDto.builder() | ||
| .userId(user.getId()) | ||
| .username(user.getUsername()) | ||
| .bio(user.getBio()) | ||
| .profileImageUrl(user.getProfileImageUrl()) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
SossBar/src/main/java/com/sossbar/user/service/UserProfileService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| package com.sossbar.user.service; | ||
|
|
||
| import com.sossbar.global.common.code.ErrorCode; | ||
| import com.sossbar.global.common.exception.BusinessException; | ||
| import com.sossbar.global.config.S3Service; | ||
| import com.sossbar.user.dto.request.UserInfoUpdateReqDto; | ||
| import com.sossbar.user.dto.response.UserInfoResDto; | ||
| import com.sossbar.user.dto.response.UserProfileInfoResDto; | ||
| import com.sossbar.user.entity.User; | ||
| import com.sossbar.user.repository.UserRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.security.Principal; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class UserProfileService { | ||
|
|
||
| private final UserRepository userRepository; | ||
| private final S3Service s3Service; | ||
|
|
||
| // 프로필 페이지 - 내 프로필 수정(실명, 한 줄 소개, 프로필 이미지) | ||
| @Transactional | ||
| public UserInfoResDto updateUserInfo(Principal principal, UserInfoUpdateReqDto userInfoUpdateReqDto, MultipartFile profileImage) { | ||
| Long id = Long.parseLong(principal.getName()); | ||
| User user = getUserById(id); | ||
|
|
||
| // 프로필 이미지 수정 처리 (기존 이미지 삭제 후 새 이미지 업로드) | ||
| String newProfileImageUrl = user.getProfileImageUrl(); | ||
|
|
||
| if (profileImage != null && !profileImage.isEmpty()) { | ||
| // 기존 이미지가 존재한다면 S3에서 삭제 | ||
| if (newProfileImageUrl != null && !newProfileImageUrl.isBlank()) { | ||
| s3Service.deleteFile(newProfileImageUrl); | ||
| } | ||
| // 새 이미지 업로드 | ||
| newProfileImageUrl = s3Service.uploadFile(profileImage, "sossbar/profile"); | ||
| } | ||
|
|
||
| user.updateUserInfo(userInfoUpdateReqDto, newProfileImageUrl); | ||
|
|
||
| return UserInfoResDto.from(user); | ||
| } | ||
|
|
||
| // 프로필 페이지 - 사용자 프로필 조회, userId로 구분 | ||
| public UserProfileInfoResDto getUserProfile(Long userId) { | ||
| User user = getUserById(userId); | ||
|
|
||
| return UserProfileInfoResDto.from(user); | ||
| } | ||
|
|
||
| // entity 찾는 공통 메소드 | ||
| private User getUserById(Long userId) { | ||
| return userRepository.findById(userId).orElseThrow( | ||
| () -> new BusinessException(ErrorCode.USER_NOT_FOUND_EXCEPTION | ||
| , ErrorCode.USER_NOT_FOUND_EXCEPTION.getMessage() + userId)); | ||
| } | ||
|
ttttkii913 marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.