-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [feat] add @onetomany and apply @batchsize * [feat] setting reponse dto * [feat] implements service * [feat] implements controller * [feat] add fetchType Lazy and Batch * [refac] long to Long * [feat] add heartCount response * [refac] reflect the code review
- Loading branch information
1 parent
9801db5
commit 52d2097
Showing
8 changed files
with
121 additions
and
3 deletions.
There are no files selected for viewing
Submodule server-yml
updated
from a2dc81 to 247c1e
This file contains 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
26 changes: 26 additions & 0 deletions
26
src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteQueryService.java
This file contains 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,26 @@ | ||
package org.hankki.hankkiserver.api.favorite.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.api.auth.service.UserFinder; | ||
import org.hankki.hankkiserver.api.favorite.service.command.FavoriteGetCommand; | ||
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteFindResponse; | ||
import org.hankki.hankkiserver.common.code.UserErrorCode; | ||
import org.hankki.hankkiserver.common.exception.UnauthorizedException; | ||
import org.hankki.hankkiserver.domain.favorite.model.Favorite; | ||
import org.hankki.hankkiserver.domain.favoritestore.model.FavoriteStore; | ||
import org.hankki.hankkiserver.domain.user.model.User; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FavoriteQueryService { | ||
|
||
private final FavoriteFinder favoriteFinder; | ||
|
||
@Transactional(readOnly = true) | ||
public FavoriteFindResponse findFavorite(final FavoriteGetCommand command) { | ||
Favorite favorite = favoriteFinder.findById(command.favoriteId()); | ||
return FavoriteFindResponse.of(favorite, favorite.getFavoriteStores().stream().map(FavoriteStore::getStore).toList()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/org/hankki/hankkiserver/api/favorite/service/command/FavoriteGetCommand.java
This file contains 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,10 @@ | ||
package org.hankki.hankkiserver.api.favorite.service.command; | ||
|
||
public record FavoriteGetCommand( | ||
Long userId, | ||
Long favoriteId | ||
) { | ||
public static FavoriteGetCommand of(final Long userId, final Long favoriteId) { | ||
return new FavoriteGetCommand(userId, favoriteId); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...main/java/org/hankki/hankkiserver/api/favorite/service/response/FavoriteFindResponse.java
This file contains 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,31 @@ | ||
package org.hankki.hankkiserver.api.favorite.service.response; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.hankki.hankkiserver.domain.favorite.model.Favorite; | ||
import org.hankki.hankkiserver.domain.store.model.Store; | ||
|
||
public record FavoriteFindResponse( | ||
String title, | ||
List<String> details, | ||
List<FavoriteStoreFindResponse> stores | ||
) { | ||
|
||
public static FavoriteFindResponse of(final Favorite favorite, final List<Store> stores) { | ||
|
||
List<String> details = new ArrayList<>(); | ||
if (!isDetailNull(favorite.getDetail())) { | ||
details = Arrays.asList(favorite.getDetail().split(" ")); | ||
} | ||
|
||
return new FavoriteFindResponse( | ||
favorite.getName(), | ||
details, | ||
stores.stream().map(FavoriteStoreFindResponse::of).toList()); | ||
} | ||
|
||
public static boolean isDetailNull(String detail) { | ||
return detail == null; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...java/org/hankki/hankkiserver/api/favorite/service/response/FavoriteStoreFindResponse.java
This file contains 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,25 @@ | ||
package org.hankki.hankkiserver.api.favorite.service.response; | ||
|
||
import org.hankki.hankkiserver.domain.store.model.Store; | ||
import org.hankki.hankkiserver.domain.store.model.StoreCategory; | ||
|
||
public record FavoriteStoreFindResponse( | ||
Long id, | ||
String name, | ||
String imageUrl, | ||
String category, | ||
int lowestPrice, | ||
int heartCount | ||
) { | ||
|
||
public static FavoriteStoreFindResponse of(Store store) { | ||
|
||
return new FavoriteStoreFindResponse( | ||
store.getId(), | ||
store.getName(), | ||
store.getImage(), | ||
store.getCategory().getName(), | ||
store.getLowestPrice(), | ||
store.getHeartCount()); | ||
} | ||
} |
This file contains 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 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