Skip to content

Commit

Permalink
Merge branch 'develop' into stock_02-1
Browse files Browse the repository at this point in the history
  • Loading branch information
in27sung authored Dec 17, 2024
2 parents b9561e6 + 76cda97 commit 615b40f
Show file tree
Hide file tree
Showing 49 changed files with 3,880 additions and 707 deletions.
2 changes: 1 addition & 1 deletion stockMate/src/main/java/com/stockm8/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class WebConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
// Intercepter 적용
registry.addInterceptor(authorizationInterceptor)
.addPathPatterns("/dashboard", "/business", "/category/**", "/product/**", "/warehouse/**", "/stock/**", "/order/**" ) // 인터셉터를 적용할 경로
.addPathPatterns("/dashboard", "/business", "/category/**", "/product/**", "/warehouse/**", "/stock/**", "/order/**","/admin/**" ) // 인터셉터를 적용할 경로
.excludePathPatterns( // 인터셉터를 제외할 경로
"/", // HomeController 경로
"/favicon.ico", // 브라우저 기본 요청
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.stockm8.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stockm8.domain.vo.Criteria;
import com.stockm8.domain.vo.OrderItemVO;
import com.stockm8.domain.vo.OrderVO;
import com.stockm8.domain.vo.PageVO;
import com.stockm8.domain.vo.OrderVO.OrderType;
import com.stockm8.domain.vo.StockVO;
import com.stockm8.domain.vo.UserVO;
import com.stockm8.service.OrderService;
import com.stockm8.service.UserService;

@Controller
@RequestMapping(value = "/admin/*")
public class AdminController {

// 현재 로그인한 사용자 정보 가져오기(인터셉터에서 정의됨)
private UserVO getCurrentUser(HttpServletRequest request) {
return (UserVO) request.getAttribute("currentUser");
}

private static final Logger logger = LoggerFactory.getLogger(AdminController.class);

@Inject
private OrderService orderService;
@Inject
private UserService userService;

/**
* 어드민 메인 페이지 표시(GET)
* http://localhost:8088/admin/adminMain
*
*/
@RequestMapping(value = "/adminMain", method = RequestMethod.GET)
public String adminMainGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("adminMainGET() 호출");

UserVO currentUser = getCurrentUser(request);
int businessId = currentUser.getBusinessId();

return "admin/adminMain";
}
/**
* 어드민 회원목록표시(GET)
* http://localhost:8088/admin/adminList
*
*/
@RequestMapping(value = "/adminList", method = RequestMethod.GET)
public String adminListGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("adminListGET() 호출");

UserVO currentUser = getCurrentUser(request);
int businessId = currentUser.getBusinessId();

return "admin/adminList";
}



} //AdminController
14 changes: 14 additions & 0 deletions stockMate/src/main/java/com/stockm8/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ public String howtouseGET(Model model, HttpSession session) throws Exception {
return "howtouse";
}

// 창고위치 - /location (GET)
@RequestMapping(value = "/location", method = RequestMethod.GET)
public String locationGET(Model model, HttpSession session) throws Exception {
Long userId = (Long) session.getAttribute("userId");
// if (id == null) {
// // 세션에 id가 없으면 에러 처리
// return "redirect:/user/main";
// }
// UserVO resultVO = userService.getUser(userId);
// model.addAttribute("resultVO", resultVO);
return "location";
}


