Guest User

Untitled

a guest
Dec 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package wad.highfive.controller;
  6.  
  7. import java.util.Collection;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.ResponseBody;
  15. import wad.highfive.data.Game;
  16. import wad.highfive.service.GameService;
  17.  
  18. @Controller
  19. public class GameController {
  20.  
  21. @Autowired
  22. private GameService gameService;
  23.  
  24. /*
  25. *
  26. POST /app/games luo uuden pelin sille annetulla nimellä ja palauttaa luodun pelin tiedot - ainoan vastaanotettavan attribuutin nimi on name. (Huom. vieläkin! Kaikki syötteet ja vastaukset ovat JSON-muotoisia)
  27. GET /app/games listaa kaikki talletetut pelit
  28. GET /app/games/[name] palauttaa yksittäisen pelin tiedot pelin nimen perusteella
  29. DELETE /app/games/[name] poistaa nimen mukaisen pelin
  30. */
  31.  
  32. @RequestMapping(value="/app/games", method=RequestMethod.POST,
  33. consumes = "application/json", produces = "application/json")
  34. public @ResponseBody Game create(@RequestBody String name) {
  35. Game game = new Game();
  36. game.setName(name);
  37.  
  38. return gameService.create(game);
  39. }
  40.  
  41. @RequestMapping(value="/app/games", method=RequestMethod.GET, produces = "application/json")
  42. public @ResponseBody Collection<Game> read(){
  43. return gameService.findAll();
  44. }
  45.  
  46. @RequestMapping(value="/app/games/{name}", method=RequestMethod.GET, produces = "application/json")
  47. public @ResponseBody Game read(@PathVariable String name){
  48. return gameService.findByName(name);
  49. }
  50.  
  51.  
  52. @RequestMapping(value="/app/games/{name}", method=RequestMethod.POST)
  53. public void delete(@PathVariable String name){
  54. Game game = gameService.findByName(name);
  55. gameService.delete(game);
  56. }
  57.  
  58. }
Add Comment
Please, Sign In to add comment