Пример #1
0
 // GET a list of all decks
 @GET
 @Produces({MediaType.APPLICATION_JSON})
 public String getAll() {
   List<Deck> deckList = deckService.getAll();
   Gson gson = new Gson();
   return gson.toJson(deckList);
 }
Пример #2
0
  // PUT - create a new deck in sorted order
  @PUT
  @Produces({MediaType.APPLICATION_JSON})
  public String createNewDeck() {
    Deck deck = deckService.createNewDeck(); // move to return statement
    Gson gson = new Gson();

    return gson.toJson(deck);
  }
Пример #3
0
  // TODO Make this exercise work without this initialization
  // TESTING initialize tempDatabase
  @POST
  public String initDatabase() {

    List<Deck> deckList = deckService.initDatabase();
    Gson gson = new Gson();

    return gson.toJson(deckList);
  }
Пример #4
0
  // DELETE - delete an existing deck
  @DELETE
  @Produces({MediaType.APPLICATION_JSON})
  @Path("/{param}")
  public String deleteDeckById(@PathParam("param") int id) {

    Gson gson = new Gson();

    if (deckService.deleteDeckById(id)) {
      return gson.toJson("Deck #" + id + " has been deleted.");
    } else {
      return gson.toJson("Delete of deck #" + id + " failed");
    }
  }
Пример #5
0
  // POST - shuffle an existing deck
  @POST
  @Path("/{param}")
  @Produces({MediaType.APPLICATION_JSON})
  public String shuffleDeckById(@PathParam("param") int id) {
    Deck deck = deckService.shuffleDeckById(id);

    if (deck == null) {
      System.out.println("Deck with id:" + id + " is not found");
      throw new NotFoundException("Deck with id:" + id + " is not found");
    }
    Gson gson = new Gson();

    return gson.toJson(deck);
  }