package com.arcbees.gwtpwebsite.server.rest;
import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.arcbees.gwtpwebsite.server.order.OrderProcessor;
import com.arcbees.gwtpwebsite.server.validation.DomainValidator;
import com.arcbees.gwtpwebsite.shared.domain.Order;
import com.arcbees.gwtpwebsite.shared.domain.OrderConfirmation;
import com.arcbees.gwtpwebsite.shared.rest.PathTokens;
import com.stripe.exception.StripeException;
@Path(PathTokens.ORDER)
@Produces(MediaType.APPLICATION_JSON)
public class OrderResource {
private final OrderProcessor orderProcessor;
@Inject
OrderResource(OrderProcessor orderProcessor) {
this.orderProcessor = orderProcessor;
}
@POST
public Response processOrder(Order order) throws StripeException {
DomainValidator<Order> validator = new DomainValidator<Order>();
validator.validate(order);
OrderConfirmation confirmation = orderProcessor.processOrder(order);
return Response.ok(confirmation).build();
}
}