/*
 * Copyright 2010-2017 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.sambrannen.spring.events.web;

import static org.springframework.http.HttpStatus.NO_CONTENT;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMethodCall;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.on;

import java.util.List;

import org.springframework.http.HttpEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponents;

import com.sambrannen.spring.events.domain.Event;
import com.sambrannen.spring.events.service.EventService;

/**
 * RESTful controller for {@link Event events}.
 *
 * @author Sam Brannen
 * @since 1.0
 */
@RestController
@RequestMapping("/events")
public class RestEventsController {

	private final EventService service;

	public RestEventsController(EventService service) {
		this.service = service;
	}

	@GetMapping
	public List<Event> retrieveAllEvents() {
		return service.findAll();
	}

	@GetMapping("/{id}")
	public Event retrieveEvent(@PathVariable Long id) {
		return service.findById(id);
	}

	@PostMapping
	public HttpEntity<Void> createEvent(@RequestBody Event postedEvent) {
		Event savedEvent = service.save(postedEvent);

		UriComponents uriComponents = fromMethodCall(
			on(getClass()).retrieveEvent(savedEvent.getId())).build();

		return ResponseEntity.created(uriComponents.encode().toUri()).build();
	}

	@PutMapping("/{id}")
	@ResponseStatus(NO_CONTENT)
	public void updateEvent(@RequestBody Event updatedEvent, @PathVariable Long id) {
		service.save(updatedEvent);
	}

	@DeleteMapping("/{id}")
	@ResponseStatus(NO_CONTENT)
	public void deleteEvent(@PathVariable Long id) {
		service.deleteById(id);
	}

}

@@ -949,16 +949,101 @@
 .List;%0A%0A
+import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A
 import o
@@ -1070,32 +1070,32 @@
 ttp.HttpEntity;%0A
-
 import org.sprin
@@ -2013,16 +2013,96 @@
 ller %7B%0A%0A
+%09private static final Log log = LogFactory.getLog(RestEventsController.class);%0A%0A
 %09private
@@ -2265,24 +2265,62 @@
 lEvents() %7B%0A
+%09%09log.debug(%22Retrieving all events%22);%0A
 %09%09return ser
@@ -2414,16 +2414,61 @@
 g id) %7B%0A
+%09%09log.debug(%22Finding event with ID: %22 + id);%0A
 %09%09return
@@ -2579,16 +2579,64 @@
 vent) %7B%0A
+%09%09log.debug(%22Creating event: %22 + postedEvent);%0A%0A
 %09%09Event 
@@ -2990,32 +2990,80 @@
 able Long id) %7B%0A
+%09%09log.debug(%22Updating event: %22 + updatedEvent);%0A
 %09%09service.save(u
@@ -3126,32 +3126,32 @@
 tus(NO_CONTENT)%0A
-
 %09public void del
@@ -3184,16 +3184,62 @@
 g id) %7B%0A
+%09%09log.debug(%22Deleting event with ID: %22 + id);%0A
 %09%09servic

Add debug logging to RestEventsController