Package com.jayway.demo.library.domain

Examples of com.jayway.demo.library.domain.Book


  @GET
  @Path("/{id}")
  @Produces("application/vnd.demo.library.book+json")
  public Response getBookById(@PathParam("id") Integer id) {
    Book book = bookRepository.getBookById(id);
    return Response.ok(BookDto.fromBean(book)).build();
  }
View Full Code Here


     @GET
     @Path("/{id}")
     @Produces("application/vnd.demo.library.book+json")
     public Response getBookById(@PathParam("id") Integer id) {
       Book book = bookRepository.getBookById(id);
       return Response.ok(BookDto.fromBean(book)).build();
     }
View Full Code Here

  @PUT
  @Path("/{id}")
  @Consumes("application/vnd.demo.library.book+json")
  @Produces("application/vnd.demo.library.book+json")
  public Response updateBook(@PathParam("id") Integer id, BookDto updatedBook) {
    Book book = bookRepository.getBookById(id);
    book.setAuthor(updatedBook.getAuthor());
    book.setTitle(updatedBook.getTitle());

    return getBookById(id);
  }
View Full Code Here

     @PUT
     @Path("/{id}")
     @Consumes("application/vnd.demo.library.book+json")
     @Produces("application/vnd.demo.library.book+json")
     public Response updateBook(@PathParam("id") Integer id, BookDto updatedBook) {
       Book book = bookRepository.getBookById(id);
       book.setAuthor(updatedBook.getAuthor());
       book.setTitle(updatedBook.getTitle());

       return getBookById(id);
     }
View Full Code Here

  @POST
  @Consumes("application/vnd.demo.library.loan+json")
  @Produces("application/vnd.demo.library.loan+json")
  @Linkable(value = LinkableIds.LOAN_NEW_ID, templateClass = LoanDto.class)
  public Response newLoan(LoanDto loan) {
    Book book = bookRepository.getBookById(loan.getBookId());
    if (book.isBorrowed()) {
      return Response.status(Status.CONFLICT).build();
    }

    Customer customer = customerRepository.getById(loan.getCustomerId());
    book.setBorrowedBy(customer);

    return HateoasResponse
        .created(LinkableIds.LOAN_DETAILS_ID, book.getId())
        .entity(loan)
        .selfLink(LinkableIds.LOAN_DETAILS_ID, book.getId())
        .link(LinkableIds.BOOK_DETAILS_ID, Rels.BOOK, book.getId())
        .link(LinkableIds.CUSTOMER_DETAILS_ID, Rels.CUSTOMER, customer.getId())
        .selfLink(LinkableIds.LOAN_RETURN_ID, book.getId()).build();
  }
View Full Code Here

  @GET
  @Path("/{id}")
  @Produces("application/vnd.demo.library.loan+json")
  @Linkable(LinkableIds.LOAN_DETAILS_ID)
  public Response getLoan(@PathParam("id") Integer id) {
    Book book = bookRepository.getBookById(id);
    if (book == null || !book.isBorrowed()) {
      return Response.status(Status.NOT_FOUND).build();
    }

    Customer customer = book.getBorrowedBy();
    return HateoasResponse.ok(new LoanDto(customer.getId(), book.getId()))
        .selfLink(LinkableIds.LOAN_DETAILS_ID, book.getId())
        .link(LinkableIds.BOOK_DETAILS_ID, Rels.BOOK, book.getId())
        .link(LinkableIds.CUSTOMER_DETAILS_ID, Rels.CUSTOMER, customer.getId())
        .selfLink(LinkableIds.LOAN_RETURN_ID, id).build();
  }
View Full Code Here

  @DELETE
  @Path("/{id}")
  @Linkable(LinkableIds.LOAN_RETURN_ID)
  public Response returnLoan(@PathParam("id") Integer id) {
    Book book = bookRepository.getBookById(id);
    book.returned();

    return HateoasResponse.ok()
        .location(makeLink(LinkableIds.LOANS_LIST_ID, Rels.LOANS)).build();
  }
View Full Code Here

    @GET
    @Path("/{id}")
    @Produces("application/vnd.demo.library.loan+json")
    @Linkable(LinkableIds.LOAN_DETAILS_ID)
    public Response getLoan(@PathParam("id") Integer id) {
        Book book = bookRepository.getBookById(id);
        if (book == null || !book.isBorrowed()) {
            return Response.status(Status.NOT_FOUND).build();
        }

        Customer customer = book.getBorrowedBy();
        return HateoasResponse.ok(new LoanDto(customer.getId(), book.getId()))
                .selfLink(LinkableIds.LOAN_DETAILS_ID, book.getId())
                .link(LinkableIds.BOOK_DETAILS_ID, Rels.BOOK, book.getId())
                .link(LinkableIds.CUSTOMER_DETAILS_ID, Rels.CUSTOMER, customer.getId())
                .selfLink(LinkableIds.LOAN_RETURN_ID, id).build();
    }
View Full Code Here

    @DELETE
    @Path("/{id}")
    @Linkable(LinkableIds.LOAN_RETURN_ID)
    public Response returnLoan(@PathParam("id") Integer id) {
        Book book = bookRepository.getBookById(id);
        book.returned();

        return HateoasResponse.ok()
                .location(makeLink(LinkableIds.LOANS_LIST_ID, Rels.LOANS)).build();
    }
View Full Code Here

TOP

Related Classes of com.jayway.demo.library.domain.Book

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.