diff --git a/src/main/java/com/hanaro/starbucks/config/JwtUtil.java b/src/main/java/com/hanaro/starbucks/config/JwtUtil.java index 9c7a63d..fd43e51 100644 --- a/src/main/java/com/hanaro/starbucks/config/JwtUtil.java +++ b/src/main/java/com/hanaro/starbucks/config/JwtUtil.java @@ -56,7 +56,7 @@ public Authentication getAuthentication(String token) { // http 요청에서 "TOKEN" 헤더 값을 읽어오는 메소드 public String resolveToken(HttpServletRequest request) { - return request.getHeader("TOKEN"); + return request.getHeader("Authorization"); } public boolean validateToken(String token){ diff --git a/src/main/java/com/hanaro/starbucks/controller/MemberController.java b/src/main/java/com/hanaro/starbucks/controller/MemberController.java index 184bce0..3c84c35 100644 --- a/src/main/java/com/hanaro/starbucks/controller/MemberController.java +++ b/src/main/java/com/hanaro/starbucks/controller/MemberController.java @@ -71,6 +71,7 @@ public void deleteUser(@PathVariable int userIdx){ @GetMapping("/points") public PointResDto getUserPoint(@RequestHeader MultiValueMap headers){ - return memberService.getUserPoint(headers.getFirst("token")); + String originalToken = headers.getFirst("authorization"); + return memberService.getUserPoint(originalToken.substring(7, originalToken.length())); } } diff --git a/src/main/java/com/hanaro/starbucks/controller/OrderController.java b/src/main/java/com/hanaro/starbucks/controller/OrderController.java index 498cdad..7aa7eb9 100644 --- a/src/main/java/com/hanaro/starbucks/controller/OrderController.java +++ b/src/main/java/com/hanaro/starbucks/controller/OrderController.java @@ -42,8 +42,10 @@ public void deleteOrder(@PathVariable int orderIdx) { @PostMapping("") public void createOrder(@RequestHeader MultiValueMap headers, @RequestBody List dtos) { - if(headers.containsKey("token") ){ - orderService.createOrder(headers.getFirst("token"), dtos); + String originalToken = headers.getFirst("authorization"); + if(headers.containsKey("authorization") ){ + String token = originalToken.substring(7, originalToken.length()); + orderService.createOrder(token, dtos); }else{ orderService.createOrder("null", dtos); } diff --git a/src/main/java/com/hanaro/starbucks/entity/Member.java b/src/main/java/com/hanaro/starbucks/entity/Member.java index d1f2104..b2cb101 100644 --- a/src/main/java/com/hanaro/starbucks/entity/Member.java +++ b/src/main/java/com/hanaro/starbucks/entity/Member.java @@ -64,6 +64,10 @@ public void update(MemberUpdateReqDto dto) { this.userJoinDate = LocalDate.now(); } + public void update(int userPoint) { + this.userPoint = userPoint; + } + @Override public Collection getAuthorities() { //계정의 권한 목록을 리턴함. diff --git a/src/main/java/com/hanaro/starbucks/service/MemberService.java b/src/main/java/com/hanaro/starbucks/service/MemberService.java index 1d0e34f..743cc9f 100644 --- a/src/main/java/com/hanaro/starbucks/service/MemberService.java +++ b/src/main/java/com/hanaro/starbucks/service/MemberService.java @@ -90,6 +90,16 @@ public void updateUser(int userIdx, MemberUpdateReqDto user){ memberRepository.save(member); } + public void updateUserPoint(int userIdx, int userPoint) { + Optional optional = memberRepository.findById(userIdx); + if(optional.isEmpty()){ + throw new IllegalArgumentException("존재하지 않는 회원입니다."); + } + Member member = optional.get(); + member.update(member.getUserPoint() + userPoint); + memberRepository.save(member); + } + public void deleteUser(int userIdx){ memberRepository.deleteById(userIdx); } diff --git a/src/main/java/com/hanaro/starbucks/service/OrderService.java b/src/main/java/com/hanaro/starbucks/service/OrderService.java index 4785763..318fc0b 100644 --- a/src/main/java/com/hanaro/starbucks/service/OrderService.java +++ b/src/main/java/com/hanaro/starbucks/service/OrderService.java @@ -90,8 +90,9 @@ private Orders findOrderById(int orderIdx) { public void createOrder(String token, List dtos){ Member member; Orders order; + int userIdx = -1; + if(token.equals("null")){ - System.out.println("~~~~~~~~~~~~~~~~~~``"); order = Orders.builder() .orderId(UUID.randomUUID().toString()) .orderStatus("주문완료") @@ -100,14 +101,16 @@ public void createOrder(String token, List dtos){ String userId = jwtUtil.getAuthentication(token).getName(); System.out.println("User ID: " + userId); member = memberService.getUserById(userId); + userIdx = member.getUserIdx(); order = Orders.builder() .user(member) .orderId(UUID.randomUUID().toString()) .orderStatus("주문완료") .build(); + } + Orders savedOrder = orderRepository.save(order); - System.out.println("~~~"+order.getOrderIdx()); List orderDetails = dtos.stream() .map(dto -> { @@ -125,12 +128,11 @@ public void createOrder(String token, List dtos){ }) .collect(Collectors.toList()); - System.out.println("~~~~~~~~"+orderDetails.size()); - for(OrderDetail orderDetail : orderDetails){ - System.out.println(orderDetail.getOrders()); - System.out.println(orderDetail.getMenu()); - System.out.println(orderDetail.getMenuTemperature()); - System.out.println(orderDetail.getOrderDetailIdx()); + + if(userIdx != -1) { + int tot = calculateTotalPrice(orderDetails); + int point = (int) Math.floor(tot / 100.0); + memberService.updateUserPoint(userIdx, point); } orderDetailRepository.saveAll(orderDetails); diff --git a/src/main/java/com/hanaro/starbucks/util/Constant.java b/src/main/java/com/hanaro/starbucks/util/Constant.java index 0fd5c2b..9b5819b 100644 --- a/src/main/java/com/hanaro/starbucks/util/Constant.java +++ b/src/main/java/com/hanaro/starbucks/util/Constant.java @@ -1,8 +1,8 @@ package com.hanaro.starbucks.util; public class Constant { - public static final String GRANDE_SIZE="grande"; - public static final String VENTI_SIZE="venti"; + public static final String GRANDE_SIZE="Grande"; + public static final String VENTI_SIZE="Venti"; public static final int GRANDE = 500; public static final int VENTI = 1000;