package io.reactivesw.customer.customer.application.controller;

import io.reactivesw.customer.customer.application.model.Customer;
import io.reactivesw.customer.customer.application.model.mapper.CustomerMapper;
import io.reactivesw.customer.customer.application.service.CustomerApplication;
import io.reactivesw.customer.customer.domain.entity.CustomerEntity;
import io.reactivesw.customer.customer.domain.service.CustomerService;
import io.reactivesw.route.CustomerRouter;
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.RestController;

/**
 * Created by umasuo on 16/12/27.
 */
@RestController
public class CustomerController {

  /**
   * logger.
   */
  private final static Logger LOG = LoggerFactory.getLogger(CustomerController.class);

  /**
   * customer service.
   */
  @Autowired
  private transient CustomerService customerService;

  /**
   * customer service.
   */
  @Autowired
  private transient CustomerApplication customerApplication;

  /**
   * login with email.
   *
   * @param email String
   * @return Customer
   */
  @PostMapping(value = CustomerRouter.CUSTOMER_ROOT, params = "email")
  public Customer getCustomerWithEmail(String email) {
    LOG.info("enter: email:", email);

    CustomerEntity entity = customerService.getByEmail(email);

    Customer customer = CustomerMapper.entityToModel(entity);

    LOG.info("exit: customer:", customer);
    return customer;
  }

  /**
   * login with google.
   *
   * @param gToken String
   * @return Customer
   */
  @PostMapping(value = CustomerRouter.CUSTOMER_ROOT, params = "gToken")
  public Customer getCustomerWithGoogleToken(String gToken) throws Exception {
    LOG.info("enter: idToken:", gToken);

    Customer customer = customerApplication.getOrCreateWithGoogleToken(gToken);


    LOG.info("exit: customer:", customer);
    return customer;
  }

}

@@ -635,27 +635,148 @@
 otation.
-PostMapping
+GetMapping;%0Aimport org.springframework.web.bind.annotation.PathVariable;%0Aimport org.springframework.web.bind.annotation.RequestParam
 ;%0Aimport
@@ -1333,35 +1333,34 @@
 stomer%0A   */%0A  @
-Pos
+Ge
 tMapping(value =
@@ -1447,16 +1447,30 @@
 thEmail(
+@RequestParam 
 String e
@@ -1808,11 +1808,10 @@
 %0A  @
-Pos
+Ge
 tMap
@@ -1917,16 +1917,30 @@
 leToken(
+@RequestParam 
 String g
@@ -2088,16 +2088,472 @@
 oken);%0A%0A
+    LOG.info(%22exit: customer:%22, customer);%0A    return customer;%0A  %7D%0A%0A  /**%0A   * get customer by id.%0A   *%0A   * @param id String customer id%0A   * @return Customer%0A   */%0A  @GetMapping(value = CustomerRouter.CUSTOMER_WITH_ID)%0A  public Customer getCustomerWithId(@PathVariable String id) %7B%0A    LOG.info(%22enter: id: %7B%7D%22, id);%0A%0A    CustomerEntity customerEntity = customerService.getById(id);%0A    Customer customer = CustomerMapper.entityToModel(customerEntity);%0A
 %0A    LOG

change customer api