Skip to content

Commit

Permalink
Merge pull request #60 from lotteon2/refactor
Browse files Browse the repository at this point in the history
✏️ QA 수정사항 반영
  • Loading branch information
qwerty1434 authored Jan 16, 2024
2 parents ad536d7 + bd5f587 commit 2f3145e
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {
implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.4.RELEASE'
implementation 'software.amazon.awssdk:sns:2.21.37'

implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '202401121522'
implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '202401160417'
}

dependencyManagement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void plusStocksWithLock(List<StockChangeDto> stockChangeDtos) {
} catch (Exception e) {
Long userId = stockChangeDtos.get(0).getUserId();
String phoneNumber = stockChangeDtos.get(0).getPhoneNumber();
orderStatusSQSPublisher.publish(userId, phoneNumber, NotificationKind.ORDER_FAIL);
orderStatusSQSPublisher.publish(userId, phoneNumber, NotificationKind.OUT_OF_STOCK);

throw e;
}
Expand All @@ -76,7 +76,7 @@ public void minusStocksWithLock(List<StockChangeDto> stockChangeDtos) {
} catch (Exception e) {
Long userId = stockChangeDtos.get(0).getUserId();
String phoneNumber = stockChangeDtos.get(0).getPhoneNumber();
orderStatusSQSPublisher.publish(userId, phoneNumber, NotificationKind.ORDER_FAIL);
orderStatusSQSPublisher.publish(userId, phoneNumber, NotificationKind.OUT_OF_STOCK);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void downloadAllCoupons(@PathVariable Long storeId,
@GetMapping("/{storeId}/coupons/product")
public CommonResponse<CouponsForUserResponse> storeCouponsForUser(@PathVariable Long storeId,
@RequestHeader(value = "userId", required = false) Long userId) {

LocalDate now = LocalDate.now();
return CommonResponse.success(couponFacade.getAllStoreCouponsForUser(userId, storeId, now));
}
Expand All @@ -68,14 +67,12 @@ public CommonResponse<CouponsForUserResponse> storeCouponsForUser(@PathVariable
public CommonResponse<CouponsForUserResponse> couponsInPaymentStep(@PathVariable Long storeId,
@RequestHeader(value = "userId") Long userId,
@RequestBody TotalAmountRequest totalAmountRequest) {

LocalDate now = LocalDate.now();
return CommonResponse.success(couponFacade.getAvailableCouponsInPayment(totalAmountRequest, userId, storeId, now));
}

@GetMapping("/coupons/my")
public CommonResponse<CouponsForUserResponse> myCoupons(@RequestHeader(value = "userId") Long userId) {

LocalDate now = LocalDate.now();
return CommonResponse.success(couponFacade.getMyValidCoupons(userId, now));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public void useCoupon(@PathVariable Long couponId, @PathVariable Long userId) {
@GetMapping("/count")
public CommonResponse<Integer> availableCouponCountOfUser(@RequestHeader(value = "userId") Long userId) {
LocalDate now = LocalDate.now();

return CommonResponse.success(couponService.getMyAvailableCouponCount(userId, now));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public class IssuedCouponId implements Serializable {
private Long couponId;
private Long userId;






@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public void softDeleteCoupon(Long storeId, Long couponId) {
}

public CouponsForOwnerResponse getAllStoreCoupons(Long storeId) {
return CouponsForOwnerResponse.from(couponService.getAllStoreCoupons(storeId));
LocalDate now = LocalDate.now();
return CouponsForOwnerResponse.from(couponService.getAllStoreCoupons(storeId, now));
}


public void downloadCoupon(Long userId, Long couponId, String nickname, String phoneNumber, LocalDate now) {
couponService.downloadCoupon(userId, couponId, nickname, phoneNumber, now);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public void issuePossibleCoupons(List<Coupon> coupons, Long userId, String nickn
.filter(coupon -> {
String redisKey = makeRedisKey(coupon);
Integer limitCnt = coupon.getLimitCount();
boolean issuable = (Boolean)redisLuaScriptExecutor.execute(script, redisKey, redisValue, limitCnt);
return issuable;
return (Boolean)redisLuaScriptExecutor.execute(script, redisKey, redisValue, limitCnt);
})
.forEach(coupon -> issuedCouponRepository.save(makeIssuedCoupon(coupon,userId,nickname,phoneNumber)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public Coupon read(Long couponId) {
return couponRepository.findById(couponId).orElseThrow(CouponNotFoundException::new);
}

public List<CouponForOwnerDto> readCouponsForOwner(Long storeId) {
return couponRepository.findAllDtoByStoreId(storeId);
public List<CouponForOwnerDto> readCouponsForOwner(Long storeId, LocalDate now) {
return couponRepository.findAllDtoByStoreId(storeId, now);
}

public List<Coupon> readStoresAllValidateCoupon(Long storeId, LocalDate now) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.List;

public interface CouponRepositoryCustom {
List<CouponForOwnerDto> findAllDtoByStoreId(Long storeId);
List<CouponForOwnerDto> findAllDtoByStoreId(Long storeId, LocalDate now);
List<Coupon> findAllDownloadableCouponsByStoreId(Long storeId, LocalDate now);
List<CouponWithIssueStatusDto> findStoreCouponsForUser(Long userId, Long storeId, LocalDate now);
List<CouponWithAvailabilityDto> findAvailableCoupons(Long totalAmount, Long userId, Long storeId, LocalDate now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public CouponRepositoryCustomImpl(EntityManager em) {
}

@Override
public List<CouponForOwnerDto> findAllDtoByStoreId(Long storeId) {
public List<CouponForOwnerDto> findAllDtoByStoreId(Long storeId, LocalDate now) {
return queryFactory
.select(new QCouponForOwnerDto(
coupon.id,
Expand All @@ -43,18 +43,8 @@ public List<CouponForOwnerDto> findAllDtoByStoreId(Long storeId) {
.on(coupon.id.eq(issuedCoupon.id.couponId))
.where(
coupon.store.id.eq(storeId),
coupon.isDeleted.isFalse()
)
.groupBy(
coupon.store.id,
coupon.couponCode,
coupon.couponName,
coupon.minPrice,
coupon.discountPrice,
coupon.limitCount,
coupon.startDate,
coupon.endDate,
coupon.id
coupon.isDeleted.isFalse(),
coupon.endDate.loe(now)
)
.fetch();
}
Expand Down Expand Up @@ -97,7 +87,8 @@ public List<CouponWithIssueStatusDto> findStoreCouponsForUser(Long userId, Long
.where(
coupon.store.id.eq(storeId),
isCouponUnexpired(now),
coupon.isDeleted.isFalse()
coupon.isDeleted.isFalse(),
coupon.startDate.loe(now)
)
.fetch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import kr.bb.store.domain.store.handler.StoreReader;
import kr.bb.store.util.RedisOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static kr.bb.store.util.RedisUtils.makeRedisKey;
Expand Down Expand Up @@ -98,8 +98,8 @@ public void unUseAllCoupons(List<Long> couponIds, Long userId) {
});
}

public List<CouponForOwnerDto> getAllStoreCoupons(Long storeId) {
return couponReader.readCouponsForOwner(storeId);
public List<CouponForOwnerDto> getAllStoreCoupons(Long storeId, LocalDate now) {
return couponReader.readCouponsForOwner(storeId, now);
}

public List<CouponWithIssueStatusDto> getAllStoreCouponsForUser(Long userId, Long storeId, LocalDate now) {
Expand Down Expand Up @@ -134,7 +134,7 @@ public Integer getMyAvailableCouponCount(Long userId, LocalDate now) {

public void validateCouponPrice(List<ValidatePriceDto> validatePriceDtos) {
validatePriceDtos.stream()
.filter(dto -> dto.getCouponId() != null)
.filter(dto -> Objects.nonNull(dto.getCouponId()))
.forEach(dto -> {
Coupon coupon = couponReader.read(dto.getCouponId());
Long receivedPaymentPrice = dto.getActualAmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public Page<QuestionForOwnerDto> getQuestionsForStoreOwnerWithPaging(Long storeI
.rightJoin(answer.question, question)
.where(
isReplied != null ? checkRepliedCondition(isReplied) : null,
question.isDeleted.isFalse()
question.isDeleted.isFalse(),
question.store.id.eq(storeId)
)
.orderBy(question.createdAt.desc())
.limit(pageable.getPageSize())
Expand All @@ -52,7 +53,8 @@ public Page<QuestionForOwnerDto> getQuestionsForStoreOwnerWithPaging(Long storeI
.rightJoin(answer.question, question)
.where(
isReplied != null ? checkRepliedCondition(isReplied) : null,
question.isDeleted.isFalse()
question.isDeleted.isFalse(),
question.store.id.eq(storeId)
)
.fetchOne();
return new PageImpl<>(contents,pageable,count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
public interface GugunRepository extends JpaRepository<Gugun,String> {

List<Gugun> findGugunBySidoCode(String sidoCode);
Optional<Gugun> findByName(String name);
Optional<Gugun> findBySidoAndName(Sido sido, String name);
}
20 changes: 10 additions & 10 deletions src/main/java/kr/bb/store/domain/store/facade/StoreFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import bloomingblooms.domain.flower.FlowerDto;
import bloomingblooms.domain.notification.order.OrderType;
import bloomingblooms.domain.order.ValidatePolicyDto;
import bloomingblooms.domain.store.StoreAverageDto;
import bloomingblooms.domain.store.StoreInfoDto;
import bloomingblooms.domain.store.StoreNameAndAddressDto;
import bloomingblooms.domain.store.StorePolicy;
Expand Down Expand Up @@ -47,8 +48,8 @@ public class StoreFacade {

@KafkaListener(topics = "store-average-rating-update", groupId = "average-rating")
@CacheEvict(cacheNames = "store-list-with-paging", allEntries = true)
public void updateAverageRating(Map<Long,Double> averageRatings) {
storeService.updateAverageRating(averageRatings);
public void updateAverageRating(StoreAverageDto storeAverageDto) {
storeService.updateAverageRating(storeAverageDto.getAverage());
log.info("stores averageRating updated");
}

Expand Down Expand Up @@ -78,7 +79,7 @@ public SimpleStorePagingResponse getStoresWithLikes(Long userId, Pageable pageab
.map(StoreListResponse::getStoreId)
.collect(Collectors.toList());

if(isNotGuest(userId)) {
if(isLoginUser(userId)) {
Map<Long, Boolean> storeLikes = storeLikeFeignClient.getStoreLikes(userId, storeIds).getData();
storePages.getContent().forEach(store -> store.setIsLiked(storeLikes.get(store.getStoreId())));
}
Expand All @@ -92,16 +93,17 @@ public SimpleStorePagingResponse getStoresWithLikes(Long userId, Pageable pageab
public StoreInfoUserResponse getStoreInfoForUser(Long userId, Long storeId) {
String subscriptionProductId = productFeignClient.getSubscriptionProductId(storeId).getData()
.getSubscriptionProductId();
if(isNotGuest(userId)) {

if(isLoginUser(userId)) {
Map<Long, Boolean> storeLikes = storeLikeFeignClient.getStoreLikes(userId, List.of(storeId)).getData();
Map<Long, Boolean> storeSubscriptions = storeSubscriptionFeignClient
.getStoreSubscriptions(userId, List.of(storeId)).getData();
Boolean isLiked = storeLikes.get(storeId);
Boolean isSubscribed = storeSubscriptions.get(storeId);
return storeService.getStoreInfoForUser(storeId, isLiked, isSubscribed, subscriptionProductId);
}
return storeService.getStoreInfoForUser(storeId, false, false, subscriptionProductId);

return storeService.getStoreInfoForUser(storeId, false, false, subscriptionProductId);
}

public StoreInfoManagerResponse getStoreInfoForManager(Long storeId) {
Expand All @@ -111,7 +113,7 @@ public StoreInfoManagerResponse getStoreInfoForManager(Long storeId) {
public StoreListForMapResponse getNearbyStores(Long userId, Double lat, Double lon, Integer level) {
StoreListForMapResponse nearbyStores = storeService.getNearbyStores(lat, lon, level);

if(isNotGuest(userId)) {
if(isLoginUser(userId)) {
List<Long> storeIds = nearbyStores.getStoreIds();
Map<Long, Boolean> storeLikes = storeLikeFeignClient.getStoreLikes(userId, storeIds).getData();
nearbyStores.setLikes(storeLikes);
Expand All @@ -123,7 +125,7 @@ public StoreListForMapResponse getNearbyStores(Long userId, Double lat, Double l
public StoreListForMapResponse getStoresWithRegion(Long userId, String sidoCode, String gugunCode) {
StoreListForMapResponse storesWithRegion = storeService.getStoresWithRegion(sidoCode, gugunCode);

if(isNotGuest(userId)) {
if(isLoginUser(userId)) {
List<Long> storeIds = storesWithRegion.getStoreIds();
Map<Long, Boolean> storeLikes = storeLikeFeignClient.getStoreLikes(userId, storeIds).getData();
storesWithRegion.setLikes(storeLikes);
Expand Down Expand Up @@ -180,7 +182,6 @@ public List<SettlementStoreInfoResponse> storeInfoForSettlement(List<Long> store
return storeService.storeInfoForSettlement(storeIds);
}


public DeliveryPolicyDto getDeliveryPolicy(Long storeId) {
return storeService.getDeliveryPolicy(storeId);
}
Expand All @@ -197,7 +198,6 @@ public StoreForAdminDtoResponse getStoresForAdmin(Pageable pageable, SortType so
.collect(Collectors.toList());

return StoreForAdminDtoResponse.of(data, storesForAdmin.getTotalElements());

}

public List<SidoDto> getAllSido() {
Expand All @@ -208,7 +208,7 @@ public List<GugunDto> getGuguns(String sidoCode) {
return storeService.getGuguns(sidoCode);
}

private boolean isNotGuest(Long userId) {
private boolean isLoginUser(Long userId) {
return userId != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public class GugunReader {
private final GugunRepository gugunRepository;

public Gugun readGugunCorrespondingSido(Sido sido, String gugunName) {
Gugun gugun = gugunRepository.findByName(gugunName)
Gugun gugun = gugunRepository.findBySidoAndName(sido, gugunName)
.orElseThrow(GugunNotFoundException::new);
if(!gugun.getSido().getCode().equals(sido.getCode())) {
throw new InvalidParentException();
}
return gugun;
}

public Gugun readGugunCorrespondingSidoWithCode(Sido sido, String gugunCode) {
Gugun gugun = gugunRepository.findById(gugunCode)
.orElseThrow(GugunNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ private Double levelToMeter(int level) {
default:
throw new IllegalArgumentException("정의되지 않은 레벨입니다");
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public StoreInfoManagerResponse getStoreInfoForManager(Long storeId) {
public StoreListForMapResponse getNearbyStores(Double lat, Double lon, Integer level) {
return storeReader.getNearbyStores(lat, lon, level);
}

public StoreListForMapResponse getStoresWithRegion(String sidoCode, String gugunCode) {
Sido sido = sidoReader.readSido(sidoCode);
Gugun gugun = "".equals(gugunCode) ? null : gugunReader.readGugunCorrespondingSidoWithCode(sido, gugunCode);
Expand Down Expand Up @@ -173,10 +174,8 @@ public List<SettlementStoreInfoResponse> storeInfoForSettlement(List<Long> store
.gugun(storeAddresses.get(id).getGugun().getName())
.build()
).collect(Collectors.toList());

}


public DeliveryPolicyDto getDeliveryPolicy(Long storeId) {
DeliveryPolicy deliveryPolicy = storeReader.findDeliveryPolicyByStoreId(storeId);
return DeliveryPolicyDto.fromEntity(deliveryPolicy);
Expand Down Expand Up @@ -210,7 +209,6 @@ public Page<Store> getStoresForAdmin(Pageable pageable, SortType sort, String si
}
}


public List<SidoDto> getAllSido() {
return sidoReader.readAll()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void readCouponsForOwner() {
couponRepository.saveAll(List.of(c1,c2));

// when
List<CouponForOwnerDto> result = couponReader.readCouponsForOwner(store.getId());
List<CouponForOwnerDto> result = couponReader.readCouponsForOwner(store.getId(), LocalDate.now());

// then
assertThat(result).hasSize(2);
Expand All @@ -67,7 +67,7 @@ void couponCountWillEqualIfNobodyIssueTheCoupon() {
couponRepository.save(c1);

// when
List<CouponForOwnerDto> result = couponReader.readCouponsForOwner(store.getId());
List<CouponForOwnerDto> result = couponReader.readCouponsForOwner(store.getId(), LocalDate.now());

// then
assertThat(result.get(0).getUnusedCount()).isEqualTo(c1.getLimitCount());
Expand All @@ -87,7 +87,7 @@ void unUsedCountWillDecreaseWhenUserIssueCoupon() {
issuedCouponRepository.save(createIssuedCoupon(c1, userId));

// when
List<CouponForOwnerDto> result = couponReader.readCouponsForOwner(store.getId());
List<CouponForOwnerDto> result = couponReader.readCouponsForOwner(store.getId(), LocalDate.now());

// then
assertThat(result.get(0).getUnusedCount()).isEqualTo(99);
Expand Down

0 comments on commit 2f3145e

Please sign in to comment.