Skip to content
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

feat: 프로필 조회 리팩토링 #43

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import site.travellaboratory.be.controller.article.dto.ArticleResponse;
import site.travellaboratory.be.controller.article.dto.ArticleSearchRequest;
import site.travellaboratory.be.controller.article.dto.ArticleSearchResponse;
import site.travellaboratory.be.controller.review.dto.ReviewDeleteResponse;
import site.travellaboratory.be.service.ArticleService;

@RestController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
Expand All @@ -17,14 +18,14 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/users")
@RequestMapping("/api/v1")
public class UserController {

private final UserService userService;

@GetMapping("/profile")
public ResponseEntity<UserProfileResponse> findMyProfile(@UserId final Long userId) {
final UserProfileResponse userProfileResponse = userService.findByUserProfile(userId);
@GetMapping("/profile/{id}")
public ResponseEntity<UserProfileResponse> findMyProfile(@UserId final Long userId, @PathVariable final Long id) {
final UserProfileResponse userProfileResponse = userService.findByUserProfile(userId, id);
return ResponseEntity.ok(userProfileResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import site.travellaboratory.be.domain.user.entity.User;

public record UserProfileResponse (
public record UserProfileResponse(
String profileImgUrl,
String name,
String introduce
){
public static UserProfileResponse from(final User user) {
return new UserProfileResponse(user.getProfileImgUrl(), user.getNickname(), user.getIntroduce());
String introduce,
boolean isEditable
) {
public static UserProfileResponse from(final User user, boolean isEditable) {
return new UserProfileResponse(user.getProfileImgUrl(), user.getNickname(), user.getIntroduce(), isEditable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
import site.travellaboratory.be.controller.article.dto.ArticleResponse;
import site.travellaboratory.be.controller.article.dto.ArticleSearchRequest;
import site.travellaboratory.be.controller.article.dto.ArticleSearchResponse;
import site.travellaboratory.be.controller.review.dto.ReviewDeleteResponse;
import site.travellaboratory.be.domain.article.Article;
import site.travellaboratory.be.domain.article.ArticleRepository;
import site.travellaboratory.be.domain.article.ArticleStatus;
import site.travellaboratory.be.domain.review.Review;
import site.travellaboratory.be.domain.review.ReviewStatus;
import site.travellaboratory.be.domain.user.UserRepository;
import site.travellaboratory.be.domain.user.entity.User;
import site.travellaboratory.be.domain.user.entity.UserStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ public class UserService {

private final AmazonS3Client amazonS3Client;

public UserProfileResponse findByUserProfile(final Long userId) {
final User user = userRepository.findByIdAndStatus(userId, UserStatus.ACTIVE)
public UserProfileResponse findByUserProfile(final Long userId, final Long id) {
final User user = userRepository.findByIdAndStatus(id, UserStatus.ACTIVE)
.orElseThrow(() -> new BeApplicationException(ErrorCodes.AUTH_USER_NOT_FOUND,
HttpStatus.BAD_REQUEST)
);
return UserProfileResponse.from(user);

final boolean isEditable = user.getId().equals(userId);

return UserProfileResponse.from(user, isEditable);
}

public UserProfileUpdateResponse updateProfile(
Expand Down
Loading