Skip to content

Commit

Permalink
[feat] 족보 주인 닉네임 조회 API (#231)
Browse files Browse the repository at this point in the history
* [feat] Implement controller

* [feat] Implement service

* [refac] Refacotr dto naming
  • Loading branch information
PicturePark1101 authored Dec 21, 2024
1 parent 38b8525 commit 7b5942d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hankki.hankkiserver.api.favorite.service.FavoriteQueryService;
import org.hankki.hankkiserver.api.favorite.service.command.*;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteUserNicknameGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteOwnershipGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoritesWithStatusGetResponse;
import org.hankki.hankkiserver.auth.UserId;
Expand Down Expand Up @@ -78,4 +79,9 @@ public HankkiResponse<Void> createSharedFavorite(@UserId final Long userId, @Pat
public HankkiResponse<FavoriteOwnershipGetResponse> checkFavoriteOwnership(@UserId Long userId, @PathVariable("favoriteId") final long favoriteId) {
return HankkiResponse.success(CommonSuccessCode.OK, favoriteQueryService.checkFavoriteOwnership(FavoriteOwnershipGetCommand.of(userId, favoriteId)));
}

@GetMapping("/favorites/{favoriteId}/users/me")
public HankkiResponse<FavoriteUserNicknameGetResponse> getFavoriteUserNickname(@PathVariable("favoriteId") final long id) {
return HankkiResponse.success(CommonSuccessCode.OK, favoriteQueryService.getFavoriteUserNickname(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.util.ArrayList;
import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.auth.service.UserInfoFinder;
import org.hankki.hankkiserver.api.favorite.service.command.FavoriteOwnershipGetCommand;
import org.hankki.hankkiserver.api.favorite.service.command.FavoritesGetCommand;
import org.hankki.hankkiserver.api.favorite.service.command.FavoritesWithStatusGetCommand;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteUserNicknameGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteOwnershipGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoritesWithStatusGetResponse;
import org.hankki.hankkiserver.api.store.service.StoreFinder;
Expand All @@ -25,6 +27,7 @@ public class FavoriteQueryService {

private final FavoriteFinder favoriteFinder;
private final StoreFinder storeFinder;
private final UserInfoFinder userInfoFinder;

@Transactional(readOnly = true)
public FavoriteGetResponse findFavorite(final FavoritesGetCommand command) {
Expand Down Expand Up @@ -59,6 +62,7 @@ private boolean favoriteHasNoStore(final Favorite favorite) {
return favorite.getFavoriteStores().isEmpty();
}

@Transactional(readOnly = true)
public FavoriteOwnershipGetResponse checkFavoriteOwnership(final FavoriteOwnershipGetCommand command) {
return FavoriteOwnershipGetResponse.of(isOwner(getOwnerIdById(command.favoriteId()), command.userId()));
}
Expand All @@ -70,4 +74,13 @@ private long getOwnerIdById(final long id) {
private boolean isOwner(final long ownerId, final long userId) {
return ownerId == userId;
}

@Transactional(readOnly = true)
public FavoriteUserNicknameGetResponse getFavoriteUserNickname(final long id) {
return FavoriteUserNicknameGetResponse.of(getNicknameByOwnerId(getOwnerIdById(id)));
}

private String getNicknameByOwnerId(final long userId) {
return userInfoFinder.getUserInfo(userId).getNickname();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.hankki.hankkiserver.api.favorite.service.response;

public record FavoriteUserNicknameGetResponse(
String nickname
) {
public static FavoriteUserNicknameGetResponse of(final String nickname) {
return new FavoriteUserNicknameGetResponse(nickname);
}
}

0 comments on commit 7b5942d

Please sign in to comment.