Skip to content

Commit

Permalink
Merge branch 'develop' into receivingsearch_01
Browse files Browse the repository at this point in the history
  • Loading branch information
shoqying authored Dec 11, 2024
2 parents a36b15a + 6ca03fe commit 8f5d13a
Show file tree
Hide file tree
Showing 27 changed files with 1,116 additions and 552 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public String handleException(
String referer = request.getHeader("Referer"); // 이전 페이지로 이동
return "redirect:" + (referer != null ? referer : "/");
}
}
}
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 @@ -47,7 +47,7 @@ public class WebConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
// Intercepter 적용
registry.addInterceptor(authorizationInterceptor)
.addPathPatterns("/product/**") // 인터셉터를 적용할 경로
.addPathPatterns("/product/**", "/category/**") // 인터셉터를 적용할 경로
.excludePathPatterns( // 인터셉터를 제외할 경로
"/", // HomeController 경로
"/favicon.ico", // 브라우저 기본 요청
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.util.List;

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand All @@ -12,41 +16,75 @@
import org.springframework.web.bind.annotation.RequestParam;

import com.stockm8.domain.vo.CategoryVO;
import com.stockm8.domain.vo.UserVO;
import com.stockm8.service.CategoryService;
import com.stockm8.service.UserService;

@Controller
@RequestMapping("/category")
public class CategoryController {

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

@Inject
private CategoryService cService;
private CategoryService categoryService;

@Inject
private UserService userService;

// http://localhost:8088/category/register
// 카테고리 등록 페이지 호출 (GET)
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String registerCategoryGET(Model model) throws Exception {
public String registerCategoryGET(Model model, HttpServletRequest request) throws Exception {
logger.info("registerCategoryGET(Model model, HttpServletRequest request) 호출");
// 세션에서 userId 가져오기
HttpSession session = request.getSession(false);
Long userId = (session != null) ? (Long)session.getAttribute("userId") : null;
logger.info("session: {}", userId);

// userId로 사용자 정보 조회
UserVO user = userService.getUserById(userId);
int businessId = user.getBusinessId();
logger.info("businessId: {}", businessId);

// 필요한 데이터 (예: 상위 카테고리 목록 등) 전달
List<CategoryVO> parentCategories = cService.getAllCategories();
model.addAttribute("parentCategories", parentCategories);
List<CategoryVO> categoryList = categoryService.getCategoriesByBusinessId(businessId);
model.addAttribute("categoryList", categoryList);
logger.info("Category List: {}", categoryList);

// 카테고리 등록 폼을 보여주는 페이지로 이동
return "category/register";
}

// 카테고리 등록 처리 (POST)
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerCategoryPOST(CategoryVO vo) throws Exception {
public String registerCategoryPOST(CategoryVO category, HttpServletRequest request) throws Exception {
logger.info("registerCategoryPOST(CategoryVO category, HttpServletRequest request) 실행");

logger.info(category+"");
// 세션에서 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();
category.setBusinessId(businessId);

// 서비스 호출: 부모 카테고리 체크와 카테고리 등록을 서비스에서 처리
cService.registerCategoryWithParentCheck(vo);
categoryService.registerCategoryWithParentCheck(category);

// 등록 후 목록 페이지로 리다이렉트
return "redirect:/category/list";
}


// http://localhost:8088/category/list
// 카테고리 목록 페이지 호출 (GET)
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String listCategoryGET(Model model) throws Exception {
logger.info("listCategoryGET(Model model) 호출");
// 카테고리 목록 조회
List<CategoryVO> categories = cService.getAllCategories();
List<CategoryVO> categories = categoryService.getAllCategories();

// JSP로 데이터 전달
model.addAttribute("categories", categories);
Expand All @@ -56,31 +94,41 @@ public String listCategoryGET(Model model) throws Exception {
// 카테고리 수정 페이지 (GET)
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String editCategoryGET(@RequestParam("categoryId") int categoryId, Model model) throws Exception {
// 카테고리와 상위 카테고리 정보 가져오기
CategoryVO category = cService.getCategoryWithParents(categoryId);
model.addAttribute("category", category);

// 상위 카테고리 정보
if (category.getParentId() != null) {
CategoryVO parentCategory = cService.getCategoryWithParents(category.getParentId());
model.addAttribute("parentCategory", parentCategory);
}
logger.info("editCategoryGET(@RequestParam(\"categoryId\") int categoryId, Model model) 호출");
// 카테고리와 상위 카테고리 정보 가져오기
CategoryVO vo = categoryService.getCategoryWithParents(categoryId);
model.addAttribute("category", vo);

// 상위 카테고리 정보 (부모 카테고리 리스트 가져오기)
List<CategoryVO> parentCategories = categoryService.getParentCategories(); // 부모 카테고리 리스트를 가져오기
model.addAttribute("parentCategories", parentCategories);

return "category/edit";
}

// 카테고리 수정 처리 (POST)
@RequestMapping(value = "/edit", method = RequestMethod.POST)
public String editCategoryPOST(@ModelAttribute CategoryVO vo) throws Exception {
cService.updateCategory(vo);
return "redirect:/category/list";
public String editCategoryPOST(@ModelAttribute CategoryVO category) throws Exception {
logger.info("editCategoryPOST(@ModelAttribute CategoryVO vo) 실행");

// 부모 카테고리가 비어 있으면 null로 처리
if (category.getParentId() != null && category.getParentId().equals("")) {
category.setParentId(null);
logger.info("부모 카테고리가 비어있어 null로 설정됨, categoryId: {}", category.getCategoryId());
}
// 카테고리 수정
categoryService.updateCategory(category);
logger.info("카테고리 수정 완료, categoryId: {}", category.getCategoryId());

return "redirect:/category/list"; // 수정 후 목록 페이지로 리다이렉트
}

// 카테고리 삭제 페이지 (GET)
@RequestMapping(value = "/delete", method = RequestMethod.GET)
public String deleteCategoryGET(@RequestParam("categoryId") int categoryId, Model model) throws Exception {
// 삭제할 카테고리 정보 가져오기
CategoryVO category = cService.getCategoryWithParents(categoryId);
CategoryVO category = categoryService.getCategoryWithParents(categoryId);
model.addAttribute("category", category);

return "category/delete";
Expand All @@ -90,7 +138,7 @@ public String deleteCategoryGET(@RequestParam("categoryId") int categoryId, Mode
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String deleteCategoryPOST(@RequestParam("categoryId") int categoryId) throws Exception {
// 카테고리 삭제 처리
cService.deleteCategory(categoryId);
categoryService.deleteCategory(categoryId);

return "redirect:/category/list";
}
Expand Down
162 changes: 123 additions & 39 deletions stockMate/src/main/java/com/stockm8/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ public class UserController {
@Autowired
private UserService userService;

// http://localhost:8088/user/login (o)
// http://localhost:8088/user/signin (o)
// http://localhost:8088/user/main (o)
// http://localhost:8088/user/signup (o)
// http://localhost:8088/user/dash (o)
// http://localhost:8088/user/dashboard (o)
// http://localhost:8088/user/info1 (o)
// http://localhost:8088/user/info2 (o)
// http://localhost:8088/user/editinfo1 (o)
// http://localhost:8088/user/editinfo2 (o)
// http://localhost:8088/user/consultation (o)
// http://localhost:8088/user/changepassword1 (o)

// 회원가입 - 정보입력 / GET 방식
@RequestMapping(value = "/signup", method = RequestMethod.GET)
Expand All @@ -58,13 +62,13 @@ public String userSignUpPOST(/* @ModelAttribute */ UserVO user) throws Exception
logger.info("Role received: " + user.getRole());

// 전달정보 저장
// logger.info("vo :" + user);
logger.info("vo :" + user);

// userDAO객체가 필요 => 주입
// DB에 정보를 전달 - 회원가입동작 실행
// mdao.userJoin(vo); // => 잘못됨
// 서비스 -> DAO 호출
// userService.userJoin(user);
userService.userJoin(user);

// 로그인 페이지로 이동
return "redirect:/user/signin";
Expand Down Expand Up @@ -115,7 +119,7 @@ public String userLoginPOST(UserVO user, RedirectAttributes rttr, HttpSession se
session.removeAttribute("redirectAfterLogin"); // 세션에서 URL 삭제
return "redirect:" + redirectUrl;
}
return "redirect:/user/main";
return "redirect:/user/dash";
}

// 로그인 실패 처리
Expand All @@ -133,7 +137,7 @@ public void mainGET() throws Exception {
}

// 대시보드 페이지 - GET
@RequestMapping(value = "/dash", method = RequestMethod.GET)
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
public void dashGET() {
logger.info(" dashGET() 호출 ");

Expand Down Expand Up @@ -165,7 +169,18 @@ public String userInfo1GET(Model model, HttpSession session) throws Exception {
model.addAttribute("resultVO", resultVO);
return "user/info1";
}

// 회원정보 조회 - /user/info1 (GET)
@RequestMapping(value = "/info2", method = RequestMethod.GET)
public String userInfo2GET(Model model, HttpSession session) throws Exception {
Long userId = (Long) session.getAttribute("id");
// if (id == null) {
// // 세션에 id가 없으면 에러 처리
// return "redirect:/user/main";
// }
UserVO resultVO = userService.getUser(userId);
model.addAttribute("resultVO", resultVO);
return "user/info2";
}



Expand All @@ -187,40 +202,109 @@ public String userInfo1GET(Model model, HttpSession session) throws Exception {
// }
//

// 회원정보 수정 - GET
// (기존정보를 가져와서 보여주고, 수정할 정보를 입력)
@RequestMapping(value = "/editInfo1", method = RequestMethod.GET)
public void userUpdateGET(@SessionAttribute("id") Long userId, Model model) throws Exception {
logger.info(" userUpdateGET() 호출 ");

// 사용자의 ID정보를 가져오기(세션)
logger.info("id : " + userId);

// 서비스 -> DAO 회원정보 가져오는 동작 호출
UserVO resultVO = userService.getUser(userId);

// 연결된 뷰페이지에 출력
// => model 객체에 정보 저장
model.addAttribute("resultVO", resultVO);
// /user/update.jsp 뷰페이지 연결
}

// 회원정보 수정 - POST
// (수정된 정보를 전달받아서 정보 수정)
@RequestMapping(value = "/editInfo2", method = RequestMethod.POST)
public String userUpdatePOST(UserVO user) throws Exception {
logger.info(" userUpdatePOST() ");

// 전달정보(수정정보) 저장
logger.info("vo : " + user);

// 서비스 -> DAO 호출 (회원정보 수정)
userService.updateUser(user);
// 회원정보 수정 - /user/info1 (GET)
@RequestMapping(value = "/editinfo1", method = RequestMethod.GET)
public String usereditinfo1GET(Model model, HttpSession session) throws Exception {
Long userId = (Long) session.getAttribute("id");
// if (id == null) {
// // 세션에 id가 없으면 에러 처리
// return "redirect:/user/main";
// }
UserVO resultVO = userService.getUser(userId);
model.addAttribute("resultVO", resultVO);
return "user/editinfo1";
}
// 회원정보 수정 - /user/info1 (GET)
@RequestMapping(value = "/editinfo2", method = RequestMethod.POST)
public String usereditinfo2GET(Model model, HttpSession session) throws Exception {


logger.info("ㅇㄻ니");
Long userId = (Long) session.getAttribute("id");
// if (id == null) {
// // 세션에 id가 없으면 에러 처리
// return "redirect:/user/main";
// }
UserVO resultVO = userService.getUser(userId);
model.addAttribute("resultVO", resultVO);
return "/user/editinfo2";
}



// 비밀번호 찾기 - get
@RequestMapping(value = "/findPassword", method = RequestMethod.GET)
public String findPasswordGet() {

// 수정완료시 메인페이지로 이동
return "redirect:/user/dash";
}
return "/user/findPassword";
}


// // 회원정보 수정 - GET
// // (기존정보를 가져와서 보여주고, 수정할 정보를 입력)
// @RequestMapping(value = "/editinfo1", method = RequestMethod.GET)
// public void userUpdateGET(@SessionAttribute("userId") Long userId, Model model) throws Exception {
// logger.info(" userUpdateGET() 호출 ");
//
// // 사용자의 ID정보를 가져오기(세션)
// logger.info("userId : " + userId);
//
// // 서비스 -> DAO 회원정보 가져오는 동작 호출
// UserVO resultVO = userService.getUser(userId);
//
// // 연결된 뷰페이지에 출력
// // => model 객체에 정보 저장
// model.addAttribute("resultVO", resultVO);
// // /user/update.jsp 뷰페이지 연결
// }
//
// // 회원정보 수정 - POST
// // (수정된 정보를 전달받아서 정보 수정)
// @RequestMapping(value = "/editinfo2", method = RequestMethod.POST)
// public String userUpdatePOST(UserVO user) throws Exception {
// logger.info(" userUpdatePOST() ");
//
// // 전달정보(수정정보) 저장
// logger.info("vo : " + user);
//
// // 서비스 -> DAO 호출 (회원정보 수정)
// userService.updateUser(user);
//
// // 수정완료시 메인페이지로 이동
// return "redirect:/dashboard";
// }

// 대시보드 사용법 - /user/consultation (GET)
@RequestMapping(value = "/consultation", method = RequestMethod.GET)
public String consultationGET(Model model, HttpSession session) throws Exception {
Long userId = (Long) session.getAttribute("id");
// if (id == null) {
// // 세션에 id가 없으면 에러 처리
// return "redirect:/user/main";
// }
UserVO resultVO = userService.getUser(userId);
model.addAttribute("resultVO", resultVO);
return "user/consultation";
}

// 비밀번호 변경 - /user/changepassword1 (GET)
@RequestMapping(value = "/changepassword1", method = RequestMethod.GET)
public String changepassword1GET(Model model, HttpSession session) throws Exception {
Long userId = (Long) session.getAttribute("id");
// if (id == null) {
// // 세션에 id가 없으면 에러 처리
// return "redirect:/user/main";
// }
UserVO resultVO = userService.getUser(userId);
model.addAttribute("resultVO", resultVO);
return "user/changepassword1";
}






// 회원정보 삭제 - 비밀번호 입력 (GET)
@RequestMapping(value = "/delete", method = RequestMethod.GET)
public String userDeleteGET() throws Exception {
Expand Down
Loading

0 comments on commit 8f5d13a

Please sign in to comment.