diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..641012b Binary files /dev/null and b/.DS_Store differ diff --git a/src/main/java/kuit/server/common/exception/OrderException.java b/src/main/java/kuit/server/common/exception/OrderException.java new file mode 100644 index 0000000..a8f8ef6 --- /dev/null +++ b/src/main/java/kuit/server/common/exception/OrderException.java @@ -0,0 +1,19 @@ +package kuit.server.common.exception; + +import kuit.server.common.response.status.ResponseStatus; +import lombok.Getter; + +@Getter +public class OrderException extends RuntimeException { + private final ResponseStatus exceptionStatus; + + public OrderException(ResponseStatus exceptionStatus) { + super(exceptionStatus.getMessage()); + this.exceptionStatus = exceptionStatus; + } + + public OrderException(ResponseStatus exceptionStatus, String message) { + super(message); + this.exceptionStatus = exceptionStatus; + } +} \ No newline at end of file diff --git a/src/main/java/kuit/server/common/exception/StoreException.java b/src/main/java/kuit/server/common/exception/StoreException.java new file mode 100644 index 0000000..7f91a42 --- /dev/null +++ b/src/main/java/kuit/server/common/exception/StoreException.java @@ -0,0 +1,14 @@ +package kuit.server.common.exception; + +import kuit.server.common.response.status.ResponseStatus; +import lombok.Getter; + +@Getter +public class StoreException extends RuntimeException{ + private final ResponseStatus exceptionStatus; + + public StoreException(ResponseStatus exceptionStatus) { + super(exceptionStatus.getMessage()); + this.exceptionStatus = exceptionStatus; + } +} diff --git a/src/main/java/kuit/server/common/exception_handler/DatabaseExceptionControllerAdvice.java b/src/main/java/kuit/server/common/exception_handler/DatabaseExceptionControllerAdvice.java index 643bfa5..b94696e 100644 --- a/src/main/java/kuit/server/common/exception_handler/DatabaseExceptionControllerAdvice.java +++ b/src/main/java/kuit/server/common/exception_handler/DatabaseExceptionControllerAdvice.java @@ -4,12 +4,14 @@ import jakarta.annotation.Priority; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.http.HttpStatus; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import static kuit.server.common.response.status.BaseExceptionResponseStatus.BAD_DATABASE_ID_REQUEST; import static kuit.server.common.response.status.BaseExceptionResponseStatus.BAD_SQL_GRAMMAR; import static kuit.server.common.response.status.BaseExceptionResponseStatus.DATABASE_ERROR; @@ -32,4 +34,10 @@ public BaseErrorResponse handle_DataAccessException(DataAccessException e) { return new BaseErrorResponse(DATABASE_ERROR); } + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(EmptyResultDataAccessException.class) + public BaseErrorResponse handle_EmptyResultDataAccessException(EmptyResultDataAccessException e) { + log.error("[handle_EmptyResultDataAccessException]", e); + return new BaseErrorResponse(BAD_DATABASE_ID_REQUEST); + } } diff --git a/src/main/java/kuit/server/common/exception_handler/OrderExceptionControllerAdvice.java b/src/main/java/kuit/server/common/exception_handler/OrderExceptionControllerAdvice.java new file mode 100644 index 0000000..ff91999 --- /dev/null +++ b/src/main/java/kuit/server/common/exception_handler/OrderExceptionControllerAdvice.java @@ -0,0 +1,24 @@ +package kuit.server.common.exception_handler; + +import static kuit.server.common.response.status.BaseExceptionResponseStatus.ORDER_ERROR; + +import jakarta.annotation.Priority; +import kuit.server.common.exception.OrderException; +import kuit.server.common.response.BaseErrorResponse; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +@Slf4j +@Priority(0) +@RestControllerAdvice +public class OrderExceptionControllerAdvice { + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(OrderException.class) + public BaseErrorResponse handle_UserException(OrderException e) { + log.error("[handle_OrderException]", e); + return new BaseErrorResponse(ORDER_ERROR, e.getMessage()); + } +} diff --git a/src/main/java/kuit/server/common/response/status/BaseExceptionResponseStatus.java b/src/main/java/kuit/server/common/response/status/BaseExceptionResponseStatus.java index 309ca9b..cebb331 100644 --- a/src/main/java/kuit/server/common/response/status/BaseExceptionResponseStatus.java +++ b/src/main/java/kuit/server/common/response/status/BaseExceptionResponseStatus.java @@ -17,6 +17,7 @@ public enum BaseExceptionResponseStatus implements ResponseStatus { BAD_REQUEST(2000, HttpStatus.BAD_REQUEST.value(), "유효하지 않은 요청입니다."), URL_NOT_FOUND(2001, HttpStatus.BAD_REQUEST.value(), "유효하지 않은 URL 입니다."), METHOD_NOT_ALLOWED(2002, HttpStatus.METHOD_NOT_ALLOWED.value(), "해당 URL에서는 지원하지 않는 HTTP Method 입니다."), + BAD_DATABASE_ID_REQUEST(2003, HttpStatus.BAD_REQUEST.value(), "잘못된 데이터id에 대한 접근입니다."), /** * 3000: Server, Database 오류 (INTERNAL_SERVER_ERROR) @@ -42,10 +43,22 @@ public enum BaseExceptionResponseStatus implements ResponseStatus { INVALID_USER_VALUE(5000, HttpStatus.BAD_REQUEST.value(), "회원가입 요청에서 잘못된 값이 존재합니다."), DUPLICATE_EMAIL(5001, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 이메일입니다."), DUPLICATE_NICKNAME(5002, HttpStatus.BAD_REQUEST.value(), "이미 존재하는 닉네임입니다."), - USER_NOT_FOUND(4003, HttpStatus.BAD_REQUEST.value(), "존재하지 않는 회원입니다."), - PASSWORD_NO_MATCH(4004, HttpStatus.BAD_REQUEST.value(), "비밀번호가 일치하지 않습니다."), - INVALID_USER_STATUS(4005, HttpStatus.BAD_REQUEST.value(), "잘못된 회원 status 값입니다."), - EMAIL_NOT_FOUND(4006, HttpStatus.BAD_REQUEST.value(), "존재하지 않는 이메일입니다."); + USER_NOT_FOUND(5003, HttpStatus.BAD_REQUEST.value(), "존재하지 않는 회원입니다."), + PASSWORD_NO_MATCH(5004, HttpStatus.BAD_REQUEST.value(), "비밀번호가 일치하지 않습니다."), + INVALID_USER_STATUS(5005, HttpStatus.BAD_REQUEST.value(), "잘못된 회원 status 값입니다."), + EMAIL_NOT_FOUND(5006, HttpStatus.BAD_REQUEST.value(), "존재하지 않는 이메일입니다."), + + /** + * 6000: Store 오류 + */ + STORE_ERROR(6000, HttpStatus.BAD_REQUEST.value(), "가게 정보에 오류가 있습니다."), + EMPTY_MENU(6001, HttpStatus.BAD_REQUEST.value(), "메뉴가 비어있습니다."), + + /** + * 7000: Order 오류ㅓ + */ + ORDER_ERROR(7000, HttpStatus.BAD_REQUEST.value(), "주문 정보에 오류가 있습니다."), + WRONG_ORDER_ID(7001, HttpStatus.BAD_REQUEST.value(), "잘못된 주문ID의 접근입니다."); private final int code; private final int status; diff --git a/src/main/java/kuit/server/controller/OrderController.java b/src/main/java/kuit/server/controller/OrderController.java new file mode 100644 index 0000000..cb0b940 --- /dev/null +++ b/src/main/java/kuit/server/controller/OrderController.java @@ -0,0 +1,47 @@ +package kuit.server.controller; + +import kuit.server.common.response.BaseResponse; +import kuit.server.dto.order.GetOrderResponse; +import kuit.server.dto.order.PostOrderRequest; +import kuit.server.service.OrderService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/orders") +public class OrderController { + + private final OrderService orderService; + @PostMapping("/test") + public String test(@RequestBody PostOrderRequest postOrderRequest) { + log.info(postOrderRequest.toString()); + return "Success?"; + } + +// public String registerOrder(@RequestBody PostOrderRequest postOrderRequest) { +// +// } + + @PatchMapping("/{orderId}/cancel") + public BaseResponse cancelOrder(@PathVariable long orderId) { + orderService.cancelOrder(orderId); + + return new BaseResponse<>("orderId=" + orderId + " 삭제처리 되었습니다."); + } + + @GetMapping("/{orderId}") + public GetOrderResponse getOrder(@PathVariable long orderId) { + return orderService.getOrder(orderId); + } +} diff --git a/src/main/java/kuit/server/controller/StoreController.java b/src/main/java/kuit/server/controller/StoreController.java new file mode 100644 index 0000000..a0a1916 --- /dev/null +++ b/src/main/java/kuit/server/controller/StoreController.java @@ -0,0 +1,22 @@ +package kuit.server.controller; + +import java.util.List; +import kuit.server.dto.store.GetStoreMenuResponse; +import kuit.server.service.StoreService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/stores") +@RequiredArgsConstructor +public class StoreController { + private final StoreService storeService; + + @GetMapping("/{storeId}/menus") + public List getStoreMenus(@PathVariable long storeId) { + return storeService.getMenu(storeId); + } +} diff --git a/src/main/java/kuit/server/controller/UserController.java b/src/main/java/kuit/server/controller/UserController.java index 731b583..803b630 100644 --- a/src/main/java/kuit/server/controller/UserController.java +++ b/src/main/java/kuit/server/controller/UserController.java @@ -27,7 +27,7 @@ public class UserController { /** * 회원 가입 */ - @PostMapping("") + @PostMapping("/signup") public BaseResponse signUp(@Validated @RequestBody PostUserRequest postUserRequest, BindingResult bindingResult) { log.info("[UserController.signUp]"); if (bindingResult.hasErrors()) { @@ -49,7 +49,7 @@ public BaseResponse modifyUserStatus_dormant(@PathVariable long userId) /** * 회원 탈퇴 */ - @PatchMapping("/{userId}/deleted") + @PatchMapping("/{userId}/cancel") public BaseResponse modifyUserStatus_deleted(@PathVariable long userId) { log.info("[UserController.modifyUserStatus_delete]"); userService.modifyUserStatus_deleted(userId); @@ -85,4 +85,13 @@ public BaseResponse> getUsers( return new BaseResponse<>(userService.getUsers(nickname, email, status)); } + @GetMapping("/{userId}") + public GetUserResponse getUserInfo(@PathVariable long userId) { + return userService.getUserInfoByUserId(userId); + } + + @GetMapping("/{userId}/order-history") + public List getUserOrderHistory (@PathVariable long userId) { + return userService.getOrderByUserId(userId); + } } \ No newline at end of file diff --git a/src/main/java/kuit/server/dao/OrderDao.java b/src/main/java/kuit/server/dao/OrderDao.java new file mode 100644 index 0000000..71c8c6a --- /dev/null +++ b/src/main/java/kuit/server/dao/OrderDao.java @@ -0,0 +1,38 @@ +package kuit.server.dao; + +import java.util.Map; +import kuit.server.dto.order.GetOrderResponse; +import kuit.server.dto.order.PostOrderRequest; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Repository; + +@Slf4j +@Repository +@RequiredArgsConstructor +public class OrderDao { + private final NamedParameterJdbcTemplate jdbcTemplate; + + public void registerOrder(PostOrderRequest postOrderRequest) { // TODO: 동적 쿼리;;; + String sql = "insert all"; + } + + public int cancelOrder(long orderId) { + String sql = "update `order` set status=:status where order_id=:order_id"; + Map param = Map.of( + "status", "deleted", + "order_id", orderId); + return jdbcTemplate.update(sql, param); // returns affected row + } + + public GetOrderResponse getOrder(long orderId) { + String sql = "select order_id, status, total from `order` " + + "where order_id=:order_id"; + + Map param = Map.of("order_id", orderId); + + return jdbcTemplate.queryForObject(sql, param, new BeanPropertyRowMapper<>(GetOrderResponse.class)); + } +} diff --git a/src/main/java/kuit/server/dao/StoreDao.java b/src/main/java/kuit/server/dao/StoreDao.java new file mode 100644 index 0000000..b5bc4ce --- /dev/null +++ b/src/main/java/kuit/server/dao/StoreDao.java @@ -0,0 +1,31 @@ +package kuit.server.dao; + +import java.util.List; +import java.util.Map; +import kuit.server.dto.store.GetStoreMenuResponse; +import kuit.server.dto.user.GetUserResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Repository; + +@Slf4j +@Repository +@RequiredArgsConstructor +public class StoreDao { + private final NamedParameterJdbcTemplate jdbcTemplate; + + public List getMenus(long storeId) { + String sql = "select menu.store_id, menu.name, menu.price from store " + + "join menu on store.store_id = menu.store_id " + + "where menu.store_id=:storeId"; + + Map param = Map.of("storeId", storeId); + + return jdbcTemplate.query(sql, param, + (rs, rowNum) -> new GetStoreMenuResponse( + rs.getString("menu.name"), + rs.getString("menu.price")) + ); + } +} diff --git a/src/main/java/kuit/server/dao/UserDao.java b/src/main/java/kuit/server/dao/UserDao.java index 6f8daa8..e17879d 100644 --- a/src/main/java/kuit/server/dao/UserDao.java +++ b/src/main/java/kuit/server/dao/UserDao.java @@ -1,8 +1,10 @@ package kuit.server.dao; +import kuit.server.dto.user.GetUserOrderHistoryResponse; import kuit.server.dto.user.GetUserResponse; import kuit.server.dto.user.PostUserRequest; import lombok.extern.slf4j.Slf4j; +import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.SqlParameterSource; @@ -38,8 +40,8 @@ public boolean hasDuplicateNickName(String nickname) { } public long createUser(PostUserRequest postUserRequest) { - String sql = "insert into user(email, password, phone_number, nickname, profile_image) " + - "values(:email, :password, :phoneNumber, :nickname, :profileImage)"; + String sql = "insert into user(email, password, phone_number, nickname) " + + "values(:email, :password, :phoneNumber, :nickname)"; SqlParameterSource param = new BeanPropertySqlParameterSource(postUserRequest); KeyHolder keyHolder = new GeneratedKeyHolder(); @@ -73,7 +75,7 @@ public int modifyNickname(long userId, String nickname) { } public List getUsers(String nickname, String email, String status) { - String sql = "select email, phone_number, nickname, profile_image, status from user " + + String sql = "select email, phone_number, nickname, status from user " + "where nickname like :nickname and email like :email and status=:status"; Map param = Map.of( @@ -86,7 +88,6 @@ public List getUsers(String nickname, String email, String stat rs.getString("email"), rs.getString("phone_number"), rs.getString("nickname"), - rs.getString("profile_image"), rs.getString("status")) ); } @@ -103,4 +104,22 @@ public String getPasswordByUserId(long userId) { return jdbcTemplate.queryForObject(sql, param, String.class); } + public GetUserResponse getUserByUserId(long userId) { + String sql = "select email, phone_number, nickname, status from user " + + "where user_id=:user_id"; + Map param = Map.of("user_id", userId); + + return jdbcTemplate.queryForObject(sql, param, new BeanPropertyRowMapper<>(GetUserResponse.class)); + + } + + public List getOrderByUserId(long userId) { + String sql = "select user.user_id, `order`.order_id, `order`.status, `order`.total from user " + + "join `order` on user.user_id = `order`.user_id " + + "where user.user_id=:user_id"; + + Map param = Map.of("user_id", userId); + + return jdbcTemplate.query(sql, param, new BeanPropertyRowMapper<>(GetUserOrderHistoryResponse.class)); + } } \ No newline at end of file diff --git a/src/main/java/kuit/server/dto/order/Custom.java b/src/main/java/kuit/server/dto/order/Custom.java new file mode 100644 index 0000000..c5c0a6b --- /dev/null +++ b/src/main/java/kuit/server/dto/order/Custom.java @@ -0,0 +1,9 @@ +package kuit.server.dto.order; + +import lombok.Data; + +@Data +public class Custom { + private String option; + private String[] userChoice; +} diff --git a/src/main/java/kuit/server/dto/order/GetOrderResponse.java b/src/main/java/kuit/server/dto/order/GetOrderResponse.java new file mode 100644 index 0000000..0e7abc0 --- /dev/null +++ b/src/main/java/kuit/server/dto/order/GetOrderResponse.java @@ -0,0 +1,14 @@ +package kuit.server.dto.order; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class GetOrderResponse { + private long orderId; + private String status; + private float total; +} diff --git a/src/main/java/kuit/server/dto/order/OrderDetail.java b/src/main/java/kuit/server/dto/order/OrderDetail.java new file mode 100644 index 0000000..a8d8de4 --- /dev/null +++ b/src/main/java/kuit/server/dto/order/OrderDetail.java @@ -0,0 +1,10 @@ +package kuit.server.dto.order; + +import lombok.Data; + +@Data +public class OrderDetail { + private long menuId; + private long count; + private Custom[] custom; +} diff --git a/src/main/java/kuit/server/dto/order/PostOrderRequest.java b/src/main/java/kuit/server/dto/order/PostOrderRequest.java new file mode 100644 index 0000000..59a1303 --- /dev/null +++ b/src/main/java/kuit/server/dto/order/PostOrderRequest.java @@ -0,0 +1,10 @@ +package kuit.server.dto.order; + +import lombok.Data; + +@Data +public class PostOrderRequest { + private long userId; + private long storeId; + private OrderDetail[] orderDetail; +} diff --git a/src/main/java/kuit/server/dto/store/GetStoreMenuResponse.java b/src/main/java/kuit/server/dto/store/GetStoreMenuResponse.java new file mode 100644 index 0000000..0a01fe3 --- /dev/null +++ b/src/main/java/kuit/server/dto/store/GetStoreMenuResponse.java @@ -0,0 +1,12 @@ +package kuit.server.dto.store; + +import lombok.Data; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Data +public class GetStoreMenuResponse { + private final String name; + private final String price; +} diff --git a/src/main/java/kuit/server/dto/user/GetUserOrderHistoryResponse.java b/src/main/java/kuit/server/dto/user/GetUserOrderHistoryResponse.java new file mode 100644 index 0000000..891f568 --- /dev/null +++ b/src/main/java/kuit/server/dto/user/GetUserOrderHistoryResponse.java @@ -0,0 +1,15 @@ +package kuit.server.dto.user; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class GetUserOrderHistoryResponse { + private long userId; + private long orderId; + private String status; + private float total; +} diff --git a/src/main/java/kuit/server/dto/user/GetUserResponse.java b/src/main/java/kuit/server/dto/user/GetUserResponse.java index fa6e5ac..9afaa2f 100644 --- a/src/main/java/kuit/server/dto/user/GetUserResponse.java +++ b/src/main/java/kuit/server/dto/user/GetUserResponse.java @@ -14,7 +14,6 @@ public class GetUserResponse { private String email; private String phoneNumber; private String nickname; - private String profileImage; private String status; } \ No newline at end of file diff --git a/src/main/java/kuit/server/dto/user/PatchNicknameRequest.java b/src/main/java/kuit/server/dto/user/PatchNicknameRequest.java index 517c448..86b907c 100644 --- a/src/main/java/kuit/server/dto/user/PatchNicknameRequest.java +++ b/src/main/java/kuit/server/dto/user/PatchNicknameRequest.java @@ -12,5 +12,4 @@ public class PatchNicknameRequest { @NotNull(message = "nickname: {NotNull}") private String nickname; - } \ No newline at end of file diff --git a/src/main/java/kuit/server/dto/user/PostUserRequest.java b/src/main/java/kuit/server/dto/user/PostUserRequest.java index 23c165c..6ab20c4 100644 --- a/src/main/java/kuit/server/dto/user/PostUserRequest.java +++ b/src/main/java/kuit/server/dto/user/PostUserRequest.java @@ -8,10 +8,12 @@ import lombok.Setter; import org.hibernate.validator.constraints.Length; import org.springframework.lang.Nullable; +import org.springframework.validation.annotation.Validated; @Getter @Setter @NoArgsConstructor +@Validated public class PostUserRequest { @Email(message = "email: 이메일 형식이어야 합니다") @@ -34,9 +36,6 @@ public class PostUserRequest { @Length(max = 25, message = "nickname: 최대 {max}자리까지 가능합니다") private String nickname; - @Nullable - private String profileImage; - public void resetPassword(String encodedPassword) { this.password = encodedPassword; } diff --git a/src/main/java/kuit/server/service/OrderService.java b/src/main/java/kuit/server/service/OrderService.java new file mode 100644 index 0000000..46b66f4 --- /dev/null +++ b/src/main/java/kuit/server/service/OrderService.java @@ -0,0 +1,35 @@ +package kuit.server.service; + +import static kuit.server.common.response.status.BaseExceptionResponseStatus.DATABASE_ERROR; +import static kuit.server.common.response.status.BaseExceptionResponseStatus.WRONG_ORDER_ID; + +import kuit.server.common.exception.DatabaseException; +import kuit.server.common.exception.OrderException; +import kuit.server.dao.OrderDao; +import kuit.server.dto.order.GetOrderResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +@RequiredArgsConstructor +public class OrderService { + + private final OrderDao orderDao; + public void cancelOrder(long orderId) { + int effectedRow = orderDao.cancelOrder(orderId); + if(effectedRow >= 1) { + throw new DatabaseException(DATABASE_ERROR); + } + if(effectedRow == 0) { + throw new OrderException(WRONG_ORDER_ID); + } + } + + public GetOrderResponse getOrder(long orderId) { + GetOrderResponse order = orderDao.getOrder(orderId); + + return order; + } +} diff --git a/src/main/java/kuit/server/service/StoreService.java b/src/main/java/kuit/server/service/StoreService.java new file mode 100644 index 0000000..bf1d8c3 --- /dev/null +++ b/src/main/java/kuit/server/service/StoreService.java @@ -0,0 +1,26 @@ +package kuit.server.service; + +import static kuit.server.common.response.status.BaseExceptionResponseStatus.EMPTY_MENU; + +import java.util.List; +import kuit.server.common.exception.UserException; +import kuit.server.dao.StoreDao; +import kuit.server.dto.store.GetStoreMenuResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class StoreService { + private final StoreDao storeDao; + + public List getMenu(long storeId) { + List menus = storeDao.getMenus(storeId); + + if(menus.isEmpty()) { + throw new UserException(EMPTY_MENU); + } + + return menus; + } +} diff --git a/src/main/java/kuit/server/service/UserService.java b/src/main/java/kuit/server/service/UserService.java index 5c3881b..ff7089f 100644 --- a/src/main/java/kuit/server/service/UserService.java +++ b/src/main/java/kuit/server/service/UserService.java @@ -3,6 +3,7 @@ import kuit.server.common.exception.DatabaseException; import kuit.server.common.exception.UserException; import kuit.server.dao.UserDao; +import kuit.server.dto.user.GetUserOrderHistoryResponse; import kuit.server.dto.user.*; import kuit.server.util.jwt.JwtTokenProvider; import lombok.RequiredArgsConstructor; @@ -92,4 +93,14 @@ private void validateNickname(String nickname) { } } + public GetUserResponse getUserInfoByUserId(long userId) { + return userDao.getUserByUserId(userId); + } + + + public List getOrderByUserId(long userId) { + List orders = userDao.getOrderByUserId(userId); + // 빈값도 오류가 아님 + return orders; + } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 843a1e3..3a469b8 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,10 @@ -spring: - profiles: +spring: # 환경변수 파일 yml쓰는 이유 계층구조 => 큰 프로젝트에서 관리하기 good~ + profiles: # application 설정을 특정 환경에서 적용되게 하거나 환경별로 다르게 적용할떄 쓰이는 속성 group: "local": "localDB, devPort, secret, web-mvc" "dev": "devDB, devPort, secret, web-mvc" "prod": "prodDB, prodPort, secret, web-mvc" + active: "local" #개발서버, 실제작동하는 클라우드서버, 로칼, or just set on Edit Configuration on InteliJ --- @@ -41,7 +42,7 @@ spring: init: platform: mysql ---- +--- #하이픈을 기준으로 muti yml 파일을 구분 할수 있음 spring: config: