https://github.com/clearcodehq/eh-library
https://github.com/clearcodehq/eh-library
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/clearcodehq/eh-library
- Owner: ClearcodeHQ
- License: mit
- Created: 2015-11-26T11:14:03.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-03T22:21:33.000Z (over 10 years ago)
- Last Synced: 2025-03-30T13:37:08.570Z (about 1 year ago)
- Language: PHP
- Size: 92.8 KB
- Stars: 1
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/ClearcodeHQ/eh-library)
[](https://coveralls.io/github/ClearcodeHQ/eh-library?branch=master)
[](https://scrutinizer-ci.com/g/ClearcodeHQ/eh-library/?branch=master)
[](https://www.versioneye.com/user/projects/565c16c64052e8003b00000e)
# EH-library Application for rest api course
This repository is a simple model which could be used to build REST API.
## Requirements
```json
"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.
```php
//...
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.
```php
//..
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);
}
}
```