Skip to content

Commit

Permalink
Merge pull request #24 from 28th-meetup/feat/store-1110
Browse files Browse the repository at this point in the history
[feat] 가게 찜하기, 찜한 가게 리스트
  • Loading branch information
eckrin authored Nov 11, 2023
2 parents 36b3c10 + 18336c4 commit a7098d0
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 14 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified src/.DS_Store
Binary file not shown.
Binary file modified src/main/.DS_Store
Binary file not shown.
Binary file modified src/main/java/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/kusitms/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/kusitms/jipbap/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/kusitms/jipbap/auth/.DS_Store
Binary file not shown.
Binary file modified src/main/java/com/kusitms/jipbap/common/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.kusitms.jipbap.user.User;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface StoreBookmarkRepository extends JpaRepository<StoreBookmark, Long> {
Boolean existsByUserAndStore(User user, Store store);
List<StoreBookmark> findByUser(User user);
}
15 changes: 14 additions & 1 deletion src/main/java/com/kusitms/jipbap/store/StoreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kusitms.jipbap.common.response.CommonResponse;
import com.kusitms.jipbap.security.Auth;
import com.kusitms.jipbap.security.AuthInfo;
import com.kusitms.jipbap.store.dto.BookmarkedStoreListResponseDto;
import com.kusitms.jipbap.store.dto.RegisterStoreRequestDto;
import com.kusitms.jipbap.store.dto.StoreDetailResponseDto;
import com.kusitms.jipbap.store.dto.StoreDto;
Expand All @@ -22,7 +23,7 @@
@RequiredArgsConstructor
public class StoreController {

private final int PAGESIZE = 10;
private final int PAGESIZE = 3;
private final StoreService storeService;

@Operation(summary = "가게 등록하기")
Expand Down Expand Up @@ -69,4 +70,16 @@ public CommonResponse<StoreDetailResponseDto> storeDetail(@Auth AuthInfo authInf
return new CommonResponse<>(storeService.getStoreDetail(authInfo.getEmail(), storeId));
}

@Operation(summary = "가게 찜하기")
@PostMapping("/bookmark/{storeId}")
public CommonResponse<StoreDto> bookmarkStore(@Auth AuthInfo authInfo, @PathVariable Long storeId) {
return new CommonResponse<>(storeService.bookmarkStore(authInfo.getEmail(), storeId));
}

@Operation(summary = "찜한 가게 리스트")
@GetMapping("/bookmark")
public CommonResponse<BookmarkedStoreListResponseDto> getBookmarkedStoreList(@Auth AuthInfo authInfo) {
return new CommonResponse<>(storeService.findBookmarkedStore(authInfo.getEmail()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Slice<StoreDetailResponseDto> searchByKeywordOrderBySort(User user, Pagea

List<Store> storeList = queryFactory.selectFrom(store)
.where(
lastStore(pageable, lastId),
lastStore(pageable, orderSpecifiers, lastId),
containsKeyword(keyword)
)
.limit(pageable.getPageSize()+1)
Expand Down Expand Up @@ -74,25 +74,43 @@ private Boolean isUserBookmarkedStore(User user, Store store) {

// no-offset 방식 처리하는 메서드
// 정렬조건에 따라서 다음에 나와야 할 친구들을 구함
private BooleanExpression lastStore(Pageable pageable, Long id) {
private BooleanExpression lastStore(Pageable pageable, List<OrderSpecifier<?>> specifiers, Long id) {
if(id==null) return null;

Store stdStore = queryFactory.selectFrom(QStore.store)
.where(QStore.store.id.eq(id))
.fetchFirst();

System.out.println("aaaa>>"+specifiers.get(0).getOrder());

for (Sort.Order order : pageable.getSort()) {
return switch (order.getProperty()) {
case "bookmark" -> // 추천순
store.bookmarkCount.lt(stdStore.getBookmarkCount());
case "review" -> // 후기순
store.reviewCount.lt(stdStore.getReviewCount());
case "rate" -> // 평점순
store.rateCount.lt(stdStore.getRateCount());
case "id" -> // 최신순
store.id.lt(stdStore.getId());
default -> null;
};
if(order.getDirection().isAscending()) {
switch (order.getProperty()) {
case "bookmark" : // 추천순
return store.bookmarkCount.goe(stdStore.getBookmarkCount()).and(store.id.ne(stdStore.getId()));
case "review" : // 후기순
return store.reviewCount.goe(stdStore.getReviewCount()).and(store.id.ne(stdStore.getId()));
case "rate" : // 평점순
return store.rateCount.goe(stdStore.getRateCount()).and(store.id.ne(stdStore.getId()));
case "id" : // 최신순
return store.id.gt(stdStore.getId());
default :
return null;
}
} else {
switch (order.getProperty()) {
case "bookmark" : // 추천순
return store.bookmarkCount.loe(stdStore.getBookmarkCount()).and(store.id.ne(stdStore.getId()));
case "review" : // 후기순
return store.reviewCount.loe(stdStore.getReviewCount()).and(store.id.ne(stdStore.getId()));
case "rate" : // 평점순
return store.rateCount.loe(stdStore.getRateCount()).and(store.id.ne(stdStore.getId()));
case "id" : // 최신순
return store.id.lt(stdStore.getId());
default :
return null;
}
}
}

return null;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/kusitms/jipbap/store/StoreService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kusitms.jipbap.store;

import com.kusitms.jipbap.store.dto.BookmarkedStoreListResponseDto;
import com.kusitms.jipbap.store.dto.RegisterStoreRequestDto;
import com.kusitms.jipbap.store.dto.StoreDetailResponseDto;
import com.kusitms.jipbap.store.dto.StoreDto;
Expand All @@ -15,6 +16,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -62,6 +66,47 @@ public StoreDetailResponseDto getStoreDetail(String email, Long storeId) {
);
}

@Transactional
public StoreDto bookmarkStore(String email, Long storeId) {
User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다."));
Store store = storeRepository.findById(storeId).orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다."));

storeBookmarkRepository.save(new StoreBookmark(null, user, store));

return new StoreDto(
null,
store.getName(),
store.getDescription(),
store.getKoreanYn(),
store.getAvgRate(),
store.getMinOrderAmount(),
store.getImage()
);
}

@Transactional
public BookmarkedStoreListResponseDto findBookmarkedStore(String email) {
User user = userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다."));

List<StoreBookmark> storeBookmarks = storeBookmarkRepository.findByUser(user);
List<StoreDto> sbList = new ArrayList<>();

for (StoreBookmark sb : storeBookmarks) {
sbList.add(new StoreDto(
sb.getId(),
sb.getStore().getName(),
sb.getStore().getDescription(),
sb.getStore().getKoreanYn(),
sb.getStore().getAvgRate(),
sb.getStore().getMinOrderAmount(),
sb.getStore().getImage()
)
);
}

return new BookmarkedStoreListResponseDto(sbList);
}

private Boolean isStoreBookmarked(User user, Store store){
return storeBookmarkRepository.existsByUserAndStore(user, store);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kusitms.jipbap.store.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@AllArgsConstructor
public class BookmarkedStoreListResponseDto {

private List<StoreDto> stores;
}

0 comments on commit a7098d0

Please sign in to comment.