Add OrderStatus
This commit is contained in:
@@ -11,4 +11,5 @@ public class ParameterConfig {
|
||||
public static final String PARAM_URI = "uri";
|
||||
public static final String PARAM_RATING = "rating";
|
||||
public static final String PARAM_IMAGE = "image";
|
||||
public static final String PARAM_STATUS = "status";
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.htwsaar.webshop.controller;
|
||||
|
||||
import de.htwsaar.webshop.model.OrderStatus;
|
||||
import de.htwsaar.webshop.repository.entities.Order;
|
||||
import de.htwsaar.webshop.service.OrderService;
|
||||
import de.htwsaar.webshop.service.ValidatorService;
|
||||
@@ -14,8 +15,7 @@ import java.util.List;
|
||||
|
||||
import static de.htwsaar.webshop.config.ControllerPathConfig.ORDER_BASE;
|
||||
import static de.htwsaar.webshop.config.ControllerPathConfig.ORDER_GET_ALL;
|
||||
import static de.htwsaar.webshop.config.ParameterConfig.PARAM_CUSTOMER_ID;
|
||||
import static de.htwsaar.webshop.config.ParameterConfig.PARAM_ID;
|
||||
import static de.htwsaar.webshop.config.ParameterConfig.*;
|
||||
import static de.htwsaar.webshop.util.LoggerUtil.logRequest;
|
||||
|
||||
@RestController
|
||||
@@ -67,16 +67,19 @@ public class OrderController {
|
||||
return ResponseEntity.ok(saved != null);
|
||||
}
|
||||
|
||||
//TODO: check whether an order should be updatable
|
||||
@RequestMapping(path = ORDER_BASE, method = RequestMethod.PUT, produces = "application/json")
|
||||
@RequestMapping(path = ORDER_BASE, method = RequestMethod.PATCH, produces = "application/json")
|
||||
public ResponseEntity<Boolean> update(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_ID) Long orderId,
|
||||
@RequestBody Order order) {
|
||||
@RequestParam(value = PARAM_STATUS) OrderStatus status) {
|
||||
logRequest(request);
|
||||
if (orderId == null || orderService.getOrderById(orderId) == null) {
|
||||
return ResponseEntity.badRequest().body(false);
|
||||
if (orderId == null) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
order.setId(orderService.getOrderById(orderId).getId());
|
||||
Order order = orderService.getOrderById(orderId);
|
||||
if (order == null) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
order.setStatus(status);
|
||||
return ResponseEntity.ok(orderService.save(order) != null);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.htwsaar.webshop.model;
|
||||
|
||||
public enum OrderStatus {
|
||||
ORDERED, //0
|
||||
IN_PROGRESS, //1
|
||||
ISSUES, //2
|
||||
DELIVERED, //3
|
||||
CANCELLED, //4
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.htwsaar.webshop.repository.entities;
|
||||
|
||||
import de.htwsaar.webshop.model.OrderStatus;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -26,6 +27,9 @@ public class Order {
|
||||
@Column(name = "time", nullable = false)
|
||||
private Long time;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private OrderStatus status;
|
||||
|
||||
@OneToMany(mappedBy = "order", orphanRemoval = true, fetch = FetchType.LAZY, cascade = CascadeType.ALL, targetEntity = OrderItem.class)
|
||||
private List<OrderItem> orderItems;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user