Skip to content

Commit

Permalink
[feat] logic for get user hearted stores view
Browse files Browse the repository at this point in the history
  • Loading branch information
kgy1008 committed Jul 16, 2024
1 parent af5b243 commit 032f614
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.hankki.hankkiserver.domain.user.model.User;
import org.springframework.stereotype.Component;

import java.util.Optional;
import java.util.List;

@Component
@RequiredArgsConstructor
Expand All @@ -18,4 +18,8 @@ public class HeartFinder {
public boolean existsByUserAndStore(final User user, final Store store) {
return heartRepository.existsByUserAndStore(user, store);
}

public List<Heart> findHeartedStoresByUserId(final Long userId) {
return heartRepository.findHeartedStoresByUserId(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.hankki.hankkiserver.api.store.service;


import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.menu.service.MenuFinder;
import org.hankki.hankkiserver.api.store.parameter.PriceCategory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.UserFavoritesGetResponse;
import org.hankki.hankkiserver.api.user.service.response.UserHeartedStoreListResponse;
import org.hankki.hankkiserver.api.user.service.response.UserProfileAndNicknameResponse;
import org.hankki.hankkiserver.api.user.service.response.UserUniversityFindResponse;
import org.hankki.hankkiserver.auth.UserId;
Expand All @@ -24,7 +25,7 @@ public class UserController {

@PostMapping("/users/me/university")
public HankkiResponse<Void> postUserUniversity(@UserId final Long userId,
@Valid @RequestBody final UserUniversityPostRequest request) {
@Valid @RequestBody final UserUniversityPostRequest request) {
userCommandService.saveUserUniversity(new UserUniversityPostCommand(userId, request));
return HankkiResponse.success(CommonSuccessCode.CREATED);
}
Expand All @@ -36,11 +37,16 @@ public HankkiResponse<UserUniversityFindResponse> findUserUniversity(@UserId fin

@GetMapping("/users/me")
public HankkiResponse<UserProfileAndNicknameResponse> getUserProfileAndNickname(@UserId final Long userId) {
return HankkiResponse.success(CommonSuccessCode.OK, userQueryService.getUserProfileAndNickname(userId));
return HankkiResponse.success(CommonSuccessCode.OK, userQueryService.getUserProfileAndNickname(userId));
}

@GetMapping("/users/me/favorites")
public HankkiResponse<UserFavoritesGetResponse> findUserFavorites(@UserId final Long userId) {
return HankkiResponse.success(CommonSuccessCode.OK,userQueryService.findUserFavorites(userId));
return HankkiResponse.success(CommonSuccessCode.OK, userQueryService.findUserFavorites(userId));
}

@GetMapping("/users/me/stores/hearts")
public HankkiResponse<UserHeartedStoreListResponse> getUserHeartedStores(@UserId final Long userId) {
return HankkiResponse.success(CommonSuccessCode.OK, userQueryService.findUserHeartedStoresView(userId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
import lombok.RequiredArgsConstructor;
import org.hankki.hankkiserver.api.auth.service.UserInfoFinder;
import org.hankki.hankkiserver.api.favorite.service.FavoriteFinder;
import org.hankki.hankkiserver.api.store.service.HeartFinder;
import org.hankki.hankkiserver.api.user.service.response.UserFavoritesGetResponse;
import org.hankki.hankkiserver.api.user.service.response.UserProfileAndNicknameResponse;
import org.hankki.hankkiserver.api.user.service.response.UserHeartedStoreListResponse;
import org.hankki.hankkiserver.api.user.service.response.UserUniversityFindResponse;
import org.hankki.hankkiserver.common.code.UserUniversityErrorCode;
import org.hankki.hankkiserver.common.exception.NotFoundException;
import org.hankki.hankkiserver.domain.heart.model.Heart;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserQueryService {

private final UserUniversityFinder userUniversityFinder;
private final FavoriteFinder favoriteFinder;
private final UserInfoFinder userInfoFinder;
private final HeartFinder heartFinder;

@Transactional(readOnly = true)
public UserUniversityFindResponse findUserUniversity(Long userId) {
Expand All @@ -27,11 +33,17 @@ public UserUniversityFindResponse findUserUniversity(Long userId) {

@Transactional(readOnly = true)
public UserFavoritesGetResponse findUserFavorites(final Long userId) {
return UserFavoritesGetResponse.of(favoriteFinder.findAllByUserId(userId));
return UserFavoritesGetResponse.of(favoriteFinder.findAllByUserId(userId));
}

@Transactional(readOnly = true)
public UserProfileAndNicknameResponse getUserProfileAndNickname(final Long userId) {
return UserProfileAndNicknameResponse.of(userInfoFinder.getUserInfo(userId));
return UserProfileAndNicknameResponse.of(userInfoFinder.getUserInfo(userId));
}

@Transactional(readOnly = true)
public UserHeartedStoreListResponse findUserHeartedStoresView(final Long userId) {
List<Heart> hearts = heartFinder.findHeartedStoresByUserId(userId);
return UserHeartedStoreListResponse.of(hearts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
import org.hankki.hankkiserver.domain.store.model.Store;
import org.hankki.hankkiserver.domain.user.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;
import java.util.List;

public interface HeartRepository extends JpaRepository<Heart, Long> {

boolean existsByUserAndStore(User user, Store store);
void deleteByUserAndStore(User user, Store store);

@Query("select h from Heart h join fetch h.store s join fetch s.storeImages " +
"where h.user.id = :userId and s.isDeleted = false order by h.id desc")
List<Heart> findHeartedStoresByUserId(Long userId);
}

0 comments on commit 032f614

Please sign in to comment.