Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package wad.highfive.controller;
- import java.util.Collection;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PathVariable;
- 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.ResponseBody;
- import wad.highfive.data.Game;
- import wad.highfive.service.GameService;
- @Controller
- public class GameController {
- @Autowired
- private GameService gameService;
- /*
- *
- 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)
- GET /app/games listaa kaikki talletetut pelit
- GET /app/games/[name] palauttaa yksittäisen pelin tiedot pelin nimen perusteella
- DELETE /app/games/[name] poistaa nimen mukaisen pelin
- */
- @RequestMapping(value="/app/games", method=RequestMethod.POST,
- consumes = "application/json", produces = "application/json")
- public @ResponseBody Game create(@RequestBody String name) {
- Game game = new Game();
- game.setName(name);
- return gameService.create(game);
- }
- @RequestMapping(value="/app/games", method=RequestMethod.GET, produces = "application/json")
- public @ResponseBody Collection<Game> read(){
- return gameService.findAll();
- }
- @RequestMapping(value="/app/games/{name}", method=RequestMethod.GET, produces = "application/json")
- public @ResponseBody Game read(@PathVariable String name){
- return gameService.findByName(name);
- }
- @RequestMapping(value="/app/games/{name}", method=RequestMethod.POST)
- public void delete(@PathVariable String name){
- Game game = gameService.findByName(name);
- gameService.delete(game);
- }
- }
Add Comment
Please, Sign In to add comment