This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from f-lab-edu/feature/mock_pay_test
- Loading branch information
Showing
105 changed files
with
705 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/delfood/controller/MenuGroupController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/com/delfood/controller/response/OrderResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 5 additions & 10 deletions
15
src/main/java/com/delfood/dao/deliveery/LocalMemoryDeliveryDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/main/java/com/delfood/dao/deliveery/RedisDeliveryDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...main/java/com/delfood/dto/AddressDTO.java → ...a/com/delfood/dto/address/AddressDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
2 changes: 1 addition & 1 deletion
2
.../com/delfood/dto/DeliveryLocationDTO.java → ...food/dto/address/DeliveryLocationDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
3 changes: 2 additions & 1 deletion
3
src/main/java/com/delfood/dto/MemberDTO.java → ...ava/com/delfood/dto/member/MemberDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...java/com/delfood/dto/MenuCategoryDTO.java → ...com/delfood/dto/menu/MenuCategoryDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/com/delfood/dto/MenuDTO.java → ...in/java/com/delfood/dto/menu/MenuDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
2 changes: 1 addition & 1 deletion
2
...in/java/com/delfood/dto/MenuGroupDTO.java → ...va/com/delfood/dto/menu/MenuGroupDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
Oops, something went wrong.