2017 © Pedro Peláez
 

library eh-library

Model and use cases for rest api course

image

clearcode/eh-library

Model and use cases for rest api course

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status Coverage Status Scrutinizer Code Quality Dependency Status, (*1)

EH-library Application for rest api course

This repository is a simple model which could be used to build REST API., (*2)

Requirements

    "require": {
        "php": ">=5.5",
        "ramsey/uuid": "~3.0",
        "everzet/persisted-objects": "~1.0"
    },

Installation

composer require --dev clearcode/eh-library

Features

  • Add book to library,
  • View books in library,
  • Reserving a book,
  • Give away a book,
  • Give back a book,
  • View reservations.

Description

Api of library., (*3)

//...

interface Library
{
    /**
     * @param UuidInterface $bookId
     * @param string        $title
     * @param string        $authors
     * @param string        $isbn
     */
    public function addBook(UuidInterface $bookId, $title, $authors, $isbn);

    /**
     * @param int  $page
     * @param null $booksPerPage
     *
     * @return BookView[]
     */
    public function listOfBooks($page = 1, $booksPerPage = null);

    /**
     * @param UuidInterface $reservationId
     * @param UuidInterface $bookId
     * @param string        $email
     */
    public function createReservation(UuidInterface $reservationId, UuidInterface $bookId, $email);

    /**
     * @param UuidInterface $reservationId
     * @param \DateTime     $givenAwayAt
     *
     * @throws BookInReservationAlreadyGivenAway
     */
    public function giveAwayBookInReservation(UuidInterface $reservationId, \DateTime $givenAwayAt);

    /**
     * @param UuidInterface $reservationId
     * 
     * @throws CannotGiveBackReservationWhichWasNotGivenAway
     */
    public function giveBackBookFromReservation(UuidInterface $reservationId);

    /**
     * @param UuidInterface $bookId
     *
     * @return ReservationView[]
     */
    public function listReservationsForBook(UuidInterface $bookId);
}

This interface is implement by Clearcode\EHLibrary\Application class., (*4)

Example

Example of adding book to library., (*5)

//..
namespace Clearcode;

use Clearcode\EHLibrary\Application;
use Ramsey\Uuid\Uuid;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class Controller
{
    public function addBookToLibraryAction(Request $request)
    {
        $bookId = Uuid::fromString($request->request->get('bookId'));

        //Library implementation
        $app = new Application();
        $app->addBook($bookId, $request->request->get('title'), $request->request->get('authors'), $request->request->get('isbn'));

        return new Response(json_encode(['id' => (string) $bookId]), 201);
    }
}

The Versions

03/12 2015

dev-master

9999999-dev

Model and use cases for rest api course

  Sources   Download

MIT

The Requires

 

The Development Requires