Skip to content

Commit

Permalink
Merge pull request #26 from 9oormthon-univ/feat/store
Browse files Browse the repository at this point in the history
[FEAT] 가게 검색 구현
  • Loading branch information
ryuwon2407 authored Nov 22, 2024
2 parents bf48443 + 70bad86 commit 8b1a9f1
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 27 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ dependencies {
// iamport
implementation 'com.github.iamport:iamport-rest-client-java:0.1.6'

// spring security
implementation("org.springframework.boot:spring-boot-starter-security")

// 휴대폰 인증 API (nurigo)
implementation 'net.nurigo:sdk:4.3.0'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import lombok.RequiredArgsConstructor;

// 해당 코드는 Jwt 전체에 대해 검증하는 것이 아닌 애플 로그인떄 받아오는 itentity token 검증용
@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.groom.swipo.domain.payment.dto.request;

import com.groom.swipo.domain.payment.entity.Pay;
import com.groom.swipo.domain.payment.entity.Paylist;
import com.groom.swipo.domain.store.entity.Store;

public record PaymentCompleteRequest(
Long storeId,
String password,
Integer amount,
Integer usedPoints
) {
public Paylist toEntity(Pay pay, Store store) {
return Paylist.builder()
.value(amount - usedPoints)
.pay(pay)
.store(store)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.groom.swipo.domain.payment.entity;

import com.groom.swipo.domain.store.entity.Store;
import com.groom.swipo.global.common.enums.Area;
import com.groom.swipo.global.entity.BaseEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand Down Expand Up @@ -42,7 +39,9 @@ public class Paylist extends BaseEntity {
private Store store;

@Builder
private Paylist(long value) {
private Paylist(long value, Pay pay, Store store) {
this.value = value;
this.pay = pay;
this.store = store;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import java.security.Principal;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.groom.swipo.domain.payment.dto.request.PaymentCompleteRequest;
import com.groom.swipo.domain.payment.dto.response.PaymentCompleteResponse;
import com.groom.swipo.domain.payment.dto.response.PaymentPageResponse;
import com.groom.swipo.domain.payment.entity.Paylist;
import com.groom.swipo.domain.payment.exception.PasswordMismatchException;
import com.groom.swipo.domain.point.entity.Card;
import com.groom.swipo.domain.point.exception.CardNotFoundException;
Expand All @@ -28,6 +30,7 @@ public class PaymentService {

private final UserRepository userRepository;
private final StoreRepository storeRepository;
private final PasswordEncoder passwordEncoder;

public PaymentPageResponse getPaymentPage(Long storeId, Principal principal) {
Long userId = Long.parseLong(principal.getName());
Expand All @@ -53,7 +56,7 @@ public PaymentCompleteResponse completePayment(PaymentCompleteRequest request, P
.findFirst()
.orElseThrow(CardNotFoundException::new);

if (!user.getPassword().equals(request.password())) {
if (!passwordEncoder.matches(request.password(), user.getPassword())) {
throw new PasswordMismatchException();
}

Expand All @@ -67,6 +70,9 @@ public PaymentCompleteResponse completePayment(PaymentCompleteRequest request, P
user.getPay().updatePay(-netPayment);
card.updatePoint(earnedPoints - request.usedPoints());

Paylist paylist = request.toEntity(user.getPay(), store);
user.getPay().getPaylists().add(paylist);

return PaymentCompleteResponse.of(request.amount(), earnedPoints, user.getPay().getTotalPay());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public record PieceInfo(
String myPieceId,
String pieceName
) {
public static PieceInfo from(MyPiece myPiece,Piece piece) {
public static PieceInfo of(MyPiece myPiece,Piece piece) {
return PieceInfo.builder()
.myPieceId(String.valueOf(myPiece.getId()))
.pieceName(piece.getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.groom.swipo.domain.point.entity;

import com.groom.swipo.domain.store.entity.Store;
import com.groom.swipo.global.common.enums.Area;
import com.groom.swipo.global.entity.BaseEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand Down Expand Up @@ -45,4 +42,4 @@ public class Cardlist extends BaseEntity {
private Cardlist(long value) {
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import com.groom.swipo.domain.point.dto.PieceInfo;
import com.groom.swipo.domain.point.entity.MyPiece;
import com.groom.swipo.domain.user.entity.User;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public SwipstoneResponse getSwipstone(Principal principal) {
}

List<PieceInfo> pieces = myPieces.stream()
.map(myPiece -> PieceInfo.from(myPiece, myPiece.getPiece()))
.map(myPiece -> PieceInfo.of(myPiece, myPiece.getPiece()))
.toList();

Integer piecesNum = pieces.size();
Expand Down Expand Up @@ -71,4 +71,4 @@ public SwipstoneSwapResponse swapSwipstone(SwipstoneSwapRequest request, Princip

return new SwipstoneSwapResponse(pay.getTotalPay());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.groom.swipo.domain.store.dto.response.MapQueryResponse;
import com.groom.swipo.domain.store.dto.response.MapStoreDetailResponse;
import com.groom.swipo.domain.store.dto.response.MapTabViewResponse;
import com.groom.swipo.domain.store.dto.response.StoreSearchResponse;
import com.groom.swipo.domain.store.service.ReviewsService;
import com.groom.swipo.domain.store.service.StoreService;
import com.groom.swipo.domain.store.service.WishlistService;
Expand Down Expand Up @@ -125,4 +126,28 @@ public ResTemplate<MapTabViewResponse> getStoreTabs(Principal principal) {
MapTabViewResponse data = storeService.getStoreTabs(principal);
return new ResTemplate<>(HttpStatus.OK, "탭별 가게 조회 성공", data);
}

@GetMapping("/search")
@Operation(
summary = "가게 검색",
description = "키워드, 카테고리, 타입별, 페이지로 필터링된 가게 리스트를 반환합니다.",
responses = {
@ApiResponse(responseCode = "200", description = "가게 검색 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청"),
@ApiResponse(responseCode = "401", description = "인증되지 않은 요청"),
@ApiResponse(responseCode = "403", description = "페이지 접근 권한이 없음"),
@ApiResponse(responseCode = "404", description = "요청한 리소스를 찾을 수 없음"),
@ApiResponse(responseCode = "500", description = "서버 오류")
}
)
public ResTemplate<StoreSearchResponse> searchStores(
@RequestParam(name = "keyword") String keyword,
@RequestParam(name = "category", defaultValue = "all") String category,
@RequestParam(name = "type") String type,
@RequestParam(name = "page", defaultValue = "0") int page,
Principal principal
) {
StoreSearchResponse data = storeService.searchStores(keyword, category, type, page, principal);
return new ResTemplate<>(HttpStatus.OK, "가게 검색 성공", data);
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/groom/swipo/domain/store/dto/StoreDetail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.groom.swipo.domain.store.dto;

import java.util.List;

import com.groom.swipo.domain.store.entity.Store;

import lombok.Builder;

@Builder
public record StoreDetail(
Long storeId,
String name,
String address,
Integer percent,
Double stars,
boolean isWish,
Integer reviewsNum,
String review,
Integer imagesNum,
List<String> imageUrls
) {
public static StoreDetail of(Store store, Double stars, boolean isWish, String review, List<String> images) {
return StoreDetail.builder()
.storeId(store.getId())
.name(store.getName())
.address(store.getAddress())
.percent(store.getPercent())
.stars(stars)
.isWish(isWish)
.reviewsNum(store.getReviews().size())
.review(review)
.imagesNum(images.size())
.imageUrls(images)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.groom.swipo.domain.store.dto.response;

import java.util.List;

import com.groom.swipo.domain.store.dto.StoreDetail;
import com.groom.swipo.global.common.PageInfo;

import lombok.Builder;

@Builder
public record StoreSearchResponse(
PageInfo pageInfo,
List<StoreDetail> stores
) {
public static StoreSearchResponse of(PageInfo pageInfo, List<StoreDetail> stores) {
return StoreSearchResponse.builder()
.pageInfo(pageInfo)
.stores(stores)
.build();
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/groom/swipo/domain/store/entity/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.groom.swipo.domain.payment.entity.Paylist;
import com.groom.swipo.domain.point.entity.Cardlist;
import com.groom.swipo.domain.point.entity.MyPiece;
import com.groom.swipo.domain.store.entity.enums.StoreCategory;
import com.groom.swipo.domain.store.entity.enums.StoreType;
import com.groom.swipo.global.common.enums.Area;
import com.groom.swipo.global.entity.BaseEntity;
Expand Down Expand Up @@ -38,9 +39,13 @@ public class Store extends BaseEntity {
private String name;

@Enumerated(EnumType.STRING)
@Column(nullable = false, length = 20)
@Column(nullable = false)
private StoreType type;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private StoreCategory category;

private String address;

@Column(nullable = false)
Expand Down Expand Up @@ -83,9 +88,11 @@ public class Store extends BaseEntity {

// 기타
@Builder
private Store(String name, StoreType type, String address, Double latitude, Double longitude, Integer percent) {
private Store(String name, StoreType type, StoreCategory category, String address, Double latitude,
Double longitude, Integer percent) {
this.name = name;
this.type = type;
this.category = category;
this.address = address;
this.latitude = latitude;
this.longitude = longitude;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.groom.swipo.domain.store.entity.enums;

public enum StoreCategory {
CAFE, DESSERT, RESTAURANT, MART, PROP, LODGMENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ List<Store> findStoresWithinRadius(
@Param("longitude") double longitude,
@Param("radius") double radius
);

// 관심 등록 수가 많은 순으로 가게 조회
@Query("""
SELECT s FROM Store s
LEFT JOIN s.wishlists w ON w.isWish = true
GROUP BY s
ORDER BY COUNT(w) DESC
""")
List<Store> findPopularStores();

// 별점 평균이 높은 순으로 가게 조회
@Query("""
SELECT s FROM Store s
LEFT JOIN s.reviews r
GROUP BY s
ORDER BY COALESCE(AVG(r.star), 0) DESC
""")
List<Store> findTopRatedStores();
}
Loading

0 comments on commit 8b1a9f1

Please sign in to comment.