Skip to content

Commit

Permalink
[feat] 사용자 닉네임, 프로필 조회 API (#69)
Browse files Browse the repository at this point in the history
* [feat] make response dto

* [feat] logic for get user nickname and profile

* [refac] add missing '/'

* [refac] add missing transational annotation

* [refac] typo correction and encapsulation variable
  • Loading branch information
kgy1008 authored Jul 14, 2024
1 parent 52d2097 commit 053ed20
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hankki.hankkiserver.api.user.service.UserCommandService;
import org.hankki.hankkiserver.api.user.service.UserQueryService;
import org.hankki.hankkiserver.api.user.service.command.UserUniversityPostCommand;
import org.hankki.hankkiserver.api.user.service.response.UserProfileAndNicknameResponse;
import org.hankki.hankkiserver.api.user.service.response.UserUniversityFindResponse;
import org.hankki.hankkiserver.auth.UserId;
import org.hankki.hankkiserver.common.code.CommonSuccessCode;
Expand All @@ -31,4 +32,9 @@ public HankkiResponse<Void> postUserUniversity(@UserId final Long userId,
public HankkiResponse<UserUniversityFindResponse> findUserUniversity(@UserId final Long userId) {
return HankkiResponse.success(CommonSuccessCode.OK, userQueryService.findUserUniversity(userId));
}

@GetMapping("/users/me")
public HankkiResponse<UserProfileAndNicknameResponse> getUserProfileAndNickname(@UserId final Long userId) {
return HankkiResponse.success(CommonSuccessCode.OK, userQueryService.getUserProfileAndNickname(userId));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.hankki.hankkiserver.api.user.service;

import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.auth.service.UserInfoFinder;
import org.hankki.hankkiserver.api.user.service.response.UserProfileAndNicknameResponse;
import org.hankki.hankkiserver.api.user.service.response.UserUniversityFindResponse;
import org.hankki.hankkiserver.common.code.UserUniversityErrorCode;
import org.hankki.hankkiserver.common.exception.NotFoundException;
Expand All @@ -12,10 +14,16 @@
public class UserQueryService {

private final UserUniversityFinder userUniversityFinder;
private final UserInfoFinder userInfoFinder;

@Transactional(readOnly = true)
public UserUniversityFindResponse findUserUniversity(Long userId) {
return UserUniversityFindResponse.of(userUniversityFinder.findByUserId(userId)
.orElseThrow(() -> new NotFoundException(UserUniversityErrorCode.USER_UNIVERSITY_NOT_FOUND)));
}

@Transactional(readOnly = true)
public UserProfileAndNicknameResponse getUserProfileAndNickname(final Long userId) {
return UserProfileAndNicknameResponse.of(userInfoFinder.getUserInfo(userId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.hankki.hankkiserver.api.user.service.response;

import org.hankki.hankkiserver.domain.user.model.UserInfo;

public record UserProfileAndNicknameResponse(
String nickname,
String profileImageUrl
) {
public static UserProfileAndNicknameResponse of(UserInfo userInfo) {
return new UserProfileAndNicknameResponse(userInfo.getNickname(), userInfo.getProfileImageUrl());
}
}

0 comments on commit 053ed20

Please sign in to comment.