Skip to content

Commit

Permalink
[feat] Implement service
Browse files Browse the repository at this point in the history
  • Loading branch information
PicturePark1101 committed Dec 21, 2024
1 parent 5d917f2 commit 2be3070
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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.FavoriteNicknameGetResponse;
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 FavoriteNicknameGetResponse getFavoriteUserNickname(final long id) {
return FavoriteNicknameGetResponse.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 FavoriteNicknameGetResponse(
String nickname
) {
public static FavoriteNicknameGetResponse of(final String nickname) {
return new FavoriteNicknameGetResponse(nickname);
}
}

0 comments on commit 2be3070

Please sign in to comment.