Skip to content
Snippets Groups Projects
Select Git revision
  • 00a083d2048d06c4c2b6aac1c02ba4d423f6e879
  • master default protected
2 results

http.java

Blame
  • http.java 2.84 KiB
    package ch.hepia.order;
    
    import ch.hepia.account.*;
    import ch.hepia.event.*;
    import ch.hepia.stock.*;
    
    import java.util.*;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    @SpringBootApplication
    @RestController
    public class http {
    
        private static OrderService orderService;
        private static AccountService accountService;
        private static StockService stockService;
    
        public static void main(String[] args) {
            http.orderService = new OrderService("localhost");
            http.accountService = new AccountService("localhost");
            http.stockService = new StockService("localhost");
            SpringApplication.run(http.class, args);
        }
    
        @RequestMapping("/order")
        public Order order(
            @RequestParam(value = "idAccount", defaultValue = "1") int idAccount,
            @RequestParam(value = "idProduct", defaultValue = "1") int idProduct,
            @RequestParam(value = "quantity", defaultValue = "1") int quantity ) {
    
            int idOrder = 5;
            Order o = new Order(idOrder, idAccount);
            o.addProduct(idProduct, quantity);
            
            Event oc = new EventOrderCreated(o.id(), "hello", idAccount, o.getProducts());
            http.orderService.send(oc);
            return o;
        }
    
        @RequestMapping("/orderNotExistingProducts")
        public Order orderNotExistingProducts() {
            int idAccount = 1;
            int idOrder = 5;
            Order o = new Order(idOrder, idAccount);
            o.addProduct(1, 4);
            o.addProduct(999, 4);
            Event oc = new EventOrderCreated(o.id(), "hello", idAccount, o.getProducts());
            http.orderService.send(oc);
            return o;
        }
    
        @RequestMapping("/createAccount")
        public String createAccount(@RequestParam(value = "name", defaultValue = "Orphée") String name) {
            accountService.send(new EventCreateAccount(1, "Creating the account", name));
            return name;
        }
    
        @RequestMapping("/creditAccount")
        public String createAccount(
            @RequestParam(value = "idAccount", defaultValue = "1") int idAccount,
            @RequestParam(value = "amount", defaultValue = "1") double amount) {
            accountService.send(new EventCreditAnAccount(5, "Crediting account", idAccount, amount));
            return null;
        }
    
    
        @RequestMapping("/createProduct")
        public Product createProduct(@RequestParam(value = "name", defaultValue = "poire") String name,
                @RequestParam(value = "price", defaultValue = "1") double price) {
    
            stockService.send(new EventCreateProduct(1, "Creating the product", name, price));
    
            return null;
        }
    
    }