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

[#55] 푸시 서비스 적용 #57

Merged
merged 36 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fbdaacf
메뉴, 옵션 단위테스트 작성
Nov 27, 2019
ab9f140
리뷰 반영
Nov 28, 2019
a1b5b1e
Owner 테스트 코드 작성 및 리팩토링
binaryyoung Nov 29, 2019
dea9db1
- 코드리뷰 반영
binaryyoung Dec 3, 2019
96821c2
Merge pull request #39 from f-lab-edu/feature/16
yyy9942 Dec 3, 2019
518aa07
Merge pull request #47 from f-lab-edu/feature/15
yyy9942 Dec 3, 2019
dfd9740
Merge pull request #43 from f-lab-edu/feature/19
binaryyoung Dec 4, 2019
25f8710
- 쿠폰 추가 기능 생성
binaryyoung Dec 4, 2019
9f79e88
코드리뷰 반영 및 쿠폰 수정 삭제 기능 추가
binaryyoung Dec 12, 2019
ffb600d
- 코드리뷰 반영
binaryyoung Dec 14, 2019
2ac117f
- 발급 쿠폰 조회기능 추가 및 CouponIssueDTO 변경
binaryyoung Dec 16, 2019
8022847
주문시 사장님에게 푸시 메세지로 알림.
Dec 31, 2019
ac1d437
AddressService 테스트코드 작성
Dec 31, 2019
873fb5e
장바구니 서비스 대상 테스트코드 작성
Dec 31, 2019
39690d7
Merge pull request #58 from f-lab-edu/주소_서비스_테스트_코드_작성
yyy9942 Jan 3, 2020
f03803a
팩토리 메서드 개선
Jan 3, 2020
d1f8847
리뷰 반영
Jan 3, 2020
b7b4aed
Merge branch '푸시_서비스_적용' of https://github.com/f-lab-edu/food-deliver…
Jan 3, 2020
6fbfbad
버그, 오류 수정
Jan 3, 2020
e1d54a9
Merge pull request #60 from f-lab-edu/장바구니_서비스_테스트_코드_작성
yyy9942 Jan 6, 2020
5825d3a
Merge pull request #63 from f-lab-edu/주소_서비스_테스트_코드_작성
yyy9942 Jan 6, 2020
36d5957
Merge remote-tracking branch 'yyy9942/feature/21' into 푸시_서비스_적용
Jan 6, 2020
d67d94d
Coupon에 대한 테스트코드 작성
Jan 6, 2020
f7f8aaf
계산시 쿠폰 적용 기능 추가
Jan 6, 2020
64e21c8
- 내 주문 조회에서도 쿠폰 적용한 결과를 볼 수 있도록 수정
Jan 7, 2020
c040948
리뷰 반영
Jan 10, 2020
0f235c5
sql 버그 수정
Jan 10, 2020
62928e6
주문 승인 기능 개발
Jan 10, 2020
b8e0e7d
리뷰 반영
Jan 12, 2020
317ca34
라이더 정보 서비스 개발
Jan 12, 2020
c359d94
Merge pull request #65 from f-lab-edu/order_coupon
yyy9942 Jan 14, 2020
5c6b1e8
Merge pull request #64 from f-lab-edu/coupon_test
yyy9942 Jan 14, 2020
0ef437a
리뷰 반영
Jan 14, 2020
06a9543
Merge pull request #68 from f-lab-edu/rider_info_service
yyy9942 Jan 16, 2020
c4d70b3
Merge pull request #71 from f-lab-edu/order_coupon
yyy9942 Jan 16, 2020
6de3866
리뷰 적용
yyy9942 Jan 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>

<!-- FCM -->
<dependency>
<groupId>com.google.firebase</groupId>
Expand Down
106 changes: 91 additions & 15 deletions src/main/java/com/delfood/aop/AuthCheckAspect.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.delfood.aop;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Objects;
import javax.servlet.http.HttpSession;
import org.apache.commons.codec.binary.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.reflect.MethodSignature;
import org.codehaus.commons.compiler.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
Expand All @@ -27,9 +34,8 @@ public class AuthCheckAspect {
* 로그인되어있지 않을 시 해당 메서드 로직을 중지시킨 후 리턴한다.
* @OwnerLoginCheck 해당 어노테이션이 적용된 메서드를 검사한다.
* @author jun
* @param pjp
* @return 로그인시 SUCCESS, 비로그인시 NO_LOGIN
* @throws Throwable
* @param jp 조인포인트
* @throws Throwable 발생 가능한 예외
*/
@Before("@annotation(com.delfood.aop.OwnerLoginCheck)")
public void ownerLoginCheck(JoinPoint jp) throws Throwable {
Expand All @@ -49,25 +55,46 @@ public void ownerLoginCheck(JoinPoint jp) throws Throwable {
* 세션에서 사장님 로그인을 체크 한다.
* 그 후 입력받은 파라미터 값 중 매장 id를 검색하여 해당 매장이 접속한 사장님의 것인지 검사한다.
* @author jun
* @param pjp
* @return 비로그인시 NO_LOGIN, 해당 매장의 사장이 아닐 시 UNAUTHORIZED, 권한이 있을 시 SUCCESS
* @throws Throwable
* @param jp 조인포인트
* @throws Throwable 발새 가능한 예외
*/
@Before("@annotation(com.delfood.aop.OwnerShopCheck)")
public void ownerShopCheck(JoinPoint jp) throws Throwable {
@Before("@annotation(com.delfood.aop.OwnerShopCheck) && @annotation(ownerShopCheck)")
public void ownerShopCheck(JoinPoint jp, OwnerShopCheck ownerShopCheck) throws Throwable {
log.debug("AOP - Owner Shop Check Started");


HttpSession session = ((ServletRequestAttributes)(RequestContextHolder.currentRequestAttributes())).getRequest().getSession();
HttpSession session =
((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest()
.getSession();
String ownerId = SessionUtil.getLoginOwnerId(session);
if(ownerId == null) {

if (ownerId == null) {
log.debug("AOP - Owner Shop Check Result - NO_LOGIN");
throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "NO_LOGIN") {};
}

Object[] args = jp.getArgs();
Long shopId = (Long) args[0];

// 메소드 파라미터 추출
MethodSignature signature = (MethodSignature) jp.getSignature();
Method method = signature.getMethod();
Parameter[] parameters = method.getParameters();

Long shopId = null;

// 파라미터의 이름과 어노테이션의 value를 비교하여 검사
for (int i = 0; i < parameters.length; i++) {
String parameterName = parameters[i].getName();
if (StringUtils.equals(ownerShopCheck.value(), parameterName)) {
shopId = (Long) args[i];
}
}

// 어노테이션 value로 설정된 값과 같은 변수 이름이 없을 경우 예외처리
if (Objects.isNull(shopId)) {
throw new IllegalArgumentException("OwnerShopCheck 어노테이션 설정이 잘못되었습니다. value와 변수 명을 일치시켜주세요.");
}


if (!shopService.isShopOwner(shopId, ownerId)) {
log.debug("AOP - Owner Shop Check Result - UNAUTHORIZED");
Expand All @@ -78,9 +105,8 @@ public void ownerShopCheck(JoinPoint jp) throws Throwable {
/**
* 고객의 로그인을 체크한다.
* @author jun
* @param pjp
* @return
* @throws Throwable
* @param jp 조인포인튼
* @throws Throwable 발생 가능한 예외
*/
@Before("@annotation(com.delfood.aop.MemberLoginCheck)")
public void memberLoginCheck(JoinPoint jp) throws Throwable {
Expand All @@ -93,4 +119,54 @@ public void memberLoginCheck(JoinPoint jp) throws Throwable {
throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "NO_LOGIN") {};
}
}

/**
* 라이더 로그인을 체크한다.
* @author jun
* @param jp 조인포인트
* @throws Throwable 발생 가능한 예외 설정
*/
@Before("@annotation(com.delfood.aop.RiderLoginCheck)")
public void riderLoginCheck(JoinPoint jp) throws Throwable {
log.debug("AOP - Rider Login Check Started");

HttpSession session =
((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest()
.getSession();
String riderId = SessionUtil.getLoginRiderId(session);

if (Objects.isNull(riderId)) {
throw new HttpStatusCodeException(HttpStatus.UNAUTHORIZED, "RIDER_NO_LOGIN") {};
}
}

/**
* 공통 로그인 체크 AOP.
* 고객, 사장님, 라이더의 로그인 체크 기능을 하나로 모아두었다.
* @param jp 조인포인트
* @throws Throwable 발생 가능한 예외
*/
@Before("@annotation(com.delfood.aop.LoginCheck) && @ annotation(loginCheck)")
public void loginCheck(JoinPoint jp, LoginCheck loginCheck) throws Throwable {
log.debug("AOP - Login Check Started");

HttpSession session =
((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest()
.getSession();

if (LoginCheck.UserType.MEMBER.equals(loginCheck.type())) {
memberLoginCheck(jp);
}

if (LoginCheck.UserType.OWNER.equals(loginCheck.type())) {
ownerLoginCheck(jp);
}

if (LoginCheck.UserType.RIDER.equals(loginCheck.type())) {
riderLoginCheck(jp);
}


}

}
28 changes: 28 additions & 0 deletions src/main/java/com/delfood/aop/LoginCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.delfood.aop;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* 로그인의 상태를 확인한다.
* 회원, 사장님, 라이더의 로그인 상태를 확인하여 로그인 되지 않았다면 예외를 발생시킨다.
* @author jun
*
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface LoginCheck {

/**
* 로그인을 체크하고 싶은 유저의 로그인 타입.
* 회원(MEMBER), 사장님(OWNER), 라이더(RIDER)중 선택할 수 있다.
* @return
*/
UserType type();

public static enum UserType {
MEMBER, OWNER, RIDER
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/delfood/aop/OwnerShopCheck.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.delfood.aop;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* <b>매장 id가 첫 번째 파라미터로 와야한다.</b>
* <b>매장 id를 파라미터로 주어야 한다.</b>
* 접속한 사장님이 해당 매장의 주인인지 확인한다.
* @author yyy99
*
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface OwnerShopCheck {

/**
* 해당 변수의 이름.
* @return
*/
String value();
}
9 changes: 9 additions & 0 deletions src/main/java/com/delfood/aop/RiderLoginCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.delfood.aop;

import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
public @interface RiderLoginCheck {

}
12 changes: 7 additions & 5 deletions src/main/java/com/delfood/controller/CartControllelr.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.delfood.controller;

import com.delfood.aop.LoginCheck;
import com.delfood.aop.LoginCheck.UserType;
import com.delfood.aop.MemberLoginCheck;
import com.delfood.dto.ItemDTO;
import com.delfood.service.CartService;
Expand All @@ -23,31 +25,31 @@ public class CartControllelr {
private CartService cartService;

@PostMapping("/members/cart/menus")
@MemberLoginCheck
@LoginCheck(type = UserType.MEMBER)
public void addMenu(@RequestBody ItemDTO item, HttpSession session) {
cartService.addOrdersItem(item, SessionUtil.getLoginMemberId(session));
}

@GetMapping("/members/cart/menus")
@MemberLoginCheck
@LoginCheck(type = UserType.MEMBER)
public List<ItemDTO> getCart(HttpSession session) {
return cartService.getItems(SessionUtil.getLoginMemberId(session));
}

@DeleteMapping("/members/cart/menus")
@MemberLoginCheck
@LoginCheck(type = UserType.MEMBER)
public void clearCart(HttpSession session) {
cartService.claer(SessionUtil.getLoginMemberId(session));
}

@DeleteMapping("/members/cart/menus/{index}")
@MemberLoginCheck
@LoginCheck(type = UserType.MEMBER)
public void deleteCartMenu(HttpSession session, @PathVariable long index) {
cartService.deleteCartMenu(SessionUtil.getLoginMemberId(session), index);
}

@GetMapping("/members/cart/price")
@MemberLoginCheck
@LoginCheck(type = UserType.MEMBER)
public CartPriceResponse cartPrice(HttpSession session) {
String memberId = SessionUtil.getLoginMemberId(session);
return new CartPriceResponse(cartService.getItems(memberId), cartService.allPrice(memberId));
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/delfood/controller/CouponController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.delfood.controller;

import com.delfood.dto.CouponDTO;
import com.delfood.service.CouponService;
import lombok.extern.log4j.Log4j2;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Log4j2
@RestController
@RequestMapping("/coupons/")
public class CouponController {

@Autowired
CouponService couponService;

/**
* 쿠폰을 추가한다.
* @param couponInfo 쿠폰 정보
* @return
*
* @author jinyoung
*/
@PostMapping
public void addCoupon(@RequestBody CouponDTO couponInfo) {

if (CouponDTO.hasNullData(couponInfo)) {
log.error("insufficient coupon information! {}", couponInfo.toString());
throw new NullPointerException("insufficient coupon information! " + couponInfo.toString());
}

couponService.addCoupon(couponInfo);
}

/**
* 쿠폰 이름과 만료일을 수정한다.
*
* @param id 쿠폰 아이디
* @param name 수정할 쿠폰 이름
* @param endAt 수정할 만료일
*
* @author jinyoung
*/
@PatchMapping
public void updateCouponNameAndEndAt(Long id, String name, LocalDateTime endAt) {
couponService.updateCouponNameAndEndAt(id, name, endAt);
}

/**
* 쿠폰을 삭제한다.
*
* @param id 쿠폰 아이디
*/
public void deleteCoupon(Long id) {
couponService.deleteCoupon(id);
}


/**
* 만료일이 지나지 않은 쿠폰들을 조회한다.
* @return 쿠폰리스트
*
* @author jinyoung
*/
@GetMapping
public List<CouponDTO> getAvailableCoupons() {
return couponService.getAvaliableCoupons();
}

}
Loading