clearcode / eh-library
Model and use cases for rest api course
dev-master
2015-12-03 11:38 UTC
Requires
- php: >=5.5
- everzet/persisted-objects: ~1.0
- ramsey/uuid: ~3.0
Requires (Dev)
- behat/behat: ~2.5
- phpunit/phpunit: ~4.5
- satooshi/php-coveralls: ^0.6.1
This package is not auto-updated.
Last update: 2024-12-21 19:16:18 UTC
README
EH-library Application for rest api course
This repository is a simple model which could be used to build REST API.
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.
//... 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.
Example
Example of adding book to library.
//.. 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); } }