コード例 #1
0
ファイル: DeckResource.java プロジェクト: pdxkar/cardShuffler
 // 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
ファイル: DeckResource.java プロジェクト: pdxkar/cardShuffler
  // 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
ファイル: DeckResource.java プロジェクト: pdxkar/cardShuffler
  // 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
ファイル: DeckResource.java プロジェクト: pdxkar/cardShuffler
  // 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
ファイル: DeckResource.java プロジェクト: pdxkar/cardShuffler
  // 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);
  }