package com.example.api;

import java.sql.Date;
import java.time.LocalDate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.domain.User;
import com.example.service.LoginUserDetailsService;

@RestController
@RequestMapping("limited")
public class EcsiteRestController {
	@Autowired
	LoginUserDetailsService loginUserDetailsService;
	
	@PostMapping("signUp")
	public User createUser(@RequestBody User user) {
		user.setRoles("user");
		LocalDate localDate =  LocalDate.now();
		Date nowDate = Date.valueOf(localDate);
		user.setCreatedAt(nowDate);
		user.setUpdatedAt(nowDate);
		loginUserDetailsService.create(user);
		return user;
	}
}