Skip to content

Commit

Permalink
Merge pull request #175 from nhnacademy-be4-My-Books/feature/order
Browse files Browse the repository at this point in the history
Feature/order 레스트독 수정
  • Loading branch information
minsu11 authored Apr 4, 2024
2 parents 45d00b3 + b5831dc commit 4505ffa
Show file tree
Hide file tree
Showing 14 changed files with 33,115 additions and 11,085 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package store.mybooks.front.home;
package store.mybooks.front.home.controller;

import java.util.List;
import lombok.RequiredArgsConstructor;
Expand All @@ -8,13 +8,11 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import store.mybooks.front.admin.book.model.response.BookLikeResponse;
import store.mybooks.front.admin.book.model.response.BookPopularityResponse;
import store.mybooks.front.admin.book.model.response.BookPublicationDateResponse;
import store.mybooks.front.admin.book.model.response.BookRatingResponse;
import store.mybooks.front.admin.book.model.response.BookReviewResponse;
import store.mybooks.front.admin.book.service.BookAdminService;
import store.mybooks.front.book.service.BookService;

/**
Expand Down Expand Up @@ -56,4 +54,6 @@ public String home(@PageableDefault(size = 8) Pageable pageable, Model model) {
public String apiDocs() {
return "api-docs";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package store.mybooks.front.home.controller;

import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import store.mybooks.front.home.dto.response.UserCheckResponse;
import store.mybooks.front.utils.CookieUtils;

/**
* packageName : store.mybooks.front.order.controller<br>
* fileName : HomeRestController<br>
* author : minsu11<br>
* date : 3/27/24<br>
* description :
* ===========================================================<br>
* DATE AUTHOR NOTE<br>
* -----------------------------------------------------------<br>
* 3/27/24 minsu11 최초 생성<br>
*/
@RestController
@RequiredArgsConstructor
public class HomeRestController {

/**
* methodName : checkUser<br>
* author : minsu11<br>
* description : 비회원의 주문내역을 화면에 보여주기 전에 유저인지 아닌지 확이.
*
* @param request the request
* @return the response entity
*/
@GetMapping("/home/user/identity")
public ResponseEntity<UserCheckResponse> checkUser(HttpServletRequest request) {
UserCheckResponse response = new UserCheckResponse(false);
if (Objects.nonNull(CookieUtils.getIdentityCookieValue(request))) {
response.changeCheckResult(true);
}
return ResponseEntity.status(HttpStatus.OK)
.body(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package store.mybooks.front.home.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
* packageName : store.mybooks.front.home.dto.response<br>
* fileName : UserCheckResponse<br>
* author : minsu11<br>
* date : 3/27/24<br>
* description :
* ===========================================================<br>
* DATE AUTHOR NOTE<br>
* -----------------------------------------------------------<br>
* 3/27/24 minsu11 최초 생성<br>
*/
@Getter
@AllArgsConstructor
public class UserCheckResponse {
private Boolean checkResult;

public void changeCheckResult(Boolean checkResult) {
this.checkResult = checkResult;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import store.mybooks.front.admin.book.model.response.BookGetResponseForOrder;
import store.mybooks.front.admin.book.model.response.BookStockResponse;
import store.mybooks.front.admin.delivery_rule.dto.DeliveryRuleResponse;
Expand Down Expand Up @@ -204,16 +209,22 @@ public String viewOrderPage(ModelMap modelMap,
modelMap.put("point", pointResponse.getRemainingPoint());
bookFromCart = cartUserService.getBookFromCart();
modelMap.put("userCheck", true);
if (bookFromCart.isEmpty()) {
modelMap.put("errorMessage", "장바구니가 비었습니다.");
return "redirect:/cart";
}
} else {

bookFromCart = cartNonUserService.getBookFromCart(cartCookie);
if (bookFromCart.isEmpty()) {
modelMap.put("errorMessage", "장바구니가 비었습니다.");
return "redirect:/cart";
}
orderInfoCheckService.validationCheckNonUserOrder(bookFromCart);
modelMap.put("userCheck", false);
}
if (bookFromCart.isEmpty()) {
return "/redirect:/cart";
}
DeliveryRuleResponse deliveryRule = deliveryRuleService.getDeliveryRuleResponseByName("배송 비");

DeliveryRuleResponse deliveryRule = deliveryRuleService
.getDeliveryRuleResponseByName(DeliveryRuleNameEnum.DELIVERY.getValue());
modelMap.put("bookLists", bookFromCart);
modelMap.put("totalCost", orderService.calculateTotalCost(bookFromCart, deliveryRule));
modelMap.put("localDate", LocalDate.now());
Expand Down Expand Up @@ -332,4 +343,8 @@ public String deleteAddress(@RequestParam(name = "addressId") Long addressId) {
return "redirect:/address";
}

@GetMapping("order/non-user")
public String viewNonUserOrder() {
return "non-user-order";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ public void checkAmount(int amount, int equalsAmount) {
}

public void validationCheckNonUserOrder(List<CartDetail> cartDetailList) {

for (CartDetail cartDetail : cartDetailList) {
BookStockResponse stock = bookAdaptor.getBookStockResponse(cartDetail.getBookId());
if (cartDetail.getStock() > stock.getStock()) {
Expand Down
Loading

0 comments on commit 4505ffa

Please sign in to comment.