Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #74 from f-lab-edu/feature/mock_pay_test
Browse files Browse the repository at this point in the history
[#75, #72] 패키지 구조 변경, 가상결제 테스트 작성
  • Loading branch information
yyy9942 authored Feb 12, 2020
2 parents ec74ca5 + d2184cb commit 0055f16
Show file tree
Hide file tree
Showing 105 changed files with 705 additions and 281 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/delfood/config/RedisConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public ObjectMapper objectMapper() {
@Bean
public RedisConnectionFactory redisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
redisStandaloneConfiguration.setPort(redisPort);
redisStandaloneConfiguration.setHostName(redisHost);
redisStandaloneConfiguration.setPassword(redisPwd);
LettuceConnectionFactory lettuceConnectionFactory =
new LettuceConnectionFactory(redisStandaloneConfiguration);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/delfood/controller/CartControllelr.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.delfood.aop.LoginCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.dto.order.item.ItemDTO;
import com.delfood.aop.MemberLoginCheck;
import com.delfood.dto.ItemDTO;
import com.delfood.service.CartService;
import com.delfood.utils.SessionUtil;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/delfood/controller/CouponController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.delfood.controller;

import com.delfood.dto.CouponDTO;
import com.delfood.dto.order.coupon.CouponDTO;
import com.delfood.service.CouponService;
import lombok.extern.log4j.Log4j2;
import java.time.LocalDateTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.delfood.aop.LoginCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.dto.order.coupon.CouponIssueDTO;
import com.delfood.aop.MemberLoginCheck;
import com.delfood.dto.CouponIssueDTO;
import com.delfood.service.CouponIssueService;
import com.delfood.utils.SessionUtil;
import java.util.List;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/delfood/controller/LocationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.delfood.aop.OwnerShopCheck;
import com.delfood.controller.reqeust.GetAddressByZipRequest;
import com.delfood.controller.reqeust.GetAddressesByRoadRequest;
import com.delfood.dto.AddressDTO;
import com.delfood.dto.DeliveryLocationDTO;
import com.delfood.dto.address.AddressDTO;
import com.delfood.dto.address.DeliveryLocationDTO;
import com.delfood.service.AddressService;
import com.delfood.service.ShopService;
import java.util.List;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/delfood/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.delfood.aop.LoginCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.dto.member.MemberDTO;
import com.delfood.aop.MemberLoginCheck;
import com.delfood.dto.MemberDTO;
import com.delfood.error.exception.DuplicateIdException;
import com.delfood.service.MemberService;
import com.delfood.service.PushService;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/delfood/controller/MenuController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.delfood.controller;

import com.delfood.dto.MenuDTO;
import com.delfood.dto.OptionDTO;
import com.delfood.dto.menu.MenuDTO;
import com.delfood.dto.menu.OptionDTO;
import com.delfood.service.MenuService;
import com.delfood.service.OptionService;
import java.util.List;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/delfood/controller/MenuGroupController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.delfood.controller;

import com.delfood.dto.MenuGroupDTO;
import com.delfood.dto.ShopDTO;
import com.delfood.dto.menu.MenuGroupDTO;
import com.delfood.dto.shop.ShopDTO;
import com.delfood.service.MenuGroupService;
import com.delfood.service.ShopService;
import com.delfood.utils.SessionUtil;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/delfood/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import com.delfood.aop.MemberLoginCheck;
import com.delfood.aop.OwnerLoginCheck;
import com.delfood.controller.response.OrderResponse;
import com.delfood.dto.ItemsBillDTO;
import com.delfood.dto.OrderDTO;
import com.delfood.dto.OrderItemDTO;
import com.delfood.dto.order.OrderDTO;
import com.delfood.dto.order.bill.ItemsBillDTO;
import com.delfood.dto.order.bill.OrderBillDTO;
import com.delfood.dto.order.item.OrderItemDTO;
import com.delfood.error.exception.coupon.IssuedCouponExistException;
import com.delfood.error.exception.order.TotalPriceMismatchException;
import com.delfood.dto.OrderBillDTO;
import com.delfood.service.CouponIssueService;
import com.delfood.service.OrderService;
import com.delfood.service.PushService;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/delfood/controller/OwnerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.delfood.aop.LoginCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.dto.owner.OwnerDTO;
import com.delfood.dto.owner.OwnerDTO.Status;
import com.delfood.aop.MemberLoginCheck;
import com.delfood.aop.OwnerLoginCheck;
import com.delfood.dto.OwnerDTO;
import com.delfood.dto.OwnerDTO.Status;
import com.delfood.error.exception.DuplicateIdException;
import com.delfood.service.OwnerService;
import com.delfood.service.PushService;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/delfood/controller/ShopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import com.delfood.aop.OwnerLoginCheck;
import com.delfood.aop.OwnerShopCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.dto.AddressDTO;
import com.delfood.dto.DeliveryLocationDTO;
import com.delfood.dto.OwnerDTO;
import com.delfood.dto.ShopDTO;
import com.delfood.dto.ShopUpdateDTO;
import com.delfood.dto.address.AddressDTO;
import com.delfood.dto.address.DeliveryLocationDTO;
import com.delfood.dto.owner.OwnerDTO;
import com.delfood.dto.shop.ShopDTO;
import com.delfood.dto.shop.ShopUpdateDTO;
import com.delfood.service.ShopService;
import com.delfood.utils.SessionUtil;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.delfood.aop.LoginCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.aop.MemberLoginCheck;
import com.delfood.dto.ShopCategoryDTO;
import com.delfood.dto.ShopDTO;
import com.delfood.dto.shop.ShopCategoryDTO;
import com.delfood.dto.shop.ShopDTO;
import com.delfood.service.MemberService;
import com.delfood.service.ShopSearchService;
import com.delfood.service.ShopService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.delfood.controller.response;

import com.delfood.dto.ItemsBillDTO;
import com.delfood.dto.order.bill.ItemsBillDTO;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/delfood/dao/CartDao.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.delfood.dao;

import com.delfood.dto.ItemDTO;
import com.delfood.dto.order.item.ItemDTO;
import com.delfood.utils.RedisKeyFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/delfood/dao/FcmDao.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.delfood.dao;

import com.delfood.dto.push.PushMessageForOne;
import com.delfood.utils.RedisKeyFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.firebase.messaging.Message;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/delfood/dao/deliveery/DeliveryDao.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.delfood.dao.deliveery;

import com.delfood.dto.OrderDTO.OrderStatus;
import com.delfood.dto.address.Position;
import com.delfood.dto.order.OrderDTO.OrderStatus;
import com.delfood.dto.rider.DeliveryRiderDTO;
import lombok.NonNull;
import java.util.List;

public interface DeliveryDao {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,29 @@
package com.delfood.dao.deliveery;

import com.delfood.dto.OrderDTO.OrderStatus;
import com.delfood.dto.address.Position;
import com.delfood.dto.order.OrderDTO.OrderStatus;
import com.delfood.dto.rider.DeliveryRiderDTO;
import com.delfood.service.OrderService;
import lombok.extern.log4j.Log4j2;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.annotation.concurrent.ThreadSafe;

import lombok.extern.log4j.Log4j2;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;

@Repository("multiThreadDeliveryDao")
@Repository("localMemoryDeliveryDao")
@ThreadSafe
@Log4j2
public class LocalMemoryDeliveryDao implements DeliveryDao{
private ConcurrentHashMap<String, DeliveryRiderDTO> riders;
private ConcurrentHashMap<Long, OrderStatus> orders;

@Value("${rider.expire}")
@Value("${expire.fcm.rider}")
private Long expireTime;

@Autowired
Expand Down
139 changes: 139 additions & 0 deletions src/main/java/com/delfood/dao/deliveery/RedisDeliveryDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.delfood.dao.deliveery;

import com.delfood.dto.order.OrderDTO.OrderStatus;
import com.delfood.dto.rider.DeliveryRiderDTO;
import com.delfood.service.OrderService;
import com.delfood.utils.RedisKeyFactory;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

@Log4j2
@Repository("redisDeliveryDao")
public class RedisDeliveryDao implements DeliveryDao {

@Autowired
private RedisTemplate<String, Object> redisTemplate;

@Autowired
private ObjectMapper objectMapper;

@Value("${expire.rider}")
public Long expireTime;

private OrderService orderService;

@Override
public void updateRiderInfo(DeliveryRiderDTO riderInfo) {
redisTemplate.opsForHash().put(RedisKeyFactory.DELIVERY_KEY, riderInfo.getRiderId(), riderInfo);
}

@Override
public boolean deleteRiderInfo(String riderId) {
return redisTemplate.opsForHash().delete(RedisKeyFactory.DELIVERY_KEY, riderId) != null;
}

@Override
public boolean hasRiderInfo(String riderId) {
return redisTemplate.opsForHash().hasKey(RedisKeyFactory.DELIVERY_KEY, riderId);
}

/**
* 특정 시점을 기준으로 일정시간 자신의 위치를 업데이트하지 않은 라이더들을 삭제한다. 일정 시점을 기준으로 하기에 동시성 제어가 필요하지 않다.
*
* @author jun
*/
@Override
public void deleteNonUpdatedRiders() {
LocalDateTime now = LocalDateTime.now();
Set<Object> keys = redisTemplate.opsForHash().keys(RedisKeyFactory.DELIVERY_KEY);
keys.stream().forEach(key -> {
Object obj = redisTemplate.opsForHash().get(RedisKeyFactory.DELIVERY_KEY, key);
if (Objects.isNull(obj) == false) {
DeliveryRiderDTO riderInfo = objectMapper.convertValue(obj, DeliveryRiderDTO.class);
if (ChronoUnit.SECONDS.between(riderInfo.getUpdatedAt(), now) > expireTime) {
redisTemplate.opsForHash().delete(RedisKeyFactory.DELIVERY_KEY, key);
log.info("Rider '{}' (이)가 스케줄에 의해 삭제됨", key);
}
}
});
}

@Override
public DeliveryRiderDTO getRiderInfo(String riderId) {
return objectMapper.convertValue(
redisTemplate.opsForHash().get(RedisKeyFactory.DELIVERY_KEY, riderId),
DeliveryRiderDTO.class);
}

@Override
public List<DeliveryRiderDTO> getRiderList() {
redisTemplate.watch(RedisKeyFactory.DELIVERY_KEY);
List<DeliveryRiderDTO> riderList;
try {
List<Object> objList = redisTemplate.opsForHash().values(RedisKeyFactory.DELIVERY_KEY);
riderList = objList.stream().map(e -> objectMapper.convertValue(e, DeliveryRiderDTO.class))
.collect(Collectors.toList());
} finally {
redisTemplate.unwatch();
}
return riderList;
}

@Override
public void deleteAll(List<String> idList) {
redisTemplate.watch(RedisKeyFactory.DELIVERY_KEY);
try {
redisTemplate.multi();
idList.stream().forEach(id -> redisTemplate.delete(id));
redisTemplate.exec();
} catch (Exception e) {
redisTemplate.discard();
} finally {
redisTemplate.unwatch();
}
}

/**
* Redis에 주문 상태 정보가 저장되어 있는지 확인한 후, 저장되어있으면 조회 후 리턴한다. 저장된 주문 정보가 없을 시 RDB에서 조회해 와 Redis에 저장한 후
* 리턴한다.
*
* @author jun
*/
@Override
public OrderStatus getOrderStatus(Long orderId) {
OrderStatus status;
redisTemplate.watch(RedisKeyFactory.ORDER_KEY);
try {
Object object = redisTemplate.opsForHash().get(RedisKeyFactory.ORDER_KEY, orderId);
if (Objects.isNull(object)) {
status = orderService.getOrderStatus(orderId);
redisTemplate.opsForHash().put(RedisKeyFactory.ORDER_KEY, orderId, status);
} else {
status = objectMapper.convertValue(object, OrderStatus.class);
}
} finally {
redisTemplate.unwatch();
}
return status;
}

@Override
public void setOrderStatus(Long orderId, OrderStatus status) {
redisTemplate.opsForHash().put(RedisKeyFactory.ORDER_KEY, orderId, status);
}

@Override
public void deleteOrderStatus(Long orderId) {
redisTemplate.opsForHash().delete(RedisKeyFactory.ORDER_KEY, orderId);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.delfood.dto;
package com.delfood.dto.address;

import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.delfood.dto;
package com.delfood.dto.address;

import java.time.LocalDateTime;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.delfood.dto;
package com.delfood.dto.member;

import java.time.LocalDateTime;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import org.springframework.lang.Nullable;
import com.delfood.dto.address.AddressDTO;

// 고객
@Getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.delfood.dto;
package com.delfood.dto.menu;

import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.delfood.dto;
package com.delfood.dto.menu;

import java.time.LocalDateTime;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.delfood.dto;
package com.delfood.dto.menu;

import java.time.LocalDateTime;
import java.util.List;
Expand Down
Loading

0 comments on commit 0055f16

Please sign in to comment.