package com.eyrolles.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.eyrolles.model.Client;
import com.eyrolles.service.IClientService;
import com.eyrolles.util.Crypt;

@RestController
@RequestMapping(path="/client")
public class ClientController {
	
	@Autowired
	IClientService serviceClient;
	
	@RequestMapping(path="/auth",method=RequestMethod.POST)
	public Client authentificate(String mail,String password){
		return serviceClient.authentificate(mail, password);
	}
	@RequestMapping(path="/add",method=RequestMethod.POST)
	public Client add(Client c){
		c.setMotDePasse(Crypt.encryptPassword(c.getMotDePasse()));
		return serviceClient.create(c);
	}
	@RequestMapping(path="/{id}",method=RequestMethod.GET)
	public Client get(@PathVariable int id){
		return serviceClient.find(id);
	}
	
}