// 상담하기 - /user/consultation (GET)
@RequestMapping(value = "/consultation", method = RequestMethod.GET)
public String consultationGET(Model model, HttpSession session) throws Exception {
Expand Down
90 changes: 53 additions & 37 deletions stockMate/src/main/java/com/stockm8/controller/OrderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stockm8.domain.vo.Criteria;
import com.stockm8.domain.vo.OrderItemVO;
import com.stockm8.domain.vo.OrderVO;
import com.stockm8.domain.vo.PageVO;
import com.stockm8.domain.vo.OrderVO.OrderType;
import com.stockm8.domain.vo.StockVO;
import com.stockm8.domain.vo.UserVO;
Expand All @@ -30,6 +33,11 @@
@Controller
@RequestMapping(value = "/order/*")
public class OrderController {

// 현재 로그인한 사용자 정보 가져오기(인터셉터에서 정의됨)
private UserVO getCurrentUser(HttpServletRequest request) {
return (UserVO) request.getAttribute("currentUser");
}

private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

Expand All @@ -49,29 +57,8 @@ public class OrderController {
public String orderRegisterGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("orderRegisterGET() 호출");


// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = userService.getUserById(userId);
int businessId = user.getBusinessId();

// HttpSession session = request.getSession(false);
// if (session != null) {
// Long userId = (Long) session.getAttribute("userId");
// if (userId != null) {
// UserVO user = userService.getUserById(userId);
// if (user != null) {
// model.addAttribute("businessId", user.getBusinessId());
// // 추가적인 권한 체크나 비즈니스 로직
// return "order/register";
// }
// }
// }
// // 인증 실패 처리 => 음 메세지 ??? 어떻게 ??
// return "user/main";
UserVO currentUser = getCurrentUser(request);
int businessId = currentUser.getBusinessId();

return "order/register";
}
Expand All @@ -81,14 +68,13 @@ public String orderRegisterGET(Model model, HttpServletRequest request, HttpServ
* http://localhost:8088/order/register
* @param order 클라이언트에서 전송된 주문 정보
* @return 처리 결과를 담은 Map 객체
* @throws Exception 주문 처리 중 발생하는 예외
*
*/
@RequestMapping(value = "/register",
method = RequestMethod.POST,
produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order) throws Exception {
public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order, HttpServletRequest request) throws Exception {
logger.info("orderRegisterPOST() 호출");
logger.info("주문 정보: " + order);

Expand All @@ -97,7 +83,6 @@ public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order) throws
throw new IllegalArgumentException("주문 유형이 누락되었습니다.");
}


// 주문에 orderItems가 있는지 확인(유효성 검사)
if (order.getOrderItems() == null || order.getOrderItems().isEmpty()) {
throw new IllegalArgumentException("주문 항목이 누락되었습니다.");
Expand Down Expand Up @@ -146,13 +131,8 @@ public Map<String, String> orderRegisterPOST(@RequestBody OrderVO order) throws
public List<StockVO> findAvailableStocks(HttpServletRequest request) throws Exception {
logger.info("findAvailableStocks() 호출");

// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;

// userId로 사용자 정보 조회
UserVO user = userService.getUserById(userId);
int businessId = user.getBusinessId();
UserVO currentUser = getCurrentUser(request);
int businessId = currentUser.getBusinessId();

return orderService.findAvailableStocks(businessId);
}
Expand All @@ -175,19 +155,55 @@ public String generateOrderNumber() throws Exception {
* http://localhost:8088/order/orderList
*/
@RequestMapping(value = "/orderList" , method = RequestMethod.GET)
public String orderListGET(Model model) {
public String orderListGET(Model model, Criteria cri, HttpServletRequest request) throws Exception {
logger.info("orderListGET() 호출");

// main에서 넘어올떄 정달정보 ?? 로그인???세션 ??
// Criteria가 null인 경우 새로 생성
if (cri == null) {
cri = new Criteria();
}

UserVO currentUser = getCurrentUser(request);
int businessId = currentUser.getBusinessId();

//서비스 -> DAO(주문 목록)
List<OrderVO> orderList = orderService.getOrderList();
List<OrderVO> orderList = orderService.getOrderList(cri, businessId);

//뷰 페이지 정보 전달(model)
// 전체 데이터 개수 조회
int totalCount = orderService.getTotalOrderCount(businessId);

// 페이징 정보 계산
PageVO pageVO = new PageVO();
pageVO.setCri(cri);
pageVO.setTotalCount(totalCount);

//뷰 페이지 정보 전달(model)
model.addAttribute("orderList",orderList);
model.addAttribute("pageVO", pageVO);

return "/order/orderList";
}

/**
* 주문 상세 정보 조회
* http://localhost:8088/order/detail?orderId=1
*/
@RequestMapping(value = "/detail", method = RequestMethod.GET)
public String orderDetailGET(@RequestParam("orderId") int orderId, Model model, HttpServletRequest request) throws Exception {
logger.info("orderDetailGET() 호출 - orderId: " + orderId);

UserVO currentUser = getCurrentUser(request);

// 주문 기본 정보 조회
OrderVO order = orderService.getOrderById(orderId);
// 주문 상세 항목 목록 조회
List<OrderItemVO> orderItems = orderService.getOrderItemsByOrderId(orderId);

// 모델에 데이터 추가
model.addAttribute("order", order);
model.addAttribute("orderItems", orderItems);

return "order/orderDetail";
}

} //OrderController
Loading

0 comments on commit 615b40f

Please sign in to comment.