package com.iservport.home.controller;

import java.util.List;

import javax.inject.Inject;

import org.helianto.security.internal.UserAuthentication;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.iservport.report.domain.Project;
import com.iservport.report.service.ProjectQueryService;

/**
 * Controlador home
 * 
 * @author mauriciofernandesdecastro
 */
@RestController
@RequestMapping("/api/home")
@PreAuthorize("isAuthenticated()")
public class HomeController {
	
	@Inject
	private ProjectQueryService projectQueryService;

	/**
	 * Lista projetos por identidade.
	 *
	 * GET       /api/home/project
	 */
	@RequestMapping(value={"/project"}, method=RequestMethod.GET)
	public List<Project> project(UserAuthentication userAuthentication) {
		return projectQueryService.projectList(userAuthentication.getUserId() ,userAuthentication.getEntityId(), userAuthentication.getIdentityId());
	}
	
	/**
	 * Atualizar projeto com checkin.
	 *
	 * PUT 	/api/home/project
	 */
	@RequestMapping(value={"/project"}, method=RequestMethod.PUT, consumes="application/json")
	public Project projectNew(UserAuthentication userAuthentication, @RequestBody Project project) {
		int userId = 0;
		if ((userAuthentication != null) && (project != null) && (userAuthentication.getUserId() > 0)) {
			userId = userAuthentication.getUserId();
			// log console
			System.out.println("UserId: " + userAuthentication.getUserId());
			System.out.println("CheckinDate: " + (project.getCheckinDate() != null ? project.getCheckinDate() : "vazio"));
		}
		return  projectQueryService.projectChecked(userId, project);
	}

}

@@ -596,17 +596,17 @@
 rolador 
-h
+H
 ome%0D%0A * 
@@ -1483,446 +1483,98 @@
 %0D%0A%09%09
-int userId = 0;%0D%0A%09%09if ((userAuthentication != null) && (project != null) && (userAuthentication.getUserId() %3E 0)) %7B%0D%0A%09%09%09userId = userAuthentication.getUserId();%0D%0A%09%09%09// log console%0D%0A%09%09%09System.out.println(%22UserId: %22 + userAuthentication.getUserId());%0D%0A%09%09%09System.out.println(%22CheckinDate: %22 + (project.getCheckinDate() != null ? project.getCheckinDate() : %22vazio%22)
+return projectQueryService.projectChecked(userAuthentication.getUserId(), project
 );%0D%0A
-%09
 %09%7D%0D%0A%09
-%09return  projectQueryService.projectChecked(userId, project);%0D%0A%09%7D%0D%0A
 %0D%0A%7D%0D

Remove testes.