Created
July 27, 2012 11:26
-
-
Save msulima/3187481 to your computer and use it in GitHub Desktop.
EventResignController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.futureprocessing.fpcommunity.controllers.event; | |
import java.security.Principal; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.WebDataBinder; | |
import org.springframework.web.bind.annotation.ExceptionHandler; | |
import org.springframework.web.bind.annotation.InitBinder; | |
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.ResponseBody; | |
import com.futureprocessing.fpcommunity.convert.IdToEventPropertyEditor; | |
import com.futureprocessing.fpcommunity.core.domain.Event; | |
import com.futureprocessing.fpcommunity.core.domain.User; | |
import com.futureprocessing.fpcommunity.core.exceptions.EventEndedException; | |
import com.futureprocessing.fpcommunity.core.exceptions.UserNotAttendingEventException; | |
import com.futureprocessing.fpcommunity.core.repositories.UserRepository; | |
import com.futureprocessing.fpcommunity.core.services.events.IEventResignService; | |
@Controller | |
public class EventResignController { | |
@Autowired | |
private UserRepository userRepository; | |
@Autowired | |
private IEventResignService eventResignService; | |
@Autowired | |
private IdToEventPropertyEditor idToEventPropertyEditor; | |
@InitBinder | |
public void initBinder(WebDataBinder binder) { | |
binder.registerCustomEditor(Event.class, idToEventPropertyEditor); | |
} | |
@ExceptionHandler(UserNotAttendingEventException.class) | |
@ResponseBody | |
public EventResignResponseStatus handleUserNotAttendingEventException() { | |
return EventResignResponseStatus.DOESNT_ATTEND; | |
} | |
@ExceptionHandler(EventEndedException.class) | |
@ResponseBody | |
public EventResignResponseStatus handleEventEndedException() { | |
return EventResignResponseStatus.EVENT_ENDED; | |
} | |
@RequestMapping(value = "/event/resign/{event}", method = RequestMethod.POST) | |
@ResponseBody | |
public EventResignResponseStatus resign(@PathVariable Event event, Principal principal) { | |
User user = userRepository.findByPrincipal(principal); | |
eventResignService.resignFromEvent(user, event); | |
return EventResignResponseStatus.OK; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment