创建 OrderController.java
parent
7134e6c5ff
commit
ed0204aae5
|
|
@ -0,0 +1,70 @@
|
|||
package com.gao.finalhw.controller;
|
||||
|
||||
import com.gao.finalhw.model.Orders;
|
||||
import com.gao.finalhw.response.ServerResponseEntity;
|
||||
import com.gao.finalhw.service.OrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.RestController;
|
||||
|
||||
@RequestMapping("/order")
|
||||
@RestController
|
||||
public class OrderController {
|
||||
private final Logger logger = LoggerFactory.getLogger(OrderController.class);
|
||||
@Autowired
|
||||
OrderService orderService;
|
||||
|
||||
@PostMapping("/add")
|
||||
public ServerResponseEntity<Boolean> addOrder(@RequestBody Orders orders) {
|
||||
logger.info("start add order.");
|
||||
if (orders != null) {
|
||||
if (orderService.addOrder(orders)) {
|
||||
return ServerResponseEntity.success(true);
|
||||
}
|
||||
return ServerResponseEntity.fail("insert fail.");
|
||||
}
|
||||
return ServerResponseEntity.fail("order data error.");
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ServerResponseEntity<Boolean> updateOrder(@RequestBody Orders orders) {
|
||||
logger.info("start update order.");
|
||||
if (orders != null) {
|
||||
if (orderService.updateOrder(orders)) {
|
||||
return ServerResponseEntity.success(true);
|
||||
}
|
||||
return ServerResponseEntity.fail("update fail.");
|
||||
}
|
||||
return ServerResponseEntity.fail("order data error.");
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
public ServerResponseEntity<Boolean> deleteOrder(@RequestBody Orders orders) {
|
||||
logger.info("start delete order by id.");
|
||||
if (orders != null) {
|
||||
if (orderService.deleteById(orders)) {
|
||||
return ServerResponseEntity.success(true);
|
||||
}
|
||||
return ServerResponseEntity.fail("delete fail.");
|
||||
}
|
||||
return ServerResponseEntity.fail("order data error.");
|
||||
}
|
||||
|
||||
@PostMapping("/delete1")
|
||||
public ServerResponseEntity<Boolean> deleteOrderByUserId(@RequestBody Orders orders) {
|
||||
logger.info("start delete order by user id.");
|
||||
if (orders != null) {
|
||||
if (orderService.deleteByUserId(orders)) {
|
||||
return ServerResponseEntity.success(true);
|
||||
}
|
||||
return ServerResponseEntity.fail("delete fail.");
|
||||
}
|
||||
return ServerResponseEntity.fail("order data error.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue