-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
106 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/kusitms/jipbap/order/OrderController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.common.response.CommonResponse; | ||
import com.kusitms.jipbap.food.dto.CategoryDto; | ||
import com.kusitms.jipbap.food.dto.RegisterCategoryRequestDto; | ||
import com.kusitms.jipbap.order.dto.OrderDto; | ||
import com.kusitms.jipbap.order.dto.OrderFoodRequestDto; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
|
||
@RestController | ||
@RequestMapping("/order") | ||
@RequiredArgsConstructor | ||
public class OrderController { | ||
|
||
private final OrderService orderService; | ||
|
||
@Operation(summary = "음식 주문하기") | ||
@PostMapping("/food") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public CommonResponse<OrderDto> orderFood(@Valid @RequestBody OrderFoodRequestDto dto) { | ||
return new CommonResponse<>(orderService.orderFood(dto)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.food.Food; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface OrderRepository extends JpaRepository <Order, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.food.Category; | ||
import com.kusitms.jipbap.food.Food; | ||
import com.kusitms.jipbap.food.FoodRepository; | ||
import com.kusitms.jipbap.food.dto.CategoryDto; | ||
import com.kusitms.jipbap.food.exception.FoodNotExistsException; | ||
import com.kusitms.jipbap.order.dto.OrderDto; | ||
import com.kusitms.jipbap.order.dto.OrderFoodRequestDto; | ||
import com.kusitms.jipbap.user.User; | ||
import com.kusitms.jipbap.user.UserRepository; | ||
import com.kusitms.jipbap.user.exception.UserNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class OrderService { | ||
|
||
private final OrderRepository orderRepository; | ||
private final UserRepository userRepository; | ||
private final FoodRepository foodRepository; | ||
|
||
public OrderDto orderFood(OrderFoodRequestDto dto) { | ||
User user = userRepository.findById(dto.getUser()).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); | ||
Food food = foodRepository.findById(dto.getFood()).orElseThrow(()-> new FoodNotExistsException("해당 음식은 유효하지 않습니다.")); | ||
|
||
Order order = orderRepository.save( | ||
new Order(null, user, food, dto.getOrderCount()) | ||
); | ||
|
||
return new OrderDto(order.getId(), user.getId(), food.getId(), order.getOrderCount()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.kusitms.jipbap.order.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class OrderDto { | ||
|
||
private Long id; | ||
|
||
private Long user; | ||
|
||
private Long food; | ||
|
||
private Long orderCount; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kusitms/jipbap/order/dto/OrderFoodRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.kusitms.jipbap.order.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class OrderFoodRequestDto { | ||
private Long user; | ||
|
||
private Long food; | ||
|
||
private Long orderCount; | ||
} |