package com.pm.server.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

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.pm.server.player.Ghost;
import com.pm.server.player.GhostRepository;
import com.pm.server.response.GhostResponse;
import com.pm.server.response.GhostsResponse;

@RestController
@RequestMapping("/ghost")
public class GhostControllerImpl implements GhostController {

	@Autowired
	private GhostRepository ghostRepository;

	@RequestMapping(
			value="/{id}/location",
			method=RequestMethod.GET,
			produces={ "application/json" }
	)
	public GhostResponse getLocationById(
			@PathVariable Integer id,
			HttpServletResponse response) {

		if(id == null) {
			response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
			return null;
		}

		Ghost ghost = ghostRepository.getGhostById(id);
		if(ghost == null) {
			response.setStatus(HttpServletResponse.SC_NOT_FOUND);
			return null;
		}

		GhostResponse ghostResponse = new GhostResponse();
		ghostResponse.setId(ghost.getId());
		ghostResponse.setLocation(ghost.getLocation());
		return ghostResponse;
	}

	@RequestMapping(
			value="/locations",
			method=RequestMethod.GET,
			produces={ "application/json" }
	)
	public GhostsResponse getAllLocations() {

		GhostsResponse ghostsResponse = new GhostsResponse();

		List<Ghost> ghosts = ghostRepository.getAllGhosts();

		if(ghosts != null) {
			for(Ghost ghost : ghosts) {

				GhostResponse ghostResponse = new GhostResponse();
				ghostResponse.setId(ghost.getId());
				ghostResponse.setLocation(ghost.getLocation());

				ghostsResponse.addGhostResponse(ghostResponse);
			}
		}

		return ghostsResponse;
	}

}
@@ -100,16 +100,100 @@
 ponse;%0A%0A
+import org.apache.logging.log4j.LogManager;%0Aimport org.apache.logging.log4j.Logger;%0A
 import o
@@ -247,16 +247,16 @@
 owired;%0A
-
 import o
@@ -493,24 +493,76 @@
 ontroller;%0A%0A
+import com.fasterxml.jackson.databind.ObjectMapper;%0A
 import com.p
@@ -881,16 +881,185 @@
 itory;%0A%0A
+%09private final static Logger log =%0A%09%09%09LogManager.getLogger(GhostControllerImpl.class.getName());%0A%0A%09private final static ObjectMapper objectMapper = new ObjectMapper();%0A%0A
 %09@Reques
@@ -1361,24 +1361,90 @@
  null;%0A%09%09%7D%0A%0A
+%09%09log.debug(%22Mapped /ghosts/%7B%7D/location%22, Integer.toString(id));%0A%0A
 %09%09Ghost ghos
@@ -1495,32 +1495,91 @@
 host == null) %7B%0A
+%09%09%09log.debug(%22No ghost with id %7B%7D%22, Integer.toString(id));%0A
 %09%09%09response.setS
@@ -1781,16 +1781,183 @@
 ion());%0A
+%0A%09%09try %7B%0A%09%09%09log.debug(%0A%09%09%09%09%09%22Returning ghostResponse: %7B%7D%22,%0A%09%09%09%09%09objectMapper.writeValueAsString(ghostResponse)%0A%09%09%09);%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09log.debug(e);%0A%09%09%7D%0A%0A
 %09%09return
@@ -2128,16 +2128,57 @@
 ns() %7B%0A%0A
+%09%09log.debug(%22Mapped /ghosts/location%22);%0A%0A
 %09%09Ghosts
@@ -2337,16 +2337,185 @@
 sts) %7B%0A%0A
+%09%09%09%09try %7B%0A%09%09%09%09%09log.debug(%0A%09%09%09%09%09%09%09%22Processing ghost: %7B%7D%22,%0A%09%09%09%09%09%09%09objectMapper.writeValueAsString(ghost)%0A%09%09%09%09%09);%0A%09%09%09%09%7D%0A%09%09%09%09catch (Exception e) %7B%0A%09%09%09%09%09log.debug(e);%0A%09%09%09%09%7D%0A%0A
 %09%09%09%09Ghos
@@ -2706,16 +2706,16 @@
 ponse);%0A
-
 %09%09%09%7D%0A%09%09%7D
@@ -2712,24 +2712,192 @@
 ;%0A%09%09%09%7D%0A%09%09%7D%0A%0A
+%09%09try %7B%0A%09%09%09log.debug(%0A%09%09%09%09%09%22Returning ghostsResponse: %7B%7D%22,%0A%09%09%09%09%09objectMapper.writeValueAsString(ghostsResponse)%0A%09%09%09);%0A%09%09%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09log.debug(e);%0A%09%09%7D%0A%0A
 %09%09return gho

Add debug messages to GhostController