From bd62f15d3e3fbda9e5bece56549ffcf307f49a64 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Sun, 5 May 2024 19:31:46 +0900 Subject: [PATCH 01/15] =?UTF-8?q?Feat:=20=EC=9C=A0=EC=A0=80=20=EC=97=AD?= =?UTF-8?q?=ED=95=A0=20=EB=B3=80=EA=B2=BD=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20(web)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deu/connect/luck/user/UserController.java | 24 ++++++++++++++----- .../kr/deu/connect/luck/user/UserService.java | 4 ++-- .../resources/templates/user/add_role.html | 20 ++++++++++++++++ .../resources/templates/user/profile.html | 2 ++ 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/templates/user/add_role.html diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserController.java b/src/main/java/ac/kr/deu/connect/luck/user/UserController.java index 6287396..a076a05 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserController.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserController.java @@ -1,7 +1,6 @@ package ac.kr.deu.connect.luck.user; import ac.kr.deu.connect.luck.auth.SignUpRequest; -import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; @@ -19,8 +18,7 @@ public class UserController { @GetMapping public String gerUserInfo(Principal principal, Model model) { - User user = userService.findUserByEmail(principal.getName()); - model.addAttribute("userInfo", userService.findUserInfo(user.getId())); + model.addAttribute("userInfo", userService.findUserInfo(principal.getName())); return "user/profile"; } @@ -36,9 +34,9 @@ public String deleteUser(Principal principal) { } @GetMapping("/update") - public String updateUserPageRequest(Model model, HttpServletRequest request) { - User user = (User) request.getSession().getAttribute("user"); - model.addAttribute("userInfo", userService.findUserInfo(user.getId())); + public String updateUserPageRequest( + Model model, Principal principal) { + model.addAttribute("userInfo", userService.findUserInfo(principal.getName())); return "user/profile_edit"; } @@ -54,5 +52,19 @@ public String updateUser( return "redirect:/user"; } + @GetMapping("/add-role") + public String addRolePageRequest() { + return "user/add_role"; + } + + @PostMapping("/add-role") + public String addRole( + Principal principal, + @RequestParam("role") UserRole role + ) { + userService.setUserRole(principal.getName(), role); + return "redirect:/user"; + } + } diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserService.java b/src/main/java/ac/kr/deu/connect/luck/user/UserService.java index d336dae..65c40f5 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserService.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserService.java @@ -51,8 +51,8 @@ public User updateUser(String userEmail, SignUpRequest signUpRequest) { return userRepository.save(findUser); } - public UserInfo findUserInfo(Long id) { - User user = userRepository.findById(id).orElseThrow(() -> new CustomException(CustomErrorCode.USER_ID_NOT_MATCH)); + public UserInfo findUserInfo(String userEmail) { + User user = userRepository.findByEmail(userEmail).orElseThrow(() -> new CustomException(CustomErrorCode.USER_ID_NOT_MATCH)); List reviews = foodTruckReviewRepository.findByAuthor(user); return new UserInfo(user, reviews); diff --git a/src/main/resources/templates/user/add_role.html b/src/main/resources/templates/user/add_role.html new file mode 100644 index 0000000..7984539 --- /dev/null +++ b/src/main/resources/templates/user/add_role.html @@ -0,0 +1,20 @@ + + + +

회원 권한 추가

+ +
+
+
+
+ + +
+ +
+
+
+
+ diff --git a/src/main/resources/templates/user/profile.html b/src/main/resources/templates/user/profile.html index 30c83b2..c58e18e 100644 --- a/src/main/resources/templates/user/profile.html +++ b/src/main/resources/templates/user/profile.html @@ -40,6 +40,8 @@

내가 작성한 리뷰

From f1610f90f5042ffa6a7d2b844b0d6a1712041491 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Sun, 5 May 2024 21:32:36 +0900 Subject: [PATCH 02/15] =?UTF-8?q?Feat:=20=ED=91=B8=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=9F=AD=20=EB=93=B1=EB=A1=9D&=EC=88=98=EC=A0=95=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FoodTruckController.java | 71 ++++++++++++++++++- .../FoodTruckMenuRestController.java | 2 +- .../repository/FoodTruckRepository.java | 2 +- .../food_truck/service/FoodTruckService.java | 4 ++ .../kr/deu/connect/luck/user/UserService.java | 5 -- .../food_truck/food_truck_register.html | 6 -- .../food_truck/manager/food_truck_edit.html | 37 ++++++++++ .../manager/food_truck_edit_photo.html | 19 +++++ .../manager/food_truck_register.html | 32 +++++++++ .../manager/my_food_truck_list.html | 34 +++++++++ .../templates/fragments/nav-bar.html | 2 +- 11 files changed, 199 insertions(+), 15 deletions(-) delete mode 100644 src/main/resources/templates/food_truck/food_truck_register.html create mode 100644 src/main/resources/templates/food_truck/manager/food_truck_edit.html create mode 100644 src/main/resources/templates/food_truck/manager/food_truck_edit_photo.html create mode 100644 src/main/resources/templates/food_truck/manager/food_truck_register.html create mode 100644 src/main/resources/templates/food_truck/manager/my_food_truck_list.html diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java index 1d83a35..42020e4 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java @@ -1,12 +1,19 @@ package ac.kr.deu.connect.luck.food_truck.controller; +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequest; +import ac.kr.deu.connect.luck.food_truck.entity.FoodType; import ac.kr.deu.connect.luck.food_truck.service.FoodTruckService; import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.multipart.MultipartFile; + +import java.security.Principal; @Controller @RequestMapping("/food-truck") @@ -28,10 +35,72 @@ public String getFoodTruckDetail( return "food_truck/food_truck_detail"; } + @GetMapping("/{id}/edit") + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") + public String editFoodTruck( + @PathVariable Long id, Model model + ) { + model.addAttribute("foodTruck", foodTruckService.getFoodTruck(id)); + return "food_truck/manager/food_truck_edit"; + } + + @PostMapping("/{id}/edit") + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") + public String editFoodTruckPost( + @PathVariable Long id, Principal principal, + FoodTruckRequest foodTruckRequest + ) { + foodTruckService.updateFoodTruck(id, principal.getName(), foodTruckRequest); + return "redirect:/food-truck/my"; + } + @GetMapping("{id}/edit.photo") + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") + public String editFoodTruckPhoto( + @PathVariable Long id, Model model + ) { + model.addAttribute("foodTruck", foodTruckService.getFoodTruck(id)); + return "food_truck/manager/food_truck_edit_photo"; + } + + @PostMapping(value = "{id}/edit.photo", consumes = "multipart/form-data") + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") + public String editFoodTruckPhotoPost( + @PathVariable Long id,Principal principal, + MultipartFile image + ) { + foodTruckService.updateFoodTruckImage(id, principal.getName(), image); + return "redirect:/food-truck/{id}/edit"; + } + + + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") + @GetMapping("/my") + public String getMyFoodTruck(Model model, Principal principal) { + model.addAttribute("foodTrucks", foodTruckService.getMyFoodTrucks(principal.getName())); + return "food_truck/manager/my_food_truck_list"; + } + + + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") @GetMapping("/register") public String registerFoodTruck() { - return "food_truck/food_truck_register"; + return "food_truck/manager/food_truck_register"; + } + + @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") + @PostMapping("/register") + public String registerFoodTruckPost( + Principal principal, + String name, + String description, + String foodType, + MultipartFile image + ) { + FoodType type = FoodType.valueOf(foodType); + FoodTruckRequest foodTruckRequest = new FoodTruckRequest(name, description, type); + foodTruckService.createFoodTruck(principal.getName(), foodTruckRequest); + return "redirect:/food-truck/my"; } } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuRestController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuRestController.java index d6101e8..29d5220 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuRestController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuRestController.java @@ -49,7 +49,7 @@ public ResponseEntity saveFoodTruckMenu( @PatchMapping(value = "/{foodTruckMenuId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") - @Operation(summary = "푸드트럭 메뉴 수정") + @Operation(summary = "푸드트럭 메뉴 수정", description = "특정 푸드트럭 메뉴를 수정합니다. 푸드트럭 매니저의 역할이 필요합니다.") public ResponseEntity updateFoodTruckMenu( @Parameter(description = "푸드트럭 UID") @PathVariable("foodTruckId") Long foodTruckId, @Parameter(description = "메뉴 UID") @PathVariable("foodTruckMenuId") Long foodTruckMenuId, diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckRepository.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckRepository.java index d35a016..20672e1 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckRepository.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckRepository.java @@ -18,6 +18,6 @@ public interface FoodTruckRepository extends JpaRepository { List findByNameContainingAndFoodType(String name, FoodType foodType); - void deleteByManager(User manager); + List findAllByManagerEmail(String email); } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java index 983b283..a4bbbff 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java @@ -148,6 +148,10 @@ public FoodTruck updateFoodTruckImage(Long foodTruckId, String userEmail, Multip return foodTruckRepository.save(foodTruck); } + public List getMyFoodTrucks(String userEmail) { + return foodTruckRepository.findAllByManagerEmail(userEmail); + } + /** * 푸드트럭 매니저인지 확인합니다. * 푸드트럭 매니저가 아닌 경우 예외를 발생시킵니다. diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserService.java b/src/main/java/ac/kr/deu/connect/luck/user/UserService.java index 65c40f5..82d0451 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserService.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserService.java @@ -1,20 +1,15 @@ package ac.kr.deu.connect.luck.user; import ac.kr.deu.connect.luck.auth.SignUpRequest; -import ac.kr.deu.connect.luck.event.EventRepository; import ac.kr.deu.connect.luck.exception.CustomErrorCode; import ac.kr.deu.connect.luck.exception.CustomException; -import ac.kr.deu.connect.luck.food_truck.entity.FoodTruck; import ac.kr.deu.connect.luck.food_truck.entity.FoodTruckReview; -import ac.kr.deu.connect.luck.food_truck.repository.FoodTruckMenuRepository; -import ac.kr.deu.connect.luck.food_truck.repository.FoodTruckRepository; import ac.kr.deu.connect.luck.food_truck.repository.FoodTruckReviewRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; -import java.security.Principal; import java.util.List; @Service diff --git a/src/main/resources/templates/food_truck/food_truck_register.html b/src/main/resources/templates/food_truck/food_truck_register.html deleted file mode 100644 index 20a0928..0000000 --- a/src/main/resources/templates/food_truck/food_truck_register.html +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/main/resources/templates/food_truck/manager/food_truck_edit.html b/src/main/resources/templates/food_truck/manager/food_truck_edit.html new file mode 100644 index 0000000..fce8254 --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/food_truck_edit.html @@ -0,0 +1,37 @@ + + + +

폼 수정

+
+ Food Truck Image +
+
+
+ +
+ + +
+
+ + +
+ +
+ + + +
+ + + + +
+
+ + +
+ diff --git a/src/main/resources/templates/food_truck/manager/food_truck_edit_photo.html b/src/main/resources/templates/food_truck/manager/food_truck_edit_photo.html new file mode 100644 index 0000000..01f74dd --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/food_truck_edit_photo.html @@ -0,0 +1,19 @@ + + + +

사진 변경 기능

+ +
+
+ +
+ + +
+ +
+
+ + +
+ diff --git a/src/main/resources/templates/food_truck/manager/food_truck_register.html b/src/main/resources/templates/food_truck/manager/food_truck_register.html new file mode 100644 index 0000000..1218e3f --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/food_truck_register.html @@ -0,0 +1,32 @@ + + + + +
+

푸드트럭 등록

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+ diff --git a/src/main/resources/templates/food_truck/manager/my_food_truck_list.html b/src/main/resources/templates/food_truck/manager/my_food_truck_list.html new file mode 100644 index 0000000..1936010 --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/my_food_truck_list.html @@ -0,0 +1,34 @@ + + + +

내 푸드트럭

+ +
+ + +
+ +
+
+ + Food Truck Image +
+ +
+ +

+ +

+ +
+
+
+
+
+
+ diff --git a/src/main/resources/templates/fragments/nav-bar.html b/src/main/resources/templates/fragments/nav-bar.html index 88eaec3..2a6110b 100644 --- a/src/main/resources/templates/fragments/nav-bar.html +++ b/src/main/resources/templates/fragments/nav-bar.html @@ -47,7 +47,7 @@ From 2a1c44a7de4f88de55c68f8e951242e73615983b Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Mon, 6 May 2024 03:43:29 +0900 Subject: [PATCH 03/15] =?UTF-8?q?Feat:=20=ED=91=B8=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=9F=AD=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../food_truck/food_truck_detail.html | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/main/resources/templates/food_truck/food_truck_detail.html b/src/main/resources/templates/food_truck/food_truck_detail.html index 20a0928..507f1ae 100644 --- a/src/main/resources/templates/food_truck/food_truck_detail.html +++ b/src/main/resources/templates/food_truck/food_truck_detail.html @@ -2,5 +2,67 @@ +
+

푸드트럭 상세 정보

+
+
+ Food Truck Image +
+
+
+

+

+

+ +
+
+ +
+
+

메뉴

+ + + + + + + + + + + + + + + + + +
사진이름가격설명
Menu Image
+
+
+ +
+
+

후기

+ + + + + + + + + + + + + + + +
작성자내용평점
+
+
+
+
From ba1edb3fb1abed2ea9b2a27f1943725fabd7fe79 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Mon, 6 May 2024 17:20:16 +0900 Subject: [PATCH 04/15] style: Code Autoformatting --- .../ac/kr/deu/connect/luck/auth/AuthController.java | 12 +++--------- .../luck/event/controller/EventController.java | 2 +- .../EventApplicationRepository.java | 2 +- .../food_truck/controller/FoodTruckController.java | 2 +- .../luck/food_truck/dto/FoodTruckDetailResponse.java | 1 - .../repository/FoodTruckReviewRepository.java | 4 ++++ .../ac/kr/deu/connect/luck/image/ImageUploader.java | 6 +++--- .../ac/kr/deu/connect/luck/now/NowRepository.java | 2 +- .../java/ac/kr/deu/connect/luck/now/NowService.java | 5 +---- .../deu/connect/luck/security/JwtTokenProvider.java | 8 +------- src/main/java/ac/kr/deu/connect/luck/user/User.java | 8 +++----- 11 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java index 5e00b03..655afd2 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java @@ -2,7 +2,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -13,21 +13,15 @@ @Controller @RequestMapping("/auth") +@RequiredArgsConstructor public class AuthController { + private final AuthService authService; @Value("${security.jwt.token.header}") private String AUTHORIZATION_HEADER; - @Value("${security.jwt.token.prefix}") private String TOKEN_PREFIX; - private final AuthService authService; - - @Autowired - public AuthController(AuthService authService) { - this.authService = authService; - } - @GetMapping("/login") public String login() { return "auth/login"; diff --git a/src/main/java/ac/kr/deu/connect/luck/event/controller/EventController.java b/src/main/java/ac/kr/deu/connect/luck/event/controller/EventController.java index be6a56b..785e5e5 100644 --- a/src/main/java/ac/kr/deu/connect/luck/event/controller/EventController.java +++ b/src/main/java/ac/kr/deu/connect/luck/event/controller/EventController.java @@ -5,8 +5,8 @@ import org.springframework.stereotype.Controller; 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.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/event") diff --git a/src/main/java/ac/kr/deu/connect/luck/event_application/EventApplicationRepository.java b/src/main/java/ac/kr/deu/connect/luck/event_application/EventApplicationRepository.java index 148d717..baef6d5 100644 --- a/src/main/java/ac/kr/deu/connect/luck/event_application/EventApplicationRepository.java +++ b/src/main/java/ac/kr/deu/connect/luck/event_application/EventApplicationRepository.java @@ -29,7 +29,7 @@ public interface EventApplicationRepository extends JpaRepository findAllByFoodTruckManager(User user); - List findAllByEventManager(User user); + List findAllByEventManagerAndEventId(User user, Long eventId); } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java index 42020e4..ae29f08 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java @@ -66,7 +66,7 @@ public String editFoodTruckPhoto( @PostMapping(value = "{id}/edit.photo", consumes = "multipart/form-data") @PreAuthorize("hasRole('FOOD_TRUCK_MANAGER')") public String editFoodTruckPhotoPost( - @PathVariable Long id,Principal principal, + @PathVariable Long id, Principal principal, MultipartFile image ) { foodTruckService.updateFoodTruckImage(id, principal.getName(), image); diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckDetailResponse.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckDetailResponse.java index 59dc82f..3cf722a 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckDetailResponse.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckDetailResponse.java @@ -1,7 +1,6 @@ package ac.kr.deu.connect.luck.food_truck.dto; import ac.kr.deu.connect.luck.food_truck.entity.FoodType; -import ac.kr.deu.connect.luck.user.User; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckReviewRepository.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckReviewRepository.java index 5893842..a4f6f9b 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckReviewRepository.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/repository/FoodTruckReviewRepository.java @@ -12,8 +12,12 @@ public interface FoodTruckReviewRepository extends JpaRepository { void deleteAllByFoodTruck(FoodTruck foodTruck); + void deleteAllByAuthor(User author); + List findByFoodTruck(FoodTruck foodTruck); + List findByFoodTruckId(Long foodTruckId); + List findByAuthor(User author); } diff --git a/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java b/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java index 0f5759f..8889cc1 100644 --- a/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java +++ b/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java @@ -23,11 +23,11 @@ public class ImageUploader { @Value("${imgbb.api-key}") private String API_KEY; - private String BASE_URL = "https://api.imgbb.com/1/upload"; + private final String BASE_URL = "https://api.imgbb.com/1/upload"; - private Long EXPIRATION = 15552000L; + private final Long EXPIRATION = 15552000L; - private RestTemplate restTemplate = new RestTemplate(); + private final RestTemplate restTemplate = new RestTemplate(); public ImageUploadResponse uploadImage(MultipartFile file) { diff --git a/src/main/java/ac/kr/deu/connect/luck/now/NowRepository.java b/src/main/java/ac/kr/deu/connect/luck/now/NowRepository.java index 7ec6b90..49cd5c9 100644 --- a/src/main/java/ac/kr/deu/connect/luck/now/NowRepository.java +++ b/src/main/java/ac/kr/deu/connect/luck/now/NowRepository.java @@ -11,7 +11,7 @@ public interface NowRepository extends JpaRepository { Optional findByFoodTruckId(Long foodTruckId); - List findByLatitudeBetweenAndLongitudeBetweenAndIsOperating(Double latitudeStart, Double latitudeEnd, Double longitudeStart, Double longitudeEnd,Boolean isOperating); + List findByLatitudeBetweenAndLongitudeBetweenAndIsOperating(Double latitudeStart, Double latitudeEnd, Double longitudeStart, Double longitudeEnd, Boolean isOperating); List findByIsOperating(Boolean isOperating); diff --git a/src/main/java/ac/kr/deu/connect/luck/now/NowService.java b/src/main/java/ac/kr/deu/connect/luck/now/NowService.java index 03c2671..d0583e7 100644 --- a/src/main/java/ac/kr/deu/connect/luck/now/NowService.java +++ b/src/main/java/ac/kr/deu/connect/luck/now/NowService.java @@ -14,14 +14,11 @@ @Service @RequiredArgsConstructor public class NowService { + protected static Double DISTANCE = 0.05; private final NowRepository nowRepository; private final FoodTruckRepository foodTruckRepository; private final JwtTokenProvider jwtTokenProvider; - - protected static Double DISTANCE = 0.05; - - /** * 현재 운영중인 푸드트럭 조회 * diff --git a/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java b/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java index 85700a3..37b82b0 100644 --- a/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java +++ b/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java @@ -26,26 +26,20 @@ @Slf4j @Component public class JwtTokenProvider { + private final MyUserDetails myUserDetails; @Value("${security.jwt.token.secret}") private String secretKey; - @Value("${security.jwt.token.expiration}") private long validityInMilliseconds; - @Value("${security.jwt.token.header}") private String header; - @Value("${security.jwt.token.prefix}") private String prefix; - @Value("${security.jwt.token.issuer}") private String issuer; - @Value("${security.jwt.token.audience}") private String audience; - private MyUserDetails myUserDetails; - @Autowired public JwtTokenProvider(MyUserDetails myUserDetails) { this.myUserDetails = myUserDetails; diff --git a/src/main/java/ac/kr/deu/connect/luck/user/User.java b/src/main/java/ac/kr/deu/connect/luck/user/User.java index 0d1758f..5847442 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/User.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/User.java @@ -18,6 +18,9 @@ @AllArgsConstructor @NoArgsConstructor public class User extends BaseEntity { + @ElementCollection(fetch = FetchType.EAGER) + @Enumerated(EnumType.STRING) + List roles; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -27,11 +30,6 @@ public class User extends BaseEntity { private String name; @Column(unique = true) private String phone; - - @ElementCollection(fetch = FetchType.EAGER) - @Enumerated(EnumType.STRING) - List roles; - @OneToMany(mappedBy = "author", cascade = CascadeType.REMOVE) @JsonManagedReference private List reviews; From 265a2aad9119508e3dd4cc840417af060cff160a Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Wed, 8 May 2024 17:14:11 +0900 Subject: [PATCH 05/15] =?UTF-8?q?Security:=20=ED=91=B8=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=9F=AD=20=EB=A7=A4=EB=8B=88=EC=A0=80=20=EA=B2=80=EC=A6=9D=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kr/deu/connect/luck/common/Checker.java | 35 +++++++++++++++++++ .../controller/FoodTruckRestController.java | 2 +- .../food_truck/service/FoodTruckService.java | 2 -- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ac/kr/deu/connect/luck/common/Checker.java diff --git a/src/main/java/ac/kr/deu/connect/luck/common/Checker.java b/src/main/java/ac/kr/deu/connect/luck/common/Checker.java new file mode 100644 index 0000000..52e6c99 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/common/Checker.java @@ -0,0 +1,35 @@ +package ac.kr.deu.connect.luck.common; + +import ac.kr.deu.connect.luck.food_truck.entity.FoodTruck; +import ac.kr.deu.connect.luck.food_truck.repository.FoodTruckRepository; +import groovy.util.logging.Slf4j; +import lombok.RequiredArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +@Slf4j +@Component +@RequiredArgsConstructor +public class Checker { + private static final Logger log = LoggerFactory.getLogger(Checker.class); + private final FoodTruckRepository foodTruckRepository; + + + public boolean isFoodTruckManager(Long id) { + + log.info("id : " + id); + FoodTruck foodTruck = foodTruckRepository.findById(id).orElseThrow( + () -> new IllegalArgumentException("해당 푸드트럭이 존재하지 않습니다.") + ); + + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + + log.info("authentication.getName() : " + authentication.getName()); + log.info("foodTruck.getManager().getEmail() : " + foodTruck.getManager().getEmail()); + + return authentication.getName().equals(foodTruck.getManager().getEmail()); + } +} + diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java index 13ac4d3..6823eef 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java @@ -53,7 +53,7 @@ public ResponseEntity createFoodTruck( @PatchMapping("/{id}") - @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER') and @checker.isFoodTruckManager(#truckId)") @Operation(summary = "푸드트럭 정보를 업데이트 합니다.", description = "푸드트럭 정보를 업데이트 합니다. 푸드트럭 관리자만 가능합니다.
푸드트럭의 대표 이미지를 변경하려면 /{id}/update-image API를 활용하십시오.") public ResponseEntity updateFoodTruck( @Parameter(description = "푸드트럭 UID") @PathVariable("id") Long truckId, diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java index a4bbbff..11d0367 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java @@ -106,8 +106,6 @@ public FoodTruckDetailResponse updateFoodTruck(Long foodTruckId, String userEmai FoodTruck foodTruck = foodTruckRepository.findById(foodTruckId).orElseThrow( () -> new CustomException(CustomErrorCode.FOOD_TRUCK_NOT_FOUND) ); - // Check if the user is the manager of the food truck - isManager(userEmail, foodTruck); // 수정할 정보가 있는 경우 수정 if (foodTruckRequest.name() != null) { From fd178108bad59884fd3c88e1992cbcd3764b25af Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Sat, 11 May 2024 14:57:05 +0900 Subject: [PATCH 06/15] =?UTF-8?q?Feat:=20=ED=98=84=EC=9E=AC=20=EC=9A=B4?= =?UTF-8?q?=EC=98=81=EC=A4=91=EC=9D=B8=20=ED=91=B8=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=9F=AD=20=EC=A7=80=EB=8F=84=20=EB=A7=88=EC=BB=A4=20=ED=91=9C?= =?UTF-8?q?=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Build&Test.yml | 4 ++ build.gradle | 70 ++++++++++--------- settings.gradle | 8 +++ .../luck/food_truck/entity/FoodType.java | 45 +++++++++++- .../deu/connect/luck/image/ImageUploader.java | 2 +- .../kr/deu/connect/luck/now/NowController.kt | 26 +++++++ .../connect/luck/security/JwtTokenFilter.java | 3 +- .../luck/security/JwtTokenProvider.java | 2 +- src/main/resources/application.yaml | 6 +- .../food_truck/manager/food_truck_edit.html | 2 - .../templates/fragments/nav-bar.html | 3 + src/main/resources/templates/now/now-map.html | 33 +++++++++ 12 files changed, 164 insertions(+), 40 deletions(-) create mode 100644 src/main/java/ac/kr/deu/connect/luck/now/NowController.kt create mode 100644 src/main/resources/templates/now/now-map.html diff --git a/.github/workflows/Build&Test.yml b/.github/workflows/Build&Test.yml index 40ca5de..a42070e 100644 --- a/.github/workflows/Build&Test.yml +++ b/.github/workflows/Build&Test.yml @@ -30,6 +30,10 @@ jobs: - name: Set Environment Variables run: echo "IMGBB_API_KEY=${{ secrets.IMGBB_API_KEY }}" >> $GITHUB_ENV + - name: Set Environment Variables + run: echo "KAKAO_API_KEY=${{ secrets.KAKAO_API_KEY }}" >> $GITHUB_ENV + + - name: Test with Gradle run: ./gradlew --info test diff --git a/build.gradle b/build.gradle index 3c733be..7e59785 100644 --- a/build.gradle +++ b/build.gradle @@ -1,52 +1,58 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.2.3' - id 'io.spring.dependency-management' version '1.1.4' + id 'java' + id 'org.springframework.boot' version '3.2.3' + id 'io.spring.dependency-management' version '1.1.4' + id 'org.jetbrains.kotlin.jvm' } group = 'ac.kr.deu' version = '0.0.1-SNAPSHOT' java { - sourceCompatibility = '17' + sourceCompatibility = JavaVersion.VERSION_17 } configurations { - compileOnly { - extendsFrom annotationProcessor - } + compileOnly { + extendsFrom annotationProcessor + } } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' - implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' - implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0' - implementation 'org.commonmark:commonmark:0.21.0' - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' - - compileOnly 'org.projectlombok:lombok' - developmentOnly 'org.springframework.boot:spring-boot-devtools' - implementation 'org.mapstruct:mapstruct:1.5.5.Final' - annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" - annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' - runtimeOnly 'com.h2database:h2' - annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'org.springframework.security:spring-security-test' - - // JWT - implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' - runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' - runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' + implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6' + implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:3.3.0' + implementation 'org.commonmark:commonmark:0.21.0' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' + + compileOnly 'org.projectlombok:lombok' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + implementation 'org.mapstruct:mapstruct:1.5.5.Final' + annotationProcessor "org.projectlombok:lombok-mapstruct-binding:0.2.0" + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.5.Final' + runtimeOnly 'com.h2database:h2' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.springframework.security:spring-security-test' + + // JWT + implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.5' + runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5' + runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5' + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() +} + +kotlin { + jvmToolchain(17) } diff --git a/settings.gradle b/settings.gradle index 4f49010..f90d7e3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,9 @@ +pluginManagement { + plugins { + id 'org.jetbrains.kotlin.jvm' version '1.9.23' + } +} +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' +} rootProject.name = 'connect.luck' diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/entity/FoodType.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/entity/FoodType.java index 3b9233c..4a9137d 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/entity/FoodType.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/entity/FoodType.java @@ -1,5 +1,48 @@ package ac.kr.deu.connect.luck.food_truck.entity; public enum FoodType { - BURGER, CHICKEN, DESSERT, DRINK, HOTDOG, NOODLE, PIZZA, RICE, SALAD, SANDWICH, SNACK, SOUP, STEAK, SUSHI, ETC + BURGER, + CHICKEN, + DESSERT, + DRINK, + HOTDOG, + NOODLE, + PIZZA, + RICE, + SALAD, + SANDWICH, + SNACK, + SOUP, + STEAK, + SUSHI, + CHINESE, + JAPANESE, + KOREAN, + ITALIAN, + MEXICAN, + FRENCH, + THAI, + VIETNAMESE, + INDIAN, + TURKISH, + GREEK, + SPANISH, + BRAZILIAN, + AMERICAN_SPECIAL, + BRUNCH, + BAKERY, + COFFEE_SHOP, + BAR, + VEGETARIAN, + WESTERN, + TACOS, + BURRITOS, + FOOD_TRUCK_SPECIAL, + STREET_FOOD, + BBQ, + GRILLED_CHEESE, + FISH_TACOS, + FRIED_CHICKEN, + ICE_CREAM, + ETC } diff --git a/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java b/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java index 8889cc1..909a10c 100644 --- a/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java +++ b/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java @@ -20,7 +20,7 @@ @Slf4j public class ImageUploader { - @Value("${imgbb.api-key}") + @Value("${api-key.imgbb}") private String API_KEY; private final String BASE_URL = "https://api.imgbb.com/1/upload"; diff --git a/src/main/java/ac/kr/deu/connect/luck/now/NowController.kt b/src/main/java/ac/kr/deu/connect/luck/now/NowController.kt new file mode 100644 index 0000000..c1a7cc8 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/now/NowController.kt @@ -0,0 +1,26 @@ +package ac.kr.deu.connect.luck.now + +import org.springframework.beans.factory.annotation.Value +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping + + +@Controller +@RequestMapping("/now") +class NowController( + val nowService: NowService +) { + + @Value("\${api-key.kakao}") + private lateinit var apiKey: String + + @GetMapping + fun now(model: Model): String { + model.addAttribute("apiKey", apiKey) + model.addAttribute("nowTruckList", nowService.getNow(null, null)) + return "now/now-map" + } + +} diff --git a/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenFilter.java b/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenFilter.java index 16f927f..11a386d 100644 --- a/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenFilter.java +++ b/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenFilter.java @@ -1,5 +1,6 @@ package ac.kr.deu.connect.luck.security; +import jakarta.annotation.Nonnull; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; @@ -19,7 +20,7 @@ public JwtTokenFilter(JwtTokenProvider jwtTokenProvider) { } @Override - protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { + protected void doFilterInternal(@Nonnull HttpServletRequest httpServletRequest, @Nonnull HttpServletResponse httpServletResponse, @Nonnull FilterChain filterChain) throws ServletException, IOException { String token = jwtTokenProvider.resolveToken(httpServletRequest); try { if (token != null && jwtTokenProvider.validateToken(token)) { diff --git a/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java b/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java index 37b82b0..17606e1 100644 --- a/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java +++ b/src/main/java/ac/kr/deu/connect/luck/security/JwtTokenProvider.java @@ -97,7 +97,7 @@ public Authentication getAuthentication(String token) { } /** - * 헤더에서 토큰 추출 메서드 + * 토큰 추출 메서드 * * @param req 요청 * @return 토큰 diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 1d16371..49c5ea5 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -44,8 +44,10 @@ server: # certificate-private-key: "classpath:privkey.pem" # certificate: "classpath:fullchain.pem" -imgbb: - api-key: ${IMGBB_API_KEY} + +api-key: + imgbb: ${IMGBB_API_KEY} + kakao: ${KAKAO_API_KEY} security: jwt: diff --git a/src/main/resources/templates/food_truck/manager/food_truck_edit.html b/src/main/resources/templates/food_truck/manager/food_truck_edit.html index fce8254..693e021 100644 --- a/src/main/resources/templates/food_truck/manager/food_truck_edit.html +++ b/src/main/resources/templates/food_truck/manager/food_truck_edit.html @@ -31,7 +31,5 @@

폼 수정

- - diff --git a/src/main/resources/templates/fragments/nav-bar.html b/src/main/resources/templates/fragments/nav-bar.html index 2a6110b..9fe4cc0 100644 --- a/src/main/resources/templates/fragments/nav-bar.html +++ b/src/main/resources/templates/fragments/nav-bar.html @@ -27,6 +27,9 @@ + diff --git a/src/main/resources/templates/now/now-map.html b/src/main/resources/templates/now/now-map.html new file mode 100644 index 0000000..992c47f --- /dev/null +++ b/src/main/resources/templates/now/now-map.html @@ -0,0 +1,33 @@ + + + + + + +
+ + +
+ From 8068e79a32ef847aa4e3a9f1db517d816dc6201e Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Mon, 13 May 2024 04:58:07 +0900 Subject: [PATCH 07/15] =?UTF-8?q?fix:=20=ED=9A=8C=EC=9B=90=EA=B0=80?= =?UTF-8?q?=EC=9E=85=20=EA=B2=BD=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/auth/agreement.html | 2 +- src/main/resources/templates/auth/login.html | 2 +- src/main/resources/templates/auth/signup.html | 2 +- .../templates/food_truck/manager/my_food_truck_list.html | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/resources/templates/auth/agreement.html b/src/main/resources/templates/auth/agreement.html index fdd1749..b265c0a 100644 --- a/src/main/resources/templates/auth/agreement.html +++ b/src/main/resources/templates/auth/agreement.html @@ -55,7 +55,7 @@

(선택) 마케팅 활용 동의

- 동의하고 계속하기 + 동의하고 계속하기 diff --git a/src/main/resources/templates/auth/login.html b/src/main/resources/templates/auth/login.html index 1a4061f..63e989a 100644 --- a/src/main/resources/templates/auth/login.html +++ b/src/main/resources/templates/auth/login.html @@ -10,7 +10,7 @@

로그인

-
+
diff --git a/src/main/resources/templates/auth/signup.html b/src/main/resources/templates/auth/signup.html index 382eb1c..0cacb78 100644 --- a/src/main/resources/templates/auth/signup.html +++ b/src/main/resources/templates/auth/signup.html @@ -10,7 +10,7 @@

회원가입

- +
diff --git a/src/main/resources/templates/food_truck/manager/my_food_truck_list.html b/src/main/resources/templates/food_truck/manager/my_food_truck_list.html index 1936010..15e3c56 100644 --- a/src/main/resources/templates/food_truck/manager/my_food_truck_list.html +++ b/src/main/resources/templates/food_truck/manager/my_food_truck_list.html @@ -25,6 +25,9 @@

내 푸드트럭

+
From 3137ff92ac4d62c9ebbea64865f21a9f4df23451 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Mon, 13 May 2024 04:58:22 +0900 Subject: [PATCH 08/15] =?UTF-8?q?Feat:=20=ED=91=B8=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=9F=AD=20=EB=A9=94=EB=89=B4=20=EB=93=B1=EB=A1=9D=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deu/connect/luck/auth/AuthController.java | 106 ----------------- .../deu/connect/luck/auth/AuthController.kt | 108 ++++++++++++++++++ .../kr/deu/connect/luck/common/Checker.java | 1 + .../controller/FoodTruckMenuController.java | 36 ++++++ .../food_truck/dto/FoodTruckMenuRequest.kt | 10 ++ .../service/FoodTruckMenuService.java | 20 ++++ .../deu/connect/luck/user/UserController.java | 3 + .../manager/food_truck_manage_menu.html | 78 +++++++++++++ 8 files changed, 256 insertions(+), 106 deletions(-) delete mode 100644 src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java create mode 100644 src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt create mode 100644 src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckMenuRequest.kt create mode 100644 src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java deleted file mode 100644 index 655afd2..0000000 --- a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.java +++ /dev/null @@ -1,106 +0,0 @@ -package ac.kr.deu.connect.luck.auth; - -import jakarta.servlet.http.Cookie; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; - -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; - -@Controller -@RequestMapping("/auth") -@RequiredArgsConstructor -public class AuthController { - - private final AuthService authService; - @Value("${security.jwt.token.header}") - private String AUTHORIZATION_HEADER; - @Value("${security.jwt.token.prefix}") - private String TOKEN_PREFIX; - - @GetMapping("/login") - public String login() { - return "auth/login"; - } - - @PostMapping("/login") - public String loginPost( - @RequestParam("email") String email, - @RequestParam("password") String password, - HttpServletResponse response) { - // 로그인 - String token = authService.login(new LoginRequest(email, password)).token(); - String encodedToken = URLEncoder.encode(TOKEN_PREFIX + token, StandardCharsets.UTF_8); - - // 쿠키에 토큰 저장 - Cookie cookie = new Cookie(AUTHORIZATION_HEADER, encodedToken); - cookie.setPath("/"); - response.addCookie(cookie); - - return "redirect:/"; - } - - @GetMapping("/agreement") - public String agreement() { - return "auth/agreement"; - } - - @GetMapping("/signup") - public String signup() { - return "auth/signup"; - } - - /** - * 회원가입 처리 - * - * @param email 이메일 - * @param password 비밀번호 - * @param name 이름 - * @param - * @return 홈 화면 - */ - @PostMapping("/signup") - public String signupPost( - @RequestParam("email") String email, - @RequestParam("password") String password, - @RequestParam("name") String name, - @RequestParam("phone") String phone, - HttpServletResponse response) { - // 회원가입 후 자동 로그인 - // 쿠키 저장 시 토큰을 URL 인코딩(URLEncoder.encode)하여 저장 - String token = authService.signUp(new SignUpRequest(email, password, name, phone)).token(); - String encodedToken = URLEncoder.encode(TOKEN_PREFIX + token, StandardCharsets.UTF_8); - Cookie cookie = new Cookie(AUTHORIZATION_HEADER, encodedToken); - cookie.setMaxAge(60 * 30); // 30분 - cookie.setPath("/"); - response.addCookie(cookie); - - return "redirect:/"; - } - - @GetMapping("/logout") - public String logout(@CookieValue(value = "Authorization", defaultValue = "", required = false) Cookie jwtCookie, - HttpServletResponse httpServletResponse) { - // 쿠키 삭제 - jwtCookie.setMaxAge(0); - jwtCookie.setPath("/"); - jwtCookie.setValue(null); - httpServletResponse.addCookie(jwtCookie); - return "redirect:/"; - } - - @GetMapping("/find-id") - public String requestIdSearchPage() { - return "auth/find-id"; - } - - @PostMapping("/find-id") - public String idSearch(@RequestParam("phone") String phone, Model model) { - model.addAttribute("email", authService.findEmailByPhone(phone)); - return "auth/found-id"; - } -} diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt new file mode 100644 index 0000000..50a5f73 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt @@ -0,0 +1,108 @@ +package ac.kr.deu.connect.luck.auth + +import jakarta.servlet.http.Cookie +import jakarta.servlet.http.HttpServletResponse +import org.springframework.beans.factory.annotation.Value +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.web.bind.annotation.* +import java.net.URLEncoder +import java.nio.charset.StandardCharsets + +@Controller +@RequestMapping("/auth") +class AuthController( + val authService: AuthService +) { + @Value("\${security.jwt.token.header}") + private val AUTHORIZATION_HEADER: String? = null + + @Value("\${security.jwt.token.prefix}") + private val TOKEN_PREFIX: String? = null + + @GetMapping("/login") + fun login(model: Model): String { + model.addAttribute("loginRequest", LoginRequest("", "")) + return "auth/login" + } + + @PostMapping("/login") + fun loginPost( + loginRequest: LoginRequest?, + response: HttpServletResponse + ): String { + // 로그인 + val token = authService.login(loginRequest).token + val encodedToken = URLEncoder.encode(TOKEN_PREFIX + token, StandardCharsets.UTF_8) + + // 쿠키에 토큰 저장 + val cookie = Cookie(AUTHORIZATION_HEADER, encodedToken) + cookie.path = "/" + response.addCookie(cookie) + + // 홈 화면으로 리다이렉트 + return "redirect:/" + } + + @GetMapping("/agreement") + fun agreement(): String { + return "auth/agreement" + } + + @GetMapping("/signup") + fun signup(model: Model): String { + model.addAttribute("signUpRequest", SignUpRequest("", "", "", "")) + return "auth/signup" + } + + /** + * 회원가입 처리 + * + * @param email 이메일 + * @param password 비밀번호 + * @param name 이름 + * @param + * @return 홈 화면 + */ + @PostMapping("/signup") + fun signupPost( + signUpRequest: SignUpRequest, + response: HttpServletResponse + ): String { + // 회원가입 후 자동 로그인 + // 쿠키 저장 시 토큰을 URL 인코딩(URLEncoder.encode)하여 저장 + val token = authService.signUp(signUpRequest).token + val encodedToken = URLEncoder.encode(TOKEN_PREFIX + token, StandardCharsets.UTF_8) + val cookie = Cookie(AUTHORIZATION_HEADER, encodedToken) + cookie.maxAge = 60 * 30 // 30분 + cookie.path = "/" + response.addCookie(cookie) + + return "redirect:/" + } + + @GetMapping("/logout") + fun logout( + @CookieValue(value = "Authorization", defaultValue = "", required = false) jwtCookie: Cookie, + httpServletResponse: HttpServletResponse + ): String { + // 쿠키 삭제 + jwtCookie.maxAge = 0 + jwtCookie.path = "/" + jwtCookie.value = null + httpServletResponse.addCookie(jwtCookie) + return "redirect:/" + } + + @GetMapping("/find-id") + fun requestIdSearchPage(): String { + return "auth/find-id" + } + + @PostMapping("/find-id") + fun idSearch(@RequestParam("phone") phone: String?, model: Model): String { + model.addAttribute("email", authService.findEmailByPhone(phone)) + return "auth/found-id" + } + +} diff --git a/src/main/java/ac/kr/deu/connect/luck/common/Checker.java b/src/main/java/ac/kr/deu/connect/luck/common/Checker.java index 52e6c99..78521d3 100644 --- a/src/main/java/ac/kr/deu/connect/luck/common/Checker.java +++ b/src/main/java/ac/kr/deu/connect/luck/common/Checker.java @@ -9,6 +9,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; + @Slf4j @Component @RequiredArgsConstructor diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuController.java index cff5d38..3143820 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckMenuController.java @@ -1,9 +1,45 @@ package ac.kr.deu.connect.luck.food_truck.controller; +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckMenuRequest; +import ac.kr.deu.connect.luck.food_truck.service.FoodTruckMenuService; +import lombok.RequiredArgsConstructor; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import java.security.Principal; + @Controller @RequestMapping("/food-truck/menu") +@RequiredArgsConstructor public class FoodTruckMenuController { + + private final FoodTruckMenuService foodTruckMenuService; + + @GetMapping("/{truckId}") + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER') and @checker.isFoodTruckManager(#truckId)") + public String getFoodTruckMenuDetail( + @PathVariable(value = "truckId") Long truckId, Model model + ) { + model.addAttribute("foodTruckMenus", foodTruckMenuService.getFoodTruckMenus(truckId)); + model.addAttribute("foodTruckId", truckId); + model.addAttribute("foodTruckMenuRequest", new FoodTruckMenuRequest("", 0, "", null)); + return "food_truck/manager/food_truck_manage_menu"; + } + + @PostMapping(value = "/{truckId}/add", consumes = "multipart/form-data") + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER') and @checker.isFoodTruckManager(#truckId)") + public String addFoodTruckMenu( + @PathVariable(value = "truckId") Long truckId, + FoodTruckMenuRequest foodTruckMenuRequest, + Model model, Principal principal + ) { + foodTruckMenuService.createFoodTruckMenu(truckId, principal.getName(), foodTruckMenuRequest); + model.addAttribute("foodTruckId", truckId); + return "redirect:/food-truck/menu/" + truckId; + } } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckMenuRequest.kt b/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckMenuRequest.kt new file mode 100644 index 0000000..c28a745 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckMenuRequest.kt @@ -0,0 +1,10 @@ +package ac.kr.deu.connect.luck.food_truck.dto + +import org.springframework.web.multipart.MultipartFile + +data class FoodTruckMenuRequest( + val name: String, + val price: Int, + val description: String, + val image: MultipartFile? +) diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java index 944539b..ca6ddbe 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java @@ -3,6 +3,7 @@ import ac.kr.deu.connect.luck.exception.CustomErrorCode; import ac.kr.deu.connect.luck.exception.CustomException; import ac.kr.deu.connect.luck.food_truck.FoodTruckMapper; +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckMenuRequest; import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckMenuResponse; import ac.kr.deu.connect.luck.food_truck.entity.FoodTruck; import ac.kr.deu.connect.luck.food_truck.entity.FoodTruckMenu; @@ -68,6 +69,25 @@ public FoodTruckMenu saveFoodTruckMenu(Long foodTruckId, String userEmail, Strin return foodTruckMenuRepository.save(foodTruckMenu); } + public FoodTruckMenu createFoodTruckMenu(Long foodTruckId, String userEmail, FoodTruckMenuRequest foodTruckMenuRequest){ + FoodTruck foodTruck = foodTruckRepository.findById(foodTruckId).orElseThrow(); + + String imageUrl = "https://picsum.photos/1600/900"; + if (!foodTruckMenuRequest.getImage().isEmpty()){ + imageUrl = imageUploader.uploadImage(foodTruckMenuRequest.getImage()).getData().getImage().getUrl(); + } + + FoodTruckMenu foodTruckMenu = FoodTruckMenu.builder() + .name(foodTruckMenuRequest.getName()) + .description(foodTruckMenuRequest.getDescription()) + .price(foodTruckMenuRequest.getPrice()) + .foodTruck(foodTruck) + .imageUrl(imageUrl) + .build(); + + return foodTruckMenuRepository.save(foodTruckMenu); + } + public FoodTruckMenu updateFoodTruckMenu(Long foodTruckId, Long foodTruckMenuId, String userEmail, String name, String description, int price, MultipartFile multipartFile) { FoodTruck foodTruck = foodTruckRepository.findById(foodTruckId).orElseThrow(); FoodTruckMenu foodTruckMenu = foodTruckMenuRepository.findById(foodTruckMenuId).orElseThrow(); diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserController.java b/src/main/java/ac/kr/deu/connect/luck/user/UserController.java index a076a05..f6ec4b3 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserController.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserController.java @@ -3,6 +3,7 @@ import ac.kr.deu.connect.luck.auth.SignUpRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -17,6 +18,7 @@ public class UserController { private final UserService userService; @GetMapping + @PreAuthorize("isAuthenticated()") public String gerUserInfo(Principal principal, Model model) { model.addAttribute("userInfo", userService.findUserInfo(principal.getName())); return "user/profile"; @@ -64,6 +66,7 @@ public String addRole( ) { userService.setUserRole(principal.getName(), role); return "redirect:/user"; + } diff --git a/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html b/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html new file mode 100644 index 0000000..32ec7fb --- /dev/null +++ b/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html @@ -0,0 +1,78 @@ + + + + +

메뉴 관리

+
+
+ +
+
+
+
+ Food Truck Menu Image +
+
+

+

+ + + + +
+
+
+
+
+ + + +
+ From fd43fbcb9231c9586af5657c946544151af6d2c8 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Tue, 14 May 2024 01:09:27 +0900 Subject: [PATCH 09/15] Fix: Add kotlin plugin spring --- build.gradle | 1 + .../java/ac/kr/deu/connect/luck/auth/AuthController.kt | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 7e59785..7c10a51 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { id 'org.springframework.boot' version '3.2.3' id 'io.spring.dependency-management' version '1.1.4' id 'org.jetbrains.kotlin.jvm' + id 'org.jetbrains.kotlin.plugin.spring' version '1.9.23' } group = 'ac.kr.deu' diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt index 50a5f73..de200b2 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt +++ b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt @@ -3,6 +3,7 @@ package ac.kr.deu.connect.luck.auth import jakarta.servlet.http.Cookie import jakarta.servlet.http.HttpServletResponse import org.springframework.beans.factory.annotation.Value +import org.springframework.security.access.prepost.PreAuthorize import org.springframework.stereotype.Controller import org.springframework.ui.Model import org.springframework.web.bind.annotation.* @@ -12,13 +13,13 @@ import java.nio.charset.StandardCharsets @Controller @RequestMapping("/auth") class AuthController( - val authService: AuthService + private val authService: AuthService ) { @Value("\${security.jwt.token.header}") - private val AUTHORIZATION_HEADER: String? = null + lateinit var AUTHORIZATION_HEADER: String @Value("\${security.jwt.token.prefix}") - private val TOKEN_PREFIX: String? = null + lateinit var TOKEN_PREFIX: String @GetMapping("/login") fun login(model: Model): String { @@ -82,6 +83,7 @@ class AuthController( } @GetMapping("/logout") + @PreAuthorize("isAuthenticated()") fun logout( @CookieValue(value = "Authorization", defaultValue = "", required = false) jwtCookie: Cookie, httpServletResponse: HttpServletResponse From 79e8fbd3be24400ac8b6b17d8543b914248f9bd5 Mon Sep 17 00:00:00 2001 From: Namju Kim Date: Tue, 14 May 2024 10:58:55 +0900 Subject: [PATCH 10/15] =?UTF-8?q?FIx:=20=ED=91=B8=EB=93=9C=ED=8A=B8?= =?UTF-8?q?=EB=9F=AD=20=EB=93=B1=EB=A1=9D=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/MapStructMapperImpl.java | 124 +++++++++--------- .../deu/connect/luck/auth/AuthController.kt | 2 + .../connect/luck/auth/AuthRestController.java | 4 +- .../kr/deu/connect/luck/auth/AuthService.java | 4 +- .../luck/{ => auth}/dto/EmailResponse.java | 2 +- .../luck/{ => auth}/dto/IdCheckResponse.java | 2 +- .../luck/auth/{ => dto}/LoginRequest.java | 2 +- .../luck/auth/{ => dto}/SignUpRequest.java | 2 +- .../connect/luck/auth/dto/TokenResponse.kt | 9 ++ .../deu/connect/luck/dto/TokenResponse.java | 6 - .../luck/food_truck/FoodTruckMapper.java | 3 +- .../controller/FoodTruckController.java | 3 +- .../controller/FoodTruckRestController.java | 84 ------------ .../controller/FoodTruckRestController.kt | 94 +++++++++++++ .../luck/food_truck/dto/FoodTruckRequestV2.kt | 15 +++ .../service/FoodTruckMenuService.java | 4 +- .../food_truck/service/FoodTruckService.java | 14 +- .../deu/connect/luck/image/ImageUploader.java | 8 +- .../deu/connect/luck/user/UserController.java | 2 +- .../kr/deu/connect/luck/user/UserMapper.java | 4 +- .../connect/luck/user/UserRestController.java | 2 +- .../kr/deu/connect/luck/user/UserService.java | 2 +- .../food_truck/food_truck_detail.html | 2 +- .../food_truck/manager/food_truck_edit.html | 3 +- .../manager/food_truck_manage_menu.html | 20 +-- .../resources/templates/fragments/header.html | 2 +- .../templates/fragments/nav-bar.html | 2 +- src/main/resources/templates/index.html | 4 +- src/main/resources/templates/now/now-map.html | 2 +- .../resources/templates/user/add_role.html | 8 +- .../templates/user/profile_edit.html | 12 +- .../kr/deu/connect/luck/ApplicationTests.java | 6 +- 32 files changed, 244 insertions(+), 209 deletions(-) rename src/main/java/ac/kr/deu/connect/luck/{ => auth}/dto/EmailResponse.java (58%) rename src/main/java/ac/kr/deu/connect/luck/{ => auth}/dto/IdCheckResponse.java (61%) rename src/main/java/ac/kr/deu/connect/luck/auth/{ => dto}/LoginRequest.java (88%) rename src/main/java/ac/kr/deu/connect/luck/auth/{ => dto}/SignUpRequest.java (92%) create mode 100644 src/main/java/ac/kr/deu/connect/luck/auth/dto/TokenResponse.kt delete mode 100644 src/main/java/ac/kr/deu/connect/luck/dto/TokenResponse.java delete mode 100644 src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java create mode 100644 src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.kt create mode 100644 src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckRequestV2.kt diff --git a/src/main/generated/ac/kr/deu/connect/luck/configuration/MapStructMapperImpl.java b/src/main/generated/ac/kr/deu/connect/luck/configuration/MapStructMapperImpl.java index 6b22eb7..d2153f5 100644 --- a/src/main/generated/ac/kr/deu/connect/luck/configuration/MapStructMapperImpl.java +++ b/src/main/generated/ac/kr/deu/connect/luck/configuration/MapStructMapperImpl.java @@ -15,89 +15,91 @@ import ac.kr.deu.connect.luck.food_truck.FoodTruckReviewResponse; import ac.kr.deu.connect.luck.food_truck.FoodType; import ac.kr.deu.connect.luck.user.User; + import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import javax.annotation.processing.Generated; + import org.springframework.stereotype.Component; @Generated( - value = "org.mapstruct.ap.MappingProcessor", - date = "2024-04-16T02:14:38+0900", - comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.10 (Oracle Corporation)" + value = "org.mapstruct.ap.MappingProcessor", + date = "2024-04-16T02:14:38+0900", + comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.10 (Oracle Corporation)" ) @Component public class MapStructMapperImpl implements MapStructMapper { @Override public User toUser(SignUpRequest signUpRequest) { - if ( signUpRequest == null ) { + if (signUpRequest == null) { return null; } User.UserBuilder user = User.builder(); - user.email( signUpRequest.email() ); - user.password( signUpRequest.password() ); - user.name( signUpRequest.name() ); + user.email(signUpRequest.email()); + user.password(signUpRequest.password()); + user.name(signUpRequest.name()); return user.build(); } @Override public User toUser(LoginRequest loginRequest) { - if ( loginRequest == null ) { + if (loginRequest == null) { return null; } User.UserBuilder user = User.builder(); - user.email( loginRequest.email() ); - user.password( loginRequest.password() ); + user.email(loginRequest.email()); + user.password(loginRequest.password()); return user.build(); } @Override public Event toEvent(EventRequest eventRequest) { - if ( eventRequest == null ) { + if (eventRequest == null) { return null; } Event.EventBuilder event = Event.builder(); - event.manager( eventRequestToUser( eventRequest ) ); - event.title( eventRequest.title() ); - event.content( eventRequest.content() ); - event.zipCode( eventRequest.zipCode() ); - event.streetAddress( eventRequest.streetAddress() ); - event.detailAddress( eventRequest.detailAddress() ); - event.startAt( eventRequest.startAt() ); - event.endAt( eventRequest.endAt() ); - event.imageUrl( eventRequest.imageUrl() ); + event.manager(eventRequestToUser(eventRequest)); + event.title(eventRequest.title()); + event.content(eventRequest.content()); + event.zipCode(eventRequest.zipCode()); + event.streetAddress(eventRequest.streetAddress()); + event.detailAddress(eventRequest.detailAddress()); + event.startAt(eventRequest.startAt()); + event.endAt(eventRequest.endAt()); + event.imageUrl(eventRequest.imageUrl()); return event.build(); } @Override public FoodTruck toFoodTruck(FoodTruckRequest foodTruckRequest) { - if ( foodTruckRequest == null ) { + if (foodTruckRequest == null) { return null; } FoodTruck.FoodTruckBuilder foodTruck = FoodTruck.builder(); - foodTruck.name( foodTruckRequest.name() ); - foodTruck.description( foodTruckRequest.description() ); - foodTruck.imageUrl( foodTruckRequest.imageUrl() ); - foodTruck.foodType( foodTruckRequest.foodType() ); + foodTruck.name(foodTruckRequest.name()); + foodTruck.description(foodTruckRequest.description()); + foodTruck.imageUrl(foodTruckRequest.imageUrl()); + foodTruck.foodType(foodTruckRequest.foodType()); return foodTruck.build(); } @Override public FoodTruckDetailResponse toFoodTruckDetailResponse(FoodTruck foodTruck, List reviews, List menus) { - if ( foodTruck == null && reviews == null && menus == null ) { + if (foodTruck == null && reviews == null && menus == null) { return null; } @@ -107,7 +109,7 @@ public FoodTruckDetailResponse toFoodTruckDetailResponse(FoodTruck foodTruck, Li String imageUrl = null; FoodType foodType = null; User manager = null; - if ( foodTruck != null ) { + if (foodTruck != null) { id = foodTruck.getId(); name = foodTruck.getName(); description = foodTruck.getDescription(); @@ -116,18 +118,18 @@ public FoodTruckDetailResponse toFoodTruckDetailResponse(FoodTruck foodTruck, Li manager = foodTruck.getManager(); } List reviews1 = null; - reviews1 = foodTruckReviewListToFoodTruckReviewResponseList( reviews ); + reviews1 = foodTruckReviewListToFoodTruckReviewResponseList(reviews); List menus1 = null; - menus1 = foodTruckMenuListToFoodTruckMenuResponseList( menus ); + menus1 = foodTruckMenuListToFoodTruckMenuResponseList(menus); - FoodTruckDetailResponse foodTruckDetailResponse = new FoodTruckDetailResponse( id, name, description, imageUrl, foodType, manager, reviews1, menus1 ); + FoodTruckDetailResponse foodTruckDetailResponse = new FoodTruckDetailResponse(id, name, description, imageUrl, foodType, manager, reviews1, menus1); return foodTruckDetailResponse; } @Override public FoodTruckRequest toFoodTruckRequest(FoodTruck foodTruck) { - if ( foodTruck == null ) { + if (foodTruck == null) { return null; } @@ -141,58 +143,58 @@ public FoodTruckRequest toFoodTruckRequest(FoodTruck foodTruck) { imageUrl = foodTruck.getImageUrl(); foodType = foodTruck.getFoodType(); - FoodTruckRequest foodTruckRequest = new FoodTruckRequest( name, description, imageUrl, foodType ); + FoodTruckRequest foodTruckRequest = new FoodTruckRequest(name, description, imageUrl, foodType); return foodTruckRequest; } @Override public FoodTruckMenu toFoodTruckMenu(FoodTruckMenuRequest foodTruckMenuRequest) { - if ( foodTruckMenuRequest == null ) { + if (foodTruckMenuRequest == null) { return null; } FoodTruckMenu.FoodTruckMenuBuilder foodTruckMenu = FoodTruckMenu.builder(); - foodTruckMenu.name( foodTruckMenuRequest.name() ); - foodTruckMenu.description( foodTruckMenuRequest.description() ); - foodTruckMenu.imageUrl( foodTruckMenuRequest.imageUrl() ); - foodTruckMenu.price( foodTruckMenuRequest.price() ); + foodTruckMenu.name(foodTruckMenuRequest.name()); + foodTruckMenu.description(foodTruckMenuRequest.description()); + foodTruckMenu.imageUrl(foodTruckMenuRequest.imageUrl()); + foodTruckMenu.price(foodTruckMenuRequest.price()); return foodTruckMenu.build(); } @Override public FoodTruckReview toReview(FoodTruckReviewRequest foodTruckReviewRequest) { - if ( foodTruckReviewRequest == null ) { + if (foodTruckReviewRequest == null) { return null; } FoodTruckReview.FoodTruckReviewBuilder foodTruckReview = FoodTruckReview.builder(); - foodTruckReview.foodTruck( foodTruckReviewRequestToFoodTruck( foodTruckReviewRequest ) ); - foodTruckReview.author( foodTruckReviewRequestToUser( foodTruckReviewRequest ) ); - foodTruckReview.content( foodTruckReviewRequest.content() ); - foodTruckReview.score( foodTruckReviewRequest.score() ); - foodTruckReview.imageUrl( foodTruckReviewRequest.imageUrl() ); + foodTruckReview.foodTruck(foodTruckReviewRequestToFoodTruck(foodTruckReviewRequest)); + foodTruckReview.author(foodTruckReviewRequestToUser(foodTruckReviewRequest)); + foodTruckReview.content(foodTruckReviewRequest.content()); + foodTruckReview.score(foodTruckReviewRequest.score()); + foodTruckReview.imageUrl(foodTruckReviewRequest.imageUrl()); return foodTruckReview.build(); } protected User eventRequestToUser(EventRequest eventRequest) { - if ( eventRequest == null ) { + if (eventRequest == null) { return null; } User.UserBuilder user = User.builder(); - user.id( eventRequest.managerId() ); + user.id(eventRequest.managerId()); return user.build(); } protected FoodTruckReviewResponse foodTruckReviewToFoodTruckReviewResponse(FoodTruckReview foodTruckReview) { - if ( foodTruckReview == null ) { + if (foodTruckReview == null) { return null; } @@ -213,26 +215,26 @@ protected FoodTruckReviewResponse foodTruckReviewToFoodTruckReviewResponse(FoodT String foodTruckName = null; String authorName = null; - FoodTruckReviewResponse foodTruckReviewResponse = new FoodTruckReviewResponse( id, content, imageUrl, score, foodTruckName, authorName, createdAt, updatedAt ); + FoodTruckReviewResponse foodTruckReviewResponse = new FoodTruckReviewResponse(id, content, imageUrl, score, foodTruckName, authorName, createdAt, updatedAt); return foodTruckReviewResponse; } protected List foodTruckReviewListToFoodTruckReviewResponseList(List list) { - if ( list == null ) { + if (list == null) { return null; } - List list1 = new ArrayList( list.size() ); - for ( FoodTruckReview foodTruckReview : list ) { - list1.add( foodTruckReviewToFoodTruckReviewResponse( foodTruckReview ) ); + List list1 = new ArrayList(list.size()); + for (FoodTruckReview foodTruckReview : list) { + list1.add(foodTruckReviewToFoodTruckReviewResponse(foodTruckReview)); } return list1; } protected FoodTruckMenuResponse foodTruckMenuToFoodTruckMenuResponse(FoodTruckMenu foodTruckMenu) { - if ( foodTruckMenu == null ) { + if (foodTruckMenu == null) { return null; } @@ -254,44 +256,44 @@ protected FoodTruckMenuResponse foodTruckMenuToFoodTruckMenuResponse(FoodTruckMe String foodTruckName = null; - FoodTruckMenuResponse foodTruckMenuResponse = new FoodTruckMenuResponse( id, name, description, imageUrl, price, foodTruckName, createdAt, updatedAt ); + FoodTruckMenuResponse foodTruckMenuResponse = new FoodTruckMenuResponse(id, name, description, imageUrl, price, foodTruckName, createdAt, updatedAt); return foodTruckMenuResponse; } protected List foodTruckMenuListToFoodTruckMenuResponseList(List list) { - if ( list == null ) { + if (list == null) { return null; } - List list1 = new ArrayList( list.size() ); - for ( FoodTruckMenu foodTruckMenu : list ) { - list1.add( foodTruckMenuToFoodTruckMenuResponse( foodTruckMenu ) ); + List list1 = new ArrayList(list.size()); + for (FoodTruckMenu foodTruckMenu : list) { + list1.add(foodTruckMenuToFoodTruckMenuResponse(foodTruckMenu)); } return list1; } protected FoodTruck foodTruckReviewRequestToFoodTruck(FoodTruckReviewRequest foodTruckReviewRequest) { - if ( foodTruckReviewRequest == null ) { + if (foodTruckReviewRequest == null) { return null; } FoodTruck.FoodTruckBuilder foodTruck = FoodTruck.builder(); - foodTruck.id( foodTruckReviewRequest.foodTruckId() ); + foodTruck.id(foodTruckReviewRequest.foodTruckId()); return foodTruck.build(); } protected User foodTruckReviewRequestToUser(FoodTruckReviewRequest foodTruckReviewRequest) { - if ( foodTruckReviewRequest == null ) { + if (foodTruckReviewRequest == null) { return null; } User.UserBuilder user = User.builder(); - user.id( foodTruckReviewRequest.authorId() ); + user.id(foodTruckReviewRequest.authorId()); return user.build(); } diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt index de200b2..e4d65ee 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt +++ b/src/main/java/ac/kr/deu/connect/luck/auth/AuthController.kt @@ -1,5 +1,7 @@ package ac.kr.deu.connect.luck.auth +import ac.kr.deu.connect.luck.auth.dto.LoginRequest +import ac.kr.deu.connect.luck.auth.dto.SignUpRequest import jakarta.servlet.http.Cookie import jakarta.servlet.http.HttpServletResponse import org.springframework.beans.factory.annotation.Value diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthRestController.java b/src/main/java/ac/kr/deu/connect/luck/auth/AuthRestController.java index 48b40fb..0740992 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/AuthRestController.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/AuthRestController.java @@ -1,8 +1,6 @@ package ac.kr.deu.connect.luck.auth; -import ac.kr.deu.connect.luck.dto.EmailResponse; -import ac.kr.deu.connect.luck.dto.IdCheckResponse; -import ac.kr.deu.connect.luck.dto.TokenResponse; +import ac.kr.deu.connect.luck.auth.dto.*; import ac.kr.deu.connect.luck.exception.CustomErrorResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/AuthService.java b/src/main/java/ac/kr/deu/connect/luck/auth/AuthService.java index b99213c..2469446 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/AuthService.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/AuthService.java @@ -1,8 +1,6 @@ package ac.kr.deu.connect.luck.auth; -import ac.kr.deu.connect.luck.dto.EmailResponse; -import ac.kr.deu.connect.luck.dto.IdCheckResponse; -import ac.kr.deu.connect.luck.dto.TokenResponse; +import ac.kr.deu.connect.luck.auth.dto.*; import ac.kr.deu.connect.luck.exception.CustomErrorCode; import ac.kr.deu.connect.luck.exception.CustomException; import ac.kr.deu.connect.luck.security.JwtTokenProvider; diff --git a/src/main/java/ac/kr/deu/connect/luck/dto/EmailResponse.java b/src/main/java/ac/kr/deu/connect/luck/auth/dto/EmailResponse.java similarity index 58% rename from src/main/java/ac/kr/deu/connect/luck/dto/EmailResponse.java rename to src/main/java/ac/kr/deu/connect/luck/auth/dto/EmailResponse.java index 6321378..bf0301a 100644 --- a/src/main/java/ac/kr/deu/connect/luck/dto/EmailResponse.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/dto/EmailResponse.java @@ -1,4 +1,4 @@ -package ac.kr.deu.connect.luck.dto; +package ac.kr.deu.connect.luck.auth.dto; public record EmailResponse( String email diff --git a/src/main/java/ac/kr/deu/connect/luck/dto/IdCheckResponse.java b/src/main/java/ac/kr/deu/connect/luck/auth/dto/IdCheckResponse.java similarity index 61% rename from src/main/java/ac/kr/deu/connect/luck/dto/IdCheckResponse.java rename to src/main/java/ac/kr/deu/connect/luck/auth/dto/IdCheckResponse.java index 5ecfcbf..ffb9a3c 100644 --- a/src/main/java/ac/kr/deu/connect/luck/dto/IdCheckResponse.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/dto/IdCheckResponse.java @@ -1,4 +1,4 @@ -package ac.kr.deu.connect.luck.dto; +package ac.kr.deu.connect.luck.auth.dto; public record IdCheckResponse( boolean isAvailable diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/LoginRequest.java b/src/main/java/ac/kr/deu/connect/luck/auth/dto/LoginRequest.java similarity index 88% rename from src/main/java/ac/kr/deu/connect/luck/auth/LoginRequest.java rename to src/main/java/ac/kr/deu/connect/luck/auth/dto/LoginRequest.java index 0c77bd4..838f4b5 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/LoginRequest.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/dto/LoginRequest.java @@ -1,4 +1,4 @@ -package ac.kr.deu.connect.luck.auth; +package ac.kr.deu.connect.luck.auth.dto; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/SignUpRequest.java b/src/main/java/ac/kr/deu/connect/luck/auth/dto/SignUpRequest.java similarity index 92% rename from src/main/java/ac/kr/deu/connect/luck/auth/SignUpRequest.java rename to src/main/java/ac/kr/deu/connect/luck/auth/dto/SignUpRequest.java index 8ca6432..3b3d699 100644 --- a/src/main/java/ac/kr/deu/connect/luck/auth/SignUpRequest.java +++ b/src/main/java/ac/kr/deu/connect/luck/auth/dto/SignUpRequest.java @@ -1,4 +1,4 @@ -package ac.kr.deu.connect.luck.auth; +package ac.kr.deu.connect.luck.auth.dto; import io.swagger.v3.oas.annotations.media.Schema; diff --git a/src/main/java/ac/kr/deu/connect/luck/auth/dto/TokenResponse.kt b/src/main/java/ac/kr/deu/connect/luck/auth/dto/TokenResponse.kt new file mode 100644 index 0000000..e1cc554 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/auth/dto/TokenResponse.kt @@ -0,0 +1,9 @@ +package ac.kr.deu.connect.luck.auth.dto + +class TokenResponse( + val token: String +) { + override fun toString(): String { + return "TokenResponse(token='$token')" + } +} diff --git a/src/main/java/ac/kr/deu/connect/luck/dto/TokenResponse.java b/src/main/java/ac/kr/deu/connect/luck/dto/TokenResponse.java deleted file mode 100644 index 570eec4..0000000 --- a/src/main/java/ac/kr/deu/connect/luck/dto/TokenResponse.java +++ /dev/null @@ -1,6 +0,0 @@ -package ac.kr.deu.connect.luck.dto; - -public record TokenResponse( - String token -) { -} diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java index d899d04..3508526 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/FoodTruckMapper.java @@ -17,7 +17,8 @@ public interface FoodTruckMapper { * @param foodTruckRequest 푸드트럭 생성 요청 DTO * @return 푸드트럭 엔티티 */ - FoodTruck toFoodTruck(FoodTruckRequest foodTruckRequest); + @Mapping(target = "imageUrl", constant = "imageUrl") + FoodTruck toFoodTruck(FoodTruckRequestV2 foodTruckRequest); /** * 푸드트럭 엔티티를 푸드트럭 상세 응답 DTO로 변환합니다. diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java index ae29f08..a2622b5 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckController.java @@ -1,6 +1,7 @@ package ac.kr.deu.connect.luck.food_truck.controller; import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequest; +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequestV2; import ac.kr.deu.connect.luck.food_truck.entity.FoodType; import ac.kr.deu.connect.luck.food_truck.service.FoodTruckService; import lombok.RequiredArgsConstructor; @@ -98,7 +99,7 @@ public String registerFoodTruckPost( MultipartFile image ) { FoodType type = FoodType.valueOf(foodType); - FoodTruckRequest foodTruckRequest = new FoodTruckRequest(name, description, type); + FoodTruckRequestV2 foodTruckRequest = new FoodTruckRequestV2(name, description, image, type); foodTruckService.createFoodTruck(principal.getName(), foodTruckRequest); return "redirect:/food-truck/my"; } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java deleted file mode 100644 index 6823eef..0000000 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.java +++ /dev/null @@ -1,84 +0,0 @@ -package ac.kr.deu.connect.luck.food_truck.controller; - -import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckDetailResponse; -import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckHeader; -import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequest; -import ac.kr.deu.connect.luck.food_truck.entity.FoodTruck; -import ac.kr.deu.connect.luck.food_truck.entity.FoodType; -import ac.kr.deu.connect.luck.food_truck.service.FoodTruckService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.http.MediaType; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.security.Principal; -import java.util.List; - -@Tag(name = "03-Food Truck", description = "Food Truck API") -@RestController -@RequestMapping("/api/food-truck") -@RequiredArgsConstructor -public class FoodTruckRestController { - private final FoodTruckService foodTruckService; - - @GetMapping - @Operation(summary = "푸드 트럭 검색", description = "푸드트럭을 검색합니다.") - public ResponseEntity> getFoodTrucks( - @Parameter(description = "상호명") @RequestParam(name = "name", required = false) String name, - @Parameter(description = "음식 종류") @RequestParam(name = "foodType", required = false) FoodType foodType - ) { - return ResponseEntity.ok(foodTruckService.getFoodTrucks(name, foodType)); - } - - @GetMapping("/{id}") - @Operation(summary = "푸드트럭 정보를 조회합니다.") - public ResponseEntity getFoodTruck( - @Parameter(description = "푸드트럭 UID") @PathVariable("id") Long id) { - return ResponseEntity.ok(foodTruckService.getFoodTruck(id)); - } - - @PostMapping - @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") - @Operation(summary = "푸드트럭 등록", description = "

신규 푸드트럭을 등록합니다.

푸드트럭 관리자만 가능합니다.

이후 추가해야 하는 일

  • 푸드트럭 메뉴 등록
  • 푸드트럭 Now API를 통한 영업 위치 등록(등록 후 바로 삭제)
  • 대표이미지 변경(아래 {id}/update-image API 활용
") - public ResponseEntity createFoodTruck( - @RequestBody FoodTruckRequest foodTruckRequest, - Principal principal) { - return ResponseEntity.ok(foodTruckService.createFoodTruck(principal.getName(), foodTruckRequest)); - } - - - @PatchMapping("/{id}") - @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER') and @checker.isFoodTruckManager(#truckId)") - @Operation(summary = "푸드트럭 정보를 업데이트 합니다.", description = "푸드트럭 정보를 업데이트 합니다. 푸드트럭 관리자만 가능합니다.
푸드트럭의 대표 이미지를 변경하려면 /{id}/update-image API를 활용하십시오.") - public ResponseEntity updateFoodTruck( - @Parameter(description = "푸드트럭 UID") @PathVariable("id") Long truckId, - @RequestBody FoodTruckRequest foodTruckRequest, - Principal principal) { - return ResponseEntity.ok(foodTruckService.updateFoodTruck(truckId, principal.getName(), foodTruckRequest)); - } - - @PostMapping(value = "/{id}/update-image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") - @Operation(summary = "푸드트럭의 대표 이미지를 변경합니다.", description = "Image를 업로드하여 푸드트럭의 대표 이미지를 변경합니다.") - public ResponseEntity updateFoodTruckImage( - @Parameter(description = "푸드트럭 UID") @PathVariable("id") Long truckId, - @Parameter(description = "변경할 이미지") @RequestPart("image") MultipartFile multipartFile, - Principal principal) { - return ResponseEntity.ok(foodTruckService.updateFoodTruckImage(truckId, principal.getName(), multipartFile)); - } - - @DeleteMapping("/{id}") - @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") - @Operation(summary = "푸드트럭 정보 삭제", description = "

푸드트럭 정보를 삭제합니다.

삭제 되는 정보

  1. 푸드트럭 정보
  2. 푸드트럭 메뉴
  3. 푸드트럭 리뷰
") - public ResponseEntity deleteFoodTruck( - Principal principal, - @PathVariable Long id) { - return ResponseEntity.ok(foodTruckService.deleteFoodTruck(id, principal.getName())); - } -} - diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.kt b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.kt new file mode 100644 index 0000000..5ea5701 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/controller/FoodTruckRestController.kt @@ -0,0 +1,94 @@ +package ac.kr.deu.connect.luck.food_truck.controller + +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckDetailResponse +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckHeader +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequest +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequestV2 +import ac.kr.deu.connect.luck.food_truck.entity.FoodTruck +import ac.kr.deu.connect.luck.food_truck.entity.FoodType +import ac.kr.deu.connect.luck.food_truck.service.FoodTruckService +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.Parameter +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.security.access.prepost.PreAuthorize +import org.springframework.web.bind.annotation.* +import org.springframework.web.multipart.MultipartFile +import java.security.Principal + +@Tag(name = "03-Food Truck", description = "Food Truck API") +@RestController +@RequestMapping("/api/food-truck") +class FoodTruckRestController( + val foodTruckService: FoodTruckService +) { + @GetMapping + @Operation(summary = "푸드 트럭 검색", description = "푸드트럭을 검색합니다.") + fun getFoodTrucks( + @Parameter(description = "상호명") @RequestParam(name = "name", required = false) name: String?, + @Parameter(description = "음식 종류") @RequestParam(name = "foodType", required = false) foodType: FoodType? + ): ResponseEntity> { + return ResponseEntity.ok(foodTruckService.getFoodTrucks(name, foodType)) + } + + @GetMapping("/{id}") + @Operation(summary = "푸드트럭 정보를 조회합니다.") + fun getFoodTruck( + @Parameter(description = "푸드트럭 UID") @PathVariable("id") id: Long + ): ResponseEntity { + return ResponseEntity.ok(foodTruckService.getFoodTruck(id)) + } + + @PostMapping(consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") + @Operation( + summary = "푸드트럭 등록", + description = "

신규 푸드트럭을 등록합니다.

푸드트럭 관리자만 가능합니다.

주의사항

  • name, description, foodType은 필수 항목입니다.
  • 이미지를 입력하지 않을 경우 기본 이미지가 등록됩니다.
  • 이미지를 비워둘 경우 Send Empty value를 체크 해재해주세요
    빈 값 전송시 에러가 발생합니다.

모두 Body의 Form Data로 전달해야 합니다." + ) + fun createFoodTruck( + @ModelAttribute foodTruckRequestV2: FoodTruckRequestV2, + principal: Principal + ): ResponseEntity { + return ResponseEntity.ok(foodTruckService.createFoodTruck(principal.name, foodTruckRequestV2)) + } + + + @PatchMapping("/{id}") + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER') and @checker.isFoodTruckManager(#truckId)") + @Operation( + summary = "푸드트럭 정보를 업데이트 합니다.", + description = "푸드트럭 정보를 업데이트 합니다. 푸드트럭 관리자만 가능합니다.
푸드트럭의 대표 이미지를 변경하려면 /{id}/update-image API를 활용하십시오." + ) + fun updateFoodTruck( + @Parameter(description = "푸드트럭 UID") @PathVariable("id") truckId: Long?, + @RequestBody foodTruckRequest: FoodTruckRequest?, + principal: Principal + ): ResponseEntity { + return ResponseEntity.ok(foodTruckService.updateFoodTruck(truckId, principal.name, foodTruckRequest)) + } + + @PostMapping(value = ["/{id}/update-image"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") + @Operation(summary = "푸드트럭의 대표 이미지를 변경합니다.", description = "Image를 업로드하여 푸드트럭의 대표 이미지를 변경합니다.") + fun updateFoodTruckImage( + @Parameter(description = "푸드트럭 UID") @PathVariable("id") truckId: Long?, + @Parameter(description = "변경할 이미지") @RequestPart("image") multipartFile: MultipartFile?, + principal: Principal + ): ResponseEntity { + return ResponseEntity.ok(foodTruckService.updateFoodTruckImage(truckId, principal.name, multipartFile)) + } + + @DeleteMapping("/{id}") + @PreAuthorize("hasRole('ROLE_FOOD_TRUCK_MANAGER')") + @Operation( + summary = "푸드트럭 정보 삭제", + description = "

푸드트럭 정보를 삭제합니다.

삭제 되는 정보

  1. 푸드트럭 정보
  2. 푸드트럭 메뉴
  3. 푸드트럭 리뷰
" + ) + fun deleteFoodTruck( + principal: Principal, + @PathVariable id: Long? + ): ResponseEntity { + return ResponseEntity.ok(foodTruckService.deleteFoodTruck(id, principal.name)) + } +} diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckRequestV2.kt b/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckRequestV2.kt new file mode 100644 index 0000000..4744b56 --- /dev/null +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/dto/FoodTruckRequestV2.kt @@ -0,0 +1,15 @@ +package ac.kr.deu.connect.luck.food_truck.dto + +import ac.kr.deu.connect.luck.food_truck.entity.FoodType +import org.springframework.web.multipart.MultipartFile + +data class FoodTruckRequestV2( + var name: String, + var description: String, + var image: MultipartFile?, + var foodType: FoodType, +) { + override fun toString(): String { + return "FoodTruckRequestV2(name='$name', description='$description', image=$image, foodType=$foodType)" + } +} diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java index ca6ddbe..067d6a0 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckMenuService.java @@ -69,11 +69,11 @@ public FoodTruckMenu saveFoodTruckMenu(Long foodTruckId, String userEmail, Strin return foodTruckMenuRepository.save(foodTruckMenu); } - public FoodTruckMenu createFoodTruckMenu(Long foodTruckId, String userEmail, FoodTruckMenuRequest foodTruckMenuRequest){ + public FoodTruckMenu createFoodTruckMenu(Long foodTruckId, String userEmail, FoodTruckMenuRequest foodTruckMenuRequest) { FoodTruck foodTruck = foodTruckRepository.findById(foodTruckId).orElseThrow(); String imageUrl = "https://picsum.photos/1600/900"; - if (!foodTruckMenuRequest.getImage().isEmpty()){ + if (!foodTruckMenuRequest.getImage().isEmpty()) { imageUrl = imageUploader.uploadImage(foodTruckMenuRequest.getImage()).getData().getImage().getUrl(); } diff --git a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java index 11d0367..91048de 100644 --- a/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java +++ b/src/main/java/ac/kr/deu/connect/luck/food_truck/service/FoodTruckService.java @@ -6,6 +6,7 @@ import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckDetailResponse; import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckHeader; import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequest; +import ac.kr.deu.connect.luck.food_truck.dto.FoodTruckRequestV2; import ac.kr.deu.connect.luck.food_truck.entity.FoodTruck; import ac.kr.deu.connect.luck.food_truck.entity.FoodType; import ac.kr.deu.connect.luck.food_truck.repository.FoodTruckMenuRepository; @@ -14,12 +15,14 @@ import ac.kr.deu.connect.luck.image.ImageUploader; import ac.kr.deu.connect.luck.user.UserRepository; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import java.util.List; +@Slf4j @Service @RequiredArgsConstructor public class FoodTruckService { @@ -71,11 +74,16 @@ public FoodTruckDetailResponse getFoodTruck(Long id) { * @param foodTruckRequest 추가할 푸드트럭 정보 * @return 저장된 푸드트럭 정보 */ - public FoodTruck createFoodTruck(String userEmail, FoodTruckRequest foodTruckRequest) { + public FoodTruckDetailResponse createFoodTruck(String userEmail, FoodTruckRequestV2 foodTruckRequest) { FoodTruck foodTruck = foodTruckMapper.toFoodTruck(foodTruckRequest); foodTruck.setManager(userRepository.findByEmail(userEmail).orElseThrow()); - foodTruck.setImageUrl("https://picsum.photos/1600/900"); - return foodTruckRepository.save(foodTruck); + + // 이미지가 있는 경우 이미지 업로드 + if (foodTruckRequest.getImage() != null) { + foodTruck.setImageUrl(imageUploader.uploadImage(foodTruckRequest.getImage()).getData().getUrl()); + } + + return foodTruckMapper.toFoodTruckDetailResponse(foodTruckRepository.save(foodTruck)); } /** diff --git a/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java b/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java index 909a10c..88c4303 100644 --- a/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java +++ b/src/main/java/ac/kr/deu/connect/luck/image/ImageUploader.java @@ -20,15 +20,11 @@ @Slf4j public class ImageUploader { - @Value("${api-key.imgbb}") - private String API_KEY; - private final String BASE_URL = "https://api.imgbb.com/1/upload"; - private final Long EXPIRATION = 15552000L; - private final RestTemplate restTemplate = new RestTemplate(); - + @Value("${api-key.imgbb}") + private String API_KEY; public ImageUploadResponse uploadImage(MultipartFile file) { try { diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserController.java b/src/main/java/ac/kr/deu/connect/luck/user/UserController.java index f6ec4b3..4e981af 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserController.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserController.java @@ -1,6 +1,6 @@ package ac.kr.deu.connect.luck.user; -import ac.kr.deu.connect.luck.auth.SignUpRequest; +import ac.kr.deu.connect.luck.auth.dto.SignUpRequest; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserMapper.java b/src/main/java/ac/kr/deu/connect/luck/user/UserMapper.java index 8998de4..c948fa9 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserMapper.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserMapper.java @@ -1,7 +1,7 @@ package ac.kr.deu.connect.luck.user; -import ac.kr.deu.connect.luck.auth.LoginRequest; -import ac.kr.deu.connect.luck.auth.SignUpRequest; +import ac.kr.deu.connect.luck.auth.dto.LoginRequest; +import ac.kr.deu.connect.luck.auth.dto.SignUpRequest; import org.mapstruct.Mapper; @Mapper(componentModel = "spring") diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserRestController.java b/src/main/java/ac/kr/deu/connect/luck/user/UserRestController.java index 557bde6..e5284bd 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserRestController.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserRestController.java @@ -1,6 +1,6 @@ package ac.kr.deu.connect.luck.user; -import ac.kr.deu.connect.luck.auth.SignUpRequest; +import ac.kr.deu.connect.luck.auth.dto.SignUpRequest; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; diff --git a/src/main/java/ac/kr/deu/connect/luck/user/UserService.java b/src/main/java/ac/kr/deu/connect/luck/user/UserService.java index 82d0451..04f054e 100644 --- a/src/main/java/ac/kr/deu/connect/luck/user/UserService.java +++ b/src/main/java/ac/kr/deu/connect/luck/user/UserService.java @@ -1,6 +1,6 @@ package ac.kr.deu.connect.luck.user; -import ac.kr.deu.connect.luck.auth.SignUpRequest; +import ac.kr.deu.connect.luck.auth.dto.SignUpRequest; import ac.kr.deu.connect.luck.exception.CustomErrorCode; import ac.kr.deu.connect.luck.exception.CustomException; import ac.kr.deu.connect.luck.food_truck.entity.FoodTruckReview; diff --git a/src/main/resources/templates/food_truck/food_truck_detail.html b/src/main/resources/templates/food_truck/food_truck_detail.html index 507f1ae..b3b988b 100644 --- a/src/main/resources/templates/food_truck/food_truck_detail.html +++ b/src/main/resources/templates/food_truck/food_truck_detail.html @@ -31,7 +31,7 @@

메뉴

- Menu Image + Menu Image diff --git a/src/main/resources/templates/food_truck/manager/food_truck_edit.html b/src/main/resources/templates/food_truck/manager/food_truck_edit.html index 693e021..2b7f001 100644 --- a/src/main/resources/templates/food_truck/manager/food_truck_edit.html +++ b/src/main/resources/templates/food_truck/manager/food_truck_edit.html @@ -20,7 +20,8 @@

폼 수정

diff --git a/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html b/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html index 32ec7fb..0f1bd44 100644 --- a/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html +++ b/src/main/resources/templates/food_truck/manager/food_truck_manage_menu.html @@ -13,7 +13,7 @@

메뉴 관리

- +
@@ -40,35 +40,35 @@
-