Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/in27sung/stock-mate.git
Browse files Browse the repository at this point in the history
into main_16

Conflicts:
	stockMate/src/main/java/com/stockm8/controller/HomeController.java
	stockMate/src/main/webapp/WEB-INF/views/dashboard.jsp
	stockMate/src/main/webapp/WEB-INF/views/main.jsp
  • Loading branch information
BowWowBow committed Dec 19, 2024
2 parents 7a1b99b + ee2b5ef commit 1c3074a
Show file tree
Hide file tree
Showing 44 changed files with 1,685 additions and 1,402 deletions.
41 changes: 21 additions & 20 deletions stockMate/src/main/java/com/stockm8/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stockm8.config;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -70,30 +71,30 @@ public class WebConfig implements WebMvcConfigurer {
*/
@Override
public void addInterceptors(InterceptorRegistry registry) {

registry.addInterceptor(flashMessageInterceptor).addPathPatterns("/**");

List<String> excludedPaths = Arrays.asList(
"/", "/favicon.ico", "/resources/**", "/user/**", "/static/**",
"/api/**", "/dashboard", "/business", "/category/**", "/product/**",
"/warehouse/**", "/stock/**", "/order/**"
);

registry.addInterceptor(adminInterceptor)
.addPathPatterns("/admin/**") // /admin/** 경로에만 적용
.excludePathPatterns( // 인터셉터를 제외할 경로
"/", // HomeController 경로
"/favicon.ico", // 브라우저 기본 요청
"/resources/**", // 정적 리소스
"/user/**", // 로그인 및 회원가입 관련 요청
"/static/**",
"/api/**" // API 요청에 대해서는 세션 체크를 제외
);
.excludePathPatterns(excludedPaths.toArray(new String[0]));

// Intercepter 적용
registry.addInterceptor(authorizationInterceptor)
.addPathPatterns("/dashboard", "/business", "/category/**", "/product/**", "/warehouse/**", "/stock/**", "/order/**","/admin/**" ) // 인터셉터를 적용할 경로
.excludePathPatterns( // 인터셉터를 제외할 경로
"/", // HomeController 경로
"/favicon.ico", // 브라우저 기본 요청
"/resources/**", // 정적 리소스
"/user/**", // 로그인 및 회원가입 관련 요청
"/static/**",
"/api/**" // API 요청에 대해서는 세션 체크를 제외
);
// Flash 메시지 처리 인터셉터
registry.addInterceptor(new FlashMessageInterceptor());

.addPathPatterns("/dashboard", "/business", "/category/**", "/product/**", "/warehouse/**", "/stock/**", "/order/**") // 인터셉터를 적용할 경로
.excludePathPatterns( // 제외할 경로들
"/", // 홈 경로 제외
"/favicon.ico", // 브라우저 기본 요청 제외
"/resources/**", // 정적 리소스 제외
"/user/**", // 로그인, 회원가입 관련 제외
"/static/**", // 정적 리소스 제외
"/api/**");

// LocaleChangeInterceptor를 추가하면, 요청 파라미터 (예: ?lang=ko)로 Locale을 변경할 수 있음
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
localeInterceptor.setParamName("lang");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
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.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.stockm8.domain.dto.PendingUserDTO;
import com.stockm8.domain.dto.UpdateUserStatusDTO;
import com.stockm8.domain.enums.UserRole;
import com.stockm8.domain.vo.UserVO;
import com.stockm8.service.OrderService;
Expand All @@ -38,11 +41,12 @@ private UserVO getCurrentUser(HttpServletRequest request) {
private UserService userService;

/**
* 관리자 메인 페이지 표시(GET) http://localhost:8088/admin/main
* 관리자 메인 페이지 표시(GET)
*
* @throws Exception
*
*/
// http://localhost:8088/admin/main
@GetMapping("/main")
public String adminMainGET(@SessionAttribute("userId") Long userId, Model model) throws Exception {
logger.info("adminMainGET() 호출 - 페이지 접근 (userId: {})", userId);
Expand All @@ -57,7 +61,8 @@ public String adminMainGET(@SessionAttribute("userId") Long userId, Model model)
}
return "admin/main"; // 메인 페이지 반환
}


// http://localhost:8088/admin/approve
@GetMapping("/approve")
public String adminApproveGET(@SessionAttribute("userId") Long userId, Model model) throws Exception {
logger.info("adminApproveGET() 호출 - 페이지 접근 (userId: {})", userId);
Expand All @@ -68,13 +73,14 @@ public String adminApproveGET(@SessionAttribute("userId") Long userId, Model mod
// JSP로 전달
model.addAttribute("pendingUsers", pendingUsers);

return "admin/main"; // JSP 페이지 반환
return "admin/approve"; // JSP 페이지 반환
}

/**
* 관리자 회원목록표시(GET) http://localhost:8088/admin/userList
* 관리자 회원목록표시(GET)
*
*/
// http://localhost:8088/admin/userList
@RequestMapping(value = "/adminList", method = RequestMethod.GET)
public String adminListGET(Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
logger.info("adminListGET() 호출");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public String locationGET(Model model, HttpSession session) throws Exception {
}


// 상담하기 - /user/consultation (GET)
// 상담하기 - /consultation (GET)
@RequestMapping(value = "/consultation", method = RequestMethod.GET)
public String consultationGET(Model model, HttpSession session) throws Exception {
Long userId = (Long) session.getAttribute("id");
Expand Down Expand Up @@ -237,5 +237,6 @@ public String minimapGET(Model model, HttpSession session) throws Exception {
// model.addAttribute("resultVO", resultVO);
return "/minimap";
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.stockm8.controller;

public class ManagerController {

}
20 changes: 10 additions & 10 deletions stockMate/src/main/java/com/stockm8/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ public String userLoginPOST(UserVO user, RedirectAttributes rttr, HttpSession se
if (resultVO != null) {
logger.info("로그인 성공, 사용자 ID: {}", resultVO.getUserId());

// 세션에 사용자 ID 저장
session.setAttribute("userId", resultVO.getUserId());

// 원래 요청 URL로 리다이렉트
// String redirectUrl = (String) session.getAttribute("redirectAfterLogin");
//
// if (redirectUrl != null) {
// session.removeAttribute("redirectAfterLogin"); // 세션에서 URL 삭제
// return "redirect:" + redirectUrl;
// }
// 세션에 사용자 ID 저장
session.setAttribute("userId", resultVO.getUserId());

// 원래 요청 URL로 리다이렉트
String redirectUrl = (String) session.getAttribute("redirectAfterLogin");

if (redirectUrl != null) {
session.removeAttribute("redirectAfterLogin"); // 세션에서 URL 삭제
return "redirect:" + redirectUrl;
}
return "redirect:/dashboard";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.stockm8.controller.api;

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

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.stockm8.domain.dto.UpdateUserStatusDTO;
import com.stockm8.service.UserService;

@RestController
@RequestMapping("/api/admin")
public class AdminApiController {

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

@Inject
private UserService userService;

@PostMapping("/approve")
public ResponseEntity<Map<String, Object>> adminApprove(
@RequestBody UpdateUserStatusDTO updateUserStatusDTO,
@SessionAttribute(value = "userId", required = false) Long sessionUserId) {

Map<String, Object> response = new HashMap<>();

// 세션 값 확인
if (sessionUserId == null) {
logger.error("Session userId is missing");
response.put("success", false);
response.put("message", "세션 정보가 없습니다. 다시 로그인해주세요.");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(response);
}

// 세션에서 userId를 DTO에 설정
updateUserStatusDTO.setUserId(sessionUserId);

// 입력값 검증
if (updateUserStatusDTO.getApprovedUserId() == null || updateUserStatusDTO.getUserStatus() == null) {
logger.error("Invalid input: approvedUserId or userStatus is null - DTO: {}", updateUserStatusDTO);
response.put("success", false);
response.put("message", "유효하지 않은 데이터입니다.");
return ResponseEntity.badRequest().body(response);
}

// 디버깅용 로그
// logger.info("adminApprove() 호출 - approvedUserId: {}, userStatus: {}, userId: {}",
// updateUserStatusDTO.getApprovedUserId(),
// updateUserStatusDTO.getUserStatus(),
// updateUserStatusDTO.getUserId());

try {
// 사용자 상태 변경
userService.updateUserStatus(updateUserStatusDTO);

// 성공 응답
response.put("success", true);
response.put("message", "상태가 성공적으로 업데이트되었습니다.");
return ResponseEntity.ok(response);
} catch (Exception e) {
// 예외 처리
logger.error("사용자 상태 업데이트 실패", e);
response.put("success", false);
response.put("message", "상태 업데이트 실패. 관리자에게 문의해주세요.");
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.stockm8.controller.api;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
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;
import org.springframework.web.bind.annotation.SessionAttribute;

import com.stockm8.domain.dto.UpdateUserStatusDTO;
import com.stockm8.service.UserService;

@RestController
@RequestMapping("/api/manager")
public class ManagerApiController {

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

@Autowired
private UserService userService;

@PostMapping("/approve")
public ResponseEntity<Map<String, Object>> approveStaff(
@RequestBody UpdateUserStatusDTO updateUserStatusDTO,
@SessionAttribute("userId") Long sessionUserId) {

Map<String, Object> response = new HashMap<>();

// 세션에서 Manager ID를 DTO에 설정
updateUserStatusDTO.setUserId(sessionUserId);

// 입력값 검증
if (updateUserStatusDTO.getApprovedUserId() == null || updateUserStatusDTO.getUserStatus() == null) {
response.put("success", false);
response.put("message", "유효하지 않은 데이터입니다.");
return ResponseEntity.badRequest().body(response);
}

// 직원 승인 처리
userService.updateUserStatus(updateUserStatusDTO);;

response.put("success", true);
response.put("message", "직원이 성공적으로 승인되었습니다.");
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

import java.sql.Timestamp;

import com.stockm8.domain.enums.UserRole;
import com.stockm8.domain.enums.UserStatus;

import lombok.Data;

@Data
public class PendingUserDTO {

// 사용자 정보
private Long userId;
private Long approvedUserId;
private String email;
private String userName;
private String userRole;
private UserRole userRole;
private String telNumber;
private Timestamp createdAt;
private UserStatus userStatus;

// 사업자 정보
private Integer businessId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public class StockDTO {
private String warehouseName; // 창고명
private int totalQuantity; // 총 재고 수량
private int availableStock; // 사용 가능한 재고
private Timestamp updatedAt; // 최근 수정 시간
private Timestamp updatedAt; // 최근 수정 시간
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.stockm8.domain.dto;

import com.stockm8.domain.enums.UserStatus;

import lombok.Data;

@Data
public class UpdateUserStatusDTO {

private Long approvedUserId; // 승인받는 사용자 ID

private UserStatus userStatus; // Enum으로 상태값 처리

private Long userId; // 승인 작업을 수행하는 관리자 ID
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class WarehouseDetailDTO {
private String warehouseLocation; // 창고 위치
private int businessId; // 비즈니스 ID
private String businessName; // 회사명
private Long managerId; // 관리자 ID
private Long managerId; // 관리자 ID
private String managerName; // 관리자명
private Timestamp createdAt; // 창고 등록 날짜
private Timestamp updatedAt; // 창고 수정 날짜
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.FlashMap;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.stockm8.domain.enums.UserRole;
import com.stockm8.domain.vo.UserVO;
Expand Down Expand Up @@ -65,10 +67,23 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
/**
* 에러 메시지와 함께 리다이렉트 처리
*/
private boolean sendErrorMessage(HttpServletRequest request, HttpServletResponse response, String message, String redirectUrl) throws IOException {
request.getSession().setAttribute("errorMessage", message);
response.sendRedirect(request.getContextPath() + redirectUrl);
return false; // 요청 중단
private boolean sendErrorMessage(HttpServletRequest request, HttpServletResponse response, String message, String redirectUrl)
throws Exception {

// FlashMap 객체 생성 및 에러 메시지 저장
FlashMap flashMap = new FlashMap();
flashMap.put("errorMessage", message);

// FlashMap 저장소에 FlashMap 추가
RequestContextUtils.getFlashMapManager(request).saveOutputFlashMap(flashMap, request, response);

// 로그 출력
logger.info("FlashMap에 저장된 에러 메시지: {}", message);
logger.info("리다이렉트 대상 URL: {}", redirectUrl);

// 리다이렉트 수행
response.sendRedirect(redirectUrl);
return false; // handlerInterceptor 처리 중단
}

/**
Expand Down
Loading

0 comments on commit 1c3074a

Please sign in to comment.