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] 좋아요 전체 갯수 응답값 추가 #83

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -31,7 +31,7 @@ public HeartCreateResponse createHeart(final StorePostCommand storePostCommand)
validateStoreHeartCreation(user, store);
saveStoreHeart(user, store);
increaseStoreHeartCount(store);
return HeartCreateResponse.of(store.getId(), true);
return HeartCreateResponse.of(store.getId(), true, findTotalHeartCount(store));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분은 store를 매개변수로 전달해서 DTO에서 처리할 수 있지않을까요??

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store를 전달해서 dto안에서 id와 count를 꺼낼 수 있을 것 같습니다

}

public HeartDeleteResponse deleteHeart(final StoreDeleteCommand storeDeleteCommand) {
Expand All @@ -40,7 +40,7 @@ public HeartDeleteResponse deleteHeart(final StoreDeleteCommand storeDeleteComma
validateStoreHeartRemoval(user, store);
heartDeleter.deleteHeart(user,store);
decreaseStoreHeartCount(store);
return HeartDeleteResponse.of(store.getId(), false);
return HeartDeleteResponse.of(store.getId(), false, findTotalHeartCount(store));
}

private void validateStoreHeartCreation(final User user, final Store store) {
Expand All @@ -66,4 +66,8 @@ private void increaseStoreHeartCount(final Store store) {
private void decreaseStoreHeartCount(final Store store) {
store.decreaseHeartCount();
}

private int findTotalHeartCount(final Store store) {
return store.getHeartCount();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

public record HeartCreateResponse(
Long storeId,
boolean isHearted
boolean isHearted,
int count
) {
public static HeartCreateResponse of(final Long storeId, final boolean isHearted) {
return new HeartCreateResponse(storeId, isHearted);
public static HeartCreateResponse of(final Long storeId, final boolean isHearted, final int count) {
return new HeartCreateResponse(storeId, isHearted, count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

public record HeartDeleteResponse(
Long storeId,
boolean isHearted
boolean isHearted,
int count
) {
public static HeartDeleteResponse of(final Long storeId, final boolean isHearted) {
return new HeartDeleteResponse(storeId, isHearted);
public static HeartDeleteResponse of(final Long storeId, final boolean isHearted, final int count) {
return new HeartDeleteResponse(storeId, isHearted, count);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import org.hankki.hankkiserver.domain.user.model.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface HeartRepository extends JpaRepository<Heart, Long> {

boolean existsByUserAndStore(User user, Store store);
Expand Down
Loading