Skip to content

Commit

Permalink
Order controller now returns orderView as respond for new order submit
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoavg committed Jan 5, 2014
1 parent 549ad74 commit a7366d3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.qorder.qorderws.exception.BusinessDoesNotExistException;
import com.qorder.qorderws.exception.OrderDoesNotExistException;
import com.qorder.qorderws.model.order.EOrderStatus;
import com.qorder.qorderws.model.order.Order;
import com.qorder.qorderws.service.IOrderService;

@Controller
Expand All @@ -32,11 +31,11 @@ public class OrderController {
@Autowired
private IOrderService orderService;

@RequestMapping(value = "/business", params = "id", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<Long> createOrder(@RequestParam Long id, @RequestBody OrderDTO orderDTO) throws BusinessDoesNotExistException {
@RequestMapping(value = "/business", params = "id", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<OrderViewDTO> createOrder(@RequestParam Long id, @RequestBody OrderDTO orderDTO) throws BusinessDoesNotExistException {
LOGGER.info("Request for order submit");
Order order = orderService.submitOrder(id, orderDTO);
return new ResponseEntity<Long>(order.getId(),HttpStatus.CREATED);
OrderViewDTO orderView = orderService.submitOrder(id, orderDTO);
return new ResponseEntity<OrderViewDTO>(orderView,HttpStatus.CREATED);
}

@RequestMapping(value = "/business", params = "id", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import com.qorder.qorderws.exception.BusinessDoesNotExistException;
import com.qorder.qorderws.exception.OrderDoesNotExistException;
import com.qorder.qorderws.model.order.EOrderStatus;
import com.qorder.qorderws.model.order.Order;

public interface IOrderService {

Order submitOrder(long businessId, OrderDTO order) throws BusinessDoesNotExistException;
OrderViewDTO submitOrder(long businessId, OrderDTO order) throws BusinessDoesNotExistException;

BusinessOrdersDTO fetchOrdersByBusinessID(long businessId) throws BusinessDoesNotExistException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ public class OrderService implements IOrderService {
private IBusinessDAO businessDAO;

@Override
public Order submitOrder(long businessId, OrderDTO orderDTO) throws BusinessDoesNotExistException {
public OrderViewDTO submitOrder(long businessId, OrderDTO orderDTO) throws BusinessDoesNotExistException {
Order order = new OrderDTOtoOrderMapper().map(orderDTO, new Order());
order.setBusiness(businessDAO.findById(businessId));
return orderDAO.save(order);
orderDAO.save(order);
return new OrderToOrderViewDTOMapper().map(order, new OrderViewDTO());
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit a7366d3

Please sign in to comment.