From 1121a3db7d5cbc35e98f36b02e4dcd01fa6ccce0 Mon Sep 17 00:00:00 2001 From: Dorian Date: Fri, 20 Dec 2019 11:18:51 +0100 Subject: [PATCH 1/3] first commit --- .env | 2 +- composer.json | 1 + config/routes.yaml | 24 ++++ config/routes/book.yml | 38 ++++++ config/routes/category.yml | 30 +++++ config/routes/copy.yml | 30 +++++ config/routes/lending.yml | 30 +++++ config/routes/library.yml | 30 +++++ config/routes/reader.yml | 30 +++++ src/Controller/BookController.php | 80 ++++++++++++ src/Controller/CategoryController.php | 67 ++++++++++ src/Controller/CopyController.php | 67 ++++++++++ src/Controller/LendingController.php | 101 ++++++++++++++++ src/Controller/LibraryController.php | 61 ++++++++++ src/Controller/ObjectController.php | 18 +++ src/Controller/ReaderController.php | 90 ++++++++++++++ src/Entity/Book.php | 90 ++++++++++++++ src/Entity/Category.php | 79 ++++++++++++ src/Entity/Copy.php | 74 ++++++++++++ src/Entity/Lending.php | 114 ++++++++++++++++++ src/Entity/Library.php | 51 ++++++++ src/Entity/Reader.php | 110 +++++++++++++++++ src/Repository/BookRepository.php | 10 ++ src/Repository/CategoryRepository.php | 11 ++ src/Repository/CopyRepository.php | 11 ++ src/Repository/LendingRepository.php | 11 ++ src/Repository/LibraryRepository.php | 11 ++ src/Repository/ReaderRepository.php | 10 ++ src/Services/Normalizer/BookSerializer.php | 51 ++++++++ .../Normalizer/CategorySerializer.php | 49 ++++++++ src/Services/Normalizer/CopySerializer.php | 48 ++++++++ src/Services/Normalizer/LendingSerializer.php | 50 ++++++++ src/Services/Normalizer/LibrarySerializer.php | 47 ++++++++ src/Services/Normalizer/ReaderSerializer.php | 50 ++++++++ 34 files changed, 1575 insertions(+), 1 deletion(-) create mode 100644 config/routes/book.yml create mode 100644 config/routes/category.yml create mode 100644 config/routes/copy.yml create mode 100644 config/routes/lending.yml create mode 100644 config/routes/library.yml create mode 100644 config/routes/reader.yml create mode 100644 src/Controller/BookController.php create mode 100644 src/Controller/CategoryController.php create mode 100644 src/Controller/CopyController.php create mode 100644 src/Controller/LendingController.php create mode 100644 src/Controller/LibraryController.php create mode 100644 src/Controller/ObjectController.php create mode 100644 src/Controller/ReaderController.php create mode 100644 src/Entity/Book.php create mode 100644 src/Entity/Category.php create mode 100644 src/Entity/Copy.php create mode 100644 src/Entity/Lending.php create mode 100644 src/Entity/Library.php create mode 100644 src/Entity/Reader.php create mode 100644 src/Repository/BookRepository.php create mode 100644 src/Repository/CategoryRepository.php create mode 100644 src/Repository/CopyRepository.php create mode 100644 src/Repository/LendingRepository.php create mode 100644 src/Repository/LibraryRepository.php create mode 100644 src/Repository/ReaderRepository.php create mode 100644 src/Services/Normalizer/BookSerializer.php create mode 100644 src/Services/Normalizer/CategorySerializer.php create mode 100644 src/Services/Normalizer/CopySerializer.php create mode 100644 src/Services/Normalizer/LendingSerializer.php create mode 100644 src/Services/Normalizer/LibrarySerializer.php create mode 100644 src/Services/Normalizer/ReaderSerializer.php diff --git a/.env b/.env index 770e95c..39f93f2 100644 --- a/.env +++ b/.env @@ -25,5 +25,5 @@ APP_SECRET=245b1a7e18e24e1a284f7253cae8b0d0 # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db" # For a PostgreSQL database, use: "postgresql://db_user:db_password@127.0.0.1:5432/db_name?serverVersion=11&charset=utf8" # IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml -DATABASE_URL=mysql://user:password@163.172.173.245:3306/db_name +DATABASE_URL=mysql://lp23:lp23@163.172.173.245:3306/lp23 ###< doctrine/doctrine-bundle ### diff --git a/composer.json b/composer.json index c3c2f80..fd9a649 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "symfony/flex": "^1.3.1", "symfony/framework-bundle": "5.0.*", "symfony/orm-pack": "^1.0", + "symfony/serializer-pack": "^1.0", "symfony/yaml": "5.0.*" }, "require-dev": { diff --git a/config/routes.yaml b/config/routes.yaml index e43eb95..363bc27 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -1,3 +1,27 @@ #index: # path: / # controller: Alexandrie\Controller\DefaultController::index + +book: + resource: './routes/book.yml' + prefix: /book/ + +category: + resource: './routes/category.yml' + prefix: /category/ + +copy: + resource: './routes/copy.yml' + prefix: /copy/ + +lending: + resource: './routes/lending.yml' + prefix: /category/ + +library: + resource: './routes/library.yml' + prefix: /category/ + +reader: + resource: './routes/reader.yml' + prefix: /reader/ \ No newline at end of file diff --git a/config/routes/book.yml b/config/routes/book.yml new file mode 100644 index 0000000..007be4e --- /dev/null +++ b/config/routes/book.yml @@ -0,0 +1,38 @@ + +book-display-all: + path: / + controller: Alexandrie\Controller\BookController::displayAll + methods: GET + +book-add: + path: / + controller: Alexandrie\Controller\BookController::add + methods: PUT + +book-display: + path: /{id} + controller: Alexandrie\Controller\BookController::display + methods: GET + requirements: + id: \d+ + +book-update: + path: /{id} + controller: Alexandrie\Controller\BookController::update + methods: PATCH + requirements: + id: \d+ + +book-delete: + path: /{id} + controller: Alexandrie\Controller\BookController::delete + methods: DELETE + requirements: + id: \d+ + +book-readers: + path: /book/{id}/readers + controller: Alexandrie\Controller\BookController::getReaders + methods: GET + requirements: + id: \d+ \ No newline at end of file diff --git a/config/routes/category.yml b/config/routes/category.yml new file mode 100644 index 0000000..e579e04 --- /dev/null +++ b/config/routes/category.yml @@ -0,0 +1,30 @@ +category-display-all: + path: / + controller: Alexandrie\Controller\CategoryController::displayAll + methods: GET + +category-add: + path: / + controller: Alexandrie\Controller\CategoryController::add + methods: PUT + +category-display: + path: /{id} + controller: Alexandrie\Controller\CategoryController::display + methods: GET + requirements: + id: \d+ + +category-update: + path: /{id} + controller: Alexandrie\Controller\CategoryController::update + methods: PATCH + requirements: + id: \d+ + +category-delete: + path: /{id} + controller: Alexandrie\Controller\CategoryController::delete + methods: DELETE + requirements: + id: \d+ \ No newline at end of file diff --git a/config/routes/copy.yml b/config/routes/copy.yml new file mode 100644 index 0000000..230f896 --- /dev/null +++ b/config/routes/copy.yml @@ -0,0 +1,30 @@ +copy-display-all: + path: / + controller: Alexandrie\Controller\CopyController::displayAll + methods: GET + +copy-add: + path: / + controller: Alexandrie\Controller\CopyController::add + methods: PUT + +copy-display: + path: /{id} + controller: Alexandrie\Controller\CopyController::display + methods: GET + requirements: + id: \d+ + +copy-update: + path: /{id} + controller: Alexandrie\Controller\CopyController::update + methods: PATCH + requirements: + id: \d+ + +copy-delete: + path: /{id} + controller: Alexandrie\Controller\CopyController::delete + methods: DELETE + requirements: + id: \d+ \ No newline at end of file diff --git a/config/routes/lending.yml b/config/routes/lending.yml new file mode 100644 index 0000000..c335881 --- /dev/null +++ b/config/routes/lending.yml @@ -0,0 +1,30 @@ +lending-display-all: + path: / + controller: Alexandrie\Controller\LendingController::displayAll + methods: GET + +lending-add: + path: / + controller: Alexandrie\Controller\LendingController::add + methods: PUT + +lending-display: + path: /{id} + controller: Alexandrie\Controller\LendingController::display + methods: GET + requirements: + id: \d+ + +lending-update: + path: /{id} + controller: Alexandrie\Controller\LendingController::update + methods: PATCH + requirements: + id: \d+ + +lending-delete: + path: /{id} + controller: Alexandrie\Controller\LendingController::delete + methods: DELETE + requirements: + id: \d+ \ No newline at end of file diff --git a/config/routes/library.yml b/config/routes/library.yml new file mode 100644 index 0000000..9b07e50 --- /dev/null +++ b/config/routes/library.yml @@ -0,0 +1,30 @@ +library-display-all: + path: / + controller: Alexandrie\Controller\BookController::displayAll + methods: GET + +library-add: + path: / + controller: Alexandrie\Controller\BookController::add + methods: PUT + +library-display: + path: /{id} + controller: Alexandrie\Controller\BookController::display + methods: GET + requirements: + id: \d+ + +library-update: + path: /{id} + controller: Alexandrie\Controller\BookController::update + methods: PATCH + requirements: + id: \d+ + +library-delete: + path: /{id} + controller: Alexandrie\Controller\BookController::delete + methods: DELETE + requirements: + id: \d+ \ No newline at end of file diff --git a/config/routes/reader.yml b/config/routes/reader.yml new file mode 100644 index 0000000..deeafff --- /dev/null +++ b/config/routes/reader.yml @@ -0,0 +1,30 @@ +reader-display-all: + path: / + controller: Alexandrie\Controller\BookController::displayAll + methods: GET + +reader-add: + path: / + controller: Alexandrie\Controller\BookController::add + methods: PUT + +reader-display: + path: /{id} + controller: Alexandrie\Controller\BookController::display + methods: GET + requirements: + id: \d+ + +reader-update: + path: /{id} + controller: Alexandrie\Controller\BookController::update + methods: PATCH + requirements: + id: \d+ + +reader-delete: + path: /{id} + controller: Alexandrie\Controller\BookController::delete + methods: DELETE + requirements: + id: \d+ \ No newline at end of file diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php new file mode 100644 index 0000000..b6162bc --- /dev/null +++ b/src/Controller/BookController.php @@ -0,0 +1,80 @@ +getDoctrine() + ->getRepository(Book::class) + ->findAll(); + return $this->json($book,200); + } + + public function display(int $id) { + $book = $this->getDoctrine() + ->getRepository(Book::class) + ->find($id); + if (!$book) { + return $this->createNotFoundException(); + } + return $this->json($book,200); + } + + public function getReaders($id) { + $book = $this->getDoctrine()->getRepository(Book::class)->find($id); + if (!$book) { + return $this->createNotFoundException(); + } + } + + public function delete(int $id) { + $book = $this->getDoctrine() + ->getRepository(Book::class) + ->find($id); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($book); + $entityManager->flush(); + return $this->json([], 204); + } + + public function update(Request $request, int $id) { + $manager = $this->getDoctrine()->getManager(); + $book = $manager->getRepository(Book::class)->find($id); + $name = $request->get("name"); + $isbn = $request->get("isbn"); + $categoryId = $request->get("categoryId"); + + if ($name != null) { + $book->setName($name); + } + if ($isbn != null) { + $book->setIsbn($isbn); + } + if ($categoryId != null) { + $book->setCategoryId($categoryId); + } + $manager->flush(); + return $this->json($book,200); + } + + public function add(Request $request) { + $manager = $this->getDoctrine()->getManager(); + $name = $request->get("name"); + $isbn = $request->get("isbn"); + $categoryId = $request->get("categoryId"); + $book = new Book(); + $book->setName($name); + $book->setIsbn($isbn); + $book->setCategoryId($categoryId); + $manager->persist($book); + $manager->flush(); + return $this->json($book,201); + } +} \ No newline at end of file diff --git a/src/Controller/CategoryController.php b/src/Controller/CategoryController.php new file mode 100644 index 0000000..e26749b --- /dev/null +++ b/src/Controller/CategoryController.php @@ -0,0 +1,67 @@ +getDoctrine() + ->getRepository(Category::class) + ->findAll(); + return $this->json($category); + } + + public function display(int $id) { + $category = $this->getDoctrine() + ->getRepository(Category::class) + ->find($id); + if (!$category) { + return $this->createNotFoundException(); + } + return $this->json($category,200); + } + + public function delete(int $id) { + $category = $this->getDoctrine() + ->getRepository(Category::class) + ->find($id); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($category); + $entityManager->flush(); + return $this->json([], 204); + } + + public function update(Request $request, int $id) { + $manager = $this->getDoctrine()->getManager(); + $category = $manager->getRepository(Category::class)->find($id); + $code = $request->get("code"); + $label = $request->get("label"); + + if ($code != null) { + $category->setCode($code); + } + if ($label != null) { + $category->setLabel($label); + } + $manager->flush(); + return $this->json($category,200); + } + + public function add(Request $request) { + $manager = $this->getDoctrine()->getManager(); + $code = $request->get("code"); + $label = $request->get("label"); + $category = new Category(); + $category->setCode($code); + $category->setLabel($label); + $manager->persist($category); + $manager->flush(); + return $this->json($category,201); + } +} \ No newline at end of file diff --git a/src/Controller/CopyController.php b/src/Controller/CopyController.php new file mode 100644 index 0000000..03f56b2 --- /dev/null +++ b/src/Controller/CopyController.php @@ -0,0 +1,67 @@ +getDoctrine() + ->getRepository(Copy::class) + ->findAll(); + return $this->json($copy); + } + + public function display(int $id) { + $copy = $this->getDoctrine() + ->getRepository(Copy::class) + ->find($id); + if (!$copy) { + return $this->createNotFoundException(); + } + return $this->json($copy,200); + } + + public function delete(int $id) { + $copy = $this->getDoctrine() + ->getRepository(Copy::class) + ->find($id); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($copy); + $entityManager->flush(); + return $this->json([], 204); + } + + public function update(Request $request, int $id) { + $manager = $this->getDoctrine()->getManager(); + $copy = $manager->getRepository(Copy::class)->find($id); + $bookId = $request->get("bookId"); + $libraryId = $request->get("libraryId"); + + if ($bookId != null) { + $copy->setBookId($bookId); + } + if ($libraryId != null) { + $copy->setLibraryId($libraryId); + } + $manager->flush(); + return $this->json($copy,200); + } + + public function add(Request $request) { + $manager = $this->getDoctrine()->getManager(); + $bookId = $request->get("bookId"); + $libraryId = $request->get("libraryId"); + $copy = new Copy(); + $copy->setBookId($bookId); + $copy->setLibraryId($libraryId); + $manager->persist($copy); + $manager->flush(); + return $this->json($copy,201); + } +} \ No newline at end of file diff --git a/src/Controller/LendingController.php b/src/Controller/LendingController.php new file mode 100644 index 0000000..f5cc412 --- /dev/null +++ b/src/Controller/LendingController.php @@ -0,0 +1,101 @@ +getDoctrine() + ->getRepository(Lending::class) + ->findAll(); + return $this->json($lending); + } + + public function display(int $id) { + $lending = $this->getDoctrine() + ->getRepository(Lending::class) + ->find($id); + if (!$lending) { + return $this->createNotFoundException(); + } + return $this->json($lending,200); + } + + public function delete(int $id) { + $lending = $this->getDoctrine() + ->getRepository(Lending::class) + ->find($id); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($lending); + $entityManager->flush(); + return $this->json([], 204); + } + + public function update(Request $request, int $id) { + $manager = $this->getDoctrine()->getManager(); + $lending = $manager->getRepository(Lending::class)->find($id); + $copyId = $request->get("copyId"); + $readerId = $request->get("readerId"); + $startDate = $request->get("startDate"); + $endDate = $request->get("endDate"); + + if ($copyId != null) { + $lending->setCopyId($copyId); + } + if ($readerId != null) { + $lending->setReaderId($readerId); + } + if ($startDate != null) { + try { + $formatedStartDate = new DateTime($startDate); + $lending->setStartDate($formatedStartDate->format('Y-m-d')); + } catch (\Exception $e) { + return $this->json("startDate format not correct", 409); + } + } + if ($endDate != null) { + try { + $formatedEndDate = new DateTime($endDate); + $lending->setEndDate($formatedEndDate->format('Y-m-d')); + } catch (\Exception $e) { + return $this->json("EndDate format not correct", 409); + } + } + $manager->flush(); + return $this->json($lending,200); + } + + public function add(Request $request) { + $manager = $this->getDoctrine()->getManager(); + $copyId = $request->get("copyId"); + $readerId = $request->get("readerId"); + $startDate = $request->get("startDate"); + $endDate = $request->get("endDate"); + try { + $formattedStartDate = new DateTime($startDate); + } catch (\Exception $e) { + return $this->json("StartDate format not correct", 409); + } + + try { + $formattedEndDate = new DateTime($endDate); + } catch (\Exception $e) { + return $this->json("EndDate format not correct", 409); + } + $lending = new Lending(); + $lending->setCopyId($copyId); + $lending->setReaderId($readerId); + $lending->setStartDate($formattedStartDate); + $lending->setEndDate($formattedEndDate); + $manager->persist($lending); + $manager->flush(); + return $this->json($lending,201); + } +} \ No newline at end of file diff --git a/src/Controller/LibraryController.php b/src/Controller/LibraryController.php new file mode 100644 index 0000000..6f08813 --- /dev/null +++ b/src/Controller/LibraryController.php @@ -0,0 +1,61 @@ +getDoctrine() + ->getRepository(Library::class) + ->findAll(); + return $this->json($library); + } + + public function display(int $id) { + $library = $this->getDoctrine() + ->getRepository(Library::class) + ->find($id); + if (!$library) { + return $this->createNotFoundException(); + } + return $this->json($library,200); + } + + public function delete(int $id) { + $library = $this->getDoctrine() + ->getRepository(Library::class) + ->find($id); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($library); + $entityManager->flush(); + return $this->json([], 204); + } + + public function update(Request $request, int $id) { + $manager = $this->getDoctrine()->getManager(); + $library = $manager->getRepository(Library::class)->find($id); + $name = $request->get("name"); + + if ($name != null) { + $library->setName($name); + } + $manager->flush(); + return $this->json($library,200); + } + + public function add(Request $request) { + $manager = $this->getDoctrine()->getManager(); + $name = $request->get("name"); + $library = new Library(); + $library->setName($name); + $manager->persist($library); + $manager->flush(); + return $this->json($library,201); + } +} \ No newline at end of file diff --git a/src/Controller/ObjectController.php b/src/Controller/ObjectController.php new file mode 100644 index 0000000..4c1e8b8 --- /dev/null +++ b/src/Controller/ObjectController.php @@ -0,0 +1,18 @@ +getDoctrine() + ->getRepository(Reader::class) + ->findAll(); + return $this->json($reader); + } + + public function display(int $id) { + $reader = $this->getDoctrine() + ->getRepository(Reader::class) + ->find($id); + if (!$reader) { + return $this->createNotFoundException(); + } + return $this->json($reader,200); + } + + public function delete(int $id) { + $reader = $this->getDoctrine() + ->getRepository(Reader::class) + ->find($id); + $entityManager = $this->getDoctrine()->getManager(); + $entityManager->remove($reader); + $entityManager->flush(); + return $this->json([], 204); + } + + public function update(Request $request, int $id) { + $manager = $this->getDoctrine()->getManager(); + $reader = $manager->getRepository(Reader::class)->find($id); + $firstName = $request->get("firstName"); + $lastName = $request->get("lastName"); + $birthDate = $request->get("birthDate"); + $email = $request->get("email"); + + if ($firstName != null) { + $reader->setFirstName($firstName); + } + if ($lastName != null) { + $reader->setLastName($lastName); + } + if ($birthDate != null) { + try { + $formatteBirthDate = new DateTime($birthDate); + $reader->setBirthDate($formatteBirthDate->format('Y-m-d')); + } catch (\Exception $e) { + return $this->json("BirthDate format not correct", 409); + } + } + if ($email != null) { + $reader->setEmail($email); + } + $manager->flush(); + return $this->json($reader,200); + } + + public function add(Request $request) { + $manager = $this->getDoctrine()->getManager(); + $firstName = $request->get("firstName"); + $lastName = $request->get("lastName"); + $birthDate = $request->get("birthDate"); + $email = $request->get("email"); + try { + $formatteBirthDate = new DateTime($birthDate); + } catch (\Exception $e) { + return $this->json("BirthDate format not correct", 409); + } + $reader = new Reader(); + $reader->setFirtName($firstName); + $reader->setLastName($lastName); + $reader->setBirthDate($formatteBirthDate->format('Y-m-d')); + $reader->setEmail($email); + $manager->persist($reader); + $manager->flush(); + return $this->json($reader,201); + } +} \ No newline at end of file diff --git a/src/Entity/Book.php b/src/Entity/Book.php new file mode 100644 index 0000000..4a367d9 --- /dev/null +++ b/src/Entity/Book.php @@ -0,0 +1,90 @@ +id; + } + + /** + * @param mixed $name + */ + public function setName($name): void + { + $this->name = $name; + } + + /** + * @param mixed $isbn + */ + public function setIsbn($isbn): void + { + $this->isbn = $isbn; + } + + /** + * @param $categoryId + */ + public function setCategoryId($categoryId): void + { + $this->categoryId = $categoryId; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @return mixed + */ + public function getIsbn() + { + return $this->isbn; + } + + /** + * @return mixed + */ + public function getCategoryId() + { + return $this->categoryId; + } + + +} \ No newline at end of file diff --git a/src/Entity/Category.php b/src/Entity/Category.php new file mode 100644 index 0000000..1bb2585 --- /dev/null +++ b/src/Entity/Category.php @@ -0,0 +1,79 @@ +id; + } + + /** + * @return mixed + */ + public function getCode() + { + return $this->code; + } + + /** + * @return mixed + */ + public function getLabel() + { + return $this->label; + } + + /** + * @param mixed $id + */ + public function setId($id): void + { + $this->id = $id; + } + /** + * @param mixed $code + */ + public function setCode($code): void + { + $this->code = $code; + } + + /** + * @param mixed $label + */ + public function setLabel($label): void + { + $this->label = $label; + } + + + + +} \ No newline at end of file diff --git a/src/Entity/Copy.php b/src/Entity/Copy.php new file mode 100644 index 0000000..22c4b99 --- /dev/null +++ b/src/Entity/Copy.php @@ -0,0 +1,74 @@ +id; + } + + /** + * @return mixed + */ + public function getBookId() + { + return $this->bookId; + } + + /** + * @return mixed + */ + public function getLibraryId() + { + return $this->libraryId; + } + + /** + * @param mixed $bookId + */ + public function setBookId($bookId): void + { + $this->bookId = $bookId; + } + + /** + * @param mixed $libraryId + */ + public function setLibraryId($libraryId): void + { + $this->libraryId = $libraryId; + } + + + + + +} \ No newline at end of file diff --git a/src/Entity/Lending.php b/src/Entity/Lending.php new file mode 100644 index 0000000..a6649dd --- /dev/null +++ b/src/Entity/Lending.php @@ -0,0 +1,114 @@ +id; + } + + /** + * @return mixed + */ + public function getCopyId() + { + return $this->copyId; + } + + /** + * @return mixed + */ + public function getReaderId() + { + return $this->readerId; + } + + /** + * @return mixed + */ + public function getStartDate() + { + return $this->startDate; + } + + /** + * @return mixed + */ + public function getEndDate() + { + return $this->endDate; + } + + /** + * @param mixed $copyId + */ + public function setCopyId($copyId): void + { + $this->copyId = $copyId; + } + + /** + * @param mixed $readerId + */ + public function setReaderId($readerId): void + { + $this->readerId = $readerId; + } + + /** + * @param mixed $startDate + */ + public function setStartDate($startDate): void + { + $this->startDate = $startDate; + } + + /** + * @param mixed $endDate + */ + public function setEndDate($endDate): void + { + $this->endDate = $endDate; + } + + + + + +} \ No newline at end of file diff --git a/src/Entity/Library.php b/src/Entity/Library.php new file mode 100644 index 0000000..27ac123 --- /dev/null +++ b/src/Entity/Library.php @@ -0,0 +1,51 @@ +id; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @param mixed $name + */ + public function setName($name): void + { + $this->name = $name; + } + + +} \ No newline at end of file diff --git a/src/Entity/Reader.php b/src/Entity/Reader.php new file mode 100644 index 0000000..75c9634 --- /dev/null +++ b/src/Entity/Reader.php @@ -0,0 +1,110 @@ +id; + } + + /** + * @return mixed + */ + public function getFirtName() + { + return $this->firtName; + } + + /** + * @return mixed + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * @return mixed + */ + public function getBirthDate() + { + return $this->birthDate; + } + + /** + * @return mixed + */ + public function getEmail() + { + return $this->email; + } + + /** + * @param mixed $firtName + */ + public function setFirtName($firtName): void + { + $this->firtName = $firtName; + } + + /** + * @param mixed $lastName + */ + public function setLastName($lastName): void + { + $this->lastName = $lastName; + } + + /** + * @param mixed $birthDate + */ + public function setBirthDate($birthDate): void + { + $this->birthDate = $birthDate; + } + + /** + * @param mixed $email + */ + public function setEmail($email): void + { + $this->email = $email; + } + + +} \ No newline at end of file diff --git a/src/Repository/BookRepository.php b/src/Repository/BookRepository.php new file mode 100644 index 0000000..df4c513 --- /dev/null +++ b/src/Repository/BookRepository.php @@ -0,0 +1,10 @@ +id = $object->getId(); + $data->name = $object->getName(); + $data->isbn = $object->getIsbn(); + $data->categoryId = $object->getCategoryId(); + return $data; + } +} \ No newline at end of file diff --git a/src/Services/Normalizer/CategorySerializer.php b/src/Services/Normalizer/CategorySerializer.php new file mode 100644 index 0000000..4bb499d --- /dev/null +++ b/src/Services/Normalizer/CategorySerializer.php @@ -0,0 +1,49 @@ +id = $object->getId(); + $data->code = $object->getCode(); + $data->label = $object->getLabel(); + return $data; + } + +} \ No newline at end of file diff --git a/src/Services/Normalizer/CopySerializer.php b/src/Services/Normalizer/CopySerializer.php new file mode 100644 index 0000000..539e1a9 --- /dev/null +++ b/src/Services/Normalizer/CopySerializer.php @@ -0,0 +1,48 @@ +id = $object->getId(); + $data->book = $object->getBookId(); + $data->library = $object->getLibraryId(); + return $data; + } +} \ No newline at end of file diff --git a/src/Services/Normalizer/LendingSerializer.php b/src/Services/Normalizer/LendingSerializer.php new file mode 100644 index 0000000..6d83407 --- /dev/null +++ b/src/Services/Normalizer/LendingSerializer.php @@ -0,0 +1,50 @@ +id = $object->getId(); + $data->copy = $object->getCopyId(); + $data->reader = $object->getReaderId(); + $data->startDate = $object->getStartDate(); + $data->endDate = $object->getEndDate(); + return $data; + } +} \ No newline at end of file diff --git a/src/Services/Normalizer/LibrarySerializer.php b/src/Services/Normalizer/LibrarySerializer.php new file mode 100644 index 0000000..58e4b04 --- /dev/null +++ b/src/Services/Normalizer/LibrarySerializer.php @@ -0,0 +1,47 @@ +id = $object->getId(); + $data->name = $object->getName(); + return $data; + } +} \ No newline at end of file diff --git a/src/Services/Normalizer/ReaderSerializer.php b/src/Services/Normalizer/ReaderSerializer.php new file mode 100644 index 0000000..da4aca0 --- /dev/null +++ b/src/Services/Normalizer/ReaderSerializer.php @@ -0,0 +1,50 @@ +id = $object->getId(); + $data->firstName = $object->getFirstName(); + $data->lastName = $object->getLastName(); + $data->birthDate = $object->getBirthDate(); + $data->email = $object->getEmail(); + return $data; + } +} \ No newline at end of file From 6aa814db1b47034eae1734026016653fb6988a12 Mon Sep 17 00:00:00 2001 From: Dorian Date: Fri, 20 Dec 2019 11:35:28 +0100 Subject: [PATCH 2/3] Correction de prefix --- config/routes.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/routes.yaml b/config/routes.yaml index 363bc27..9b42df5 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -16,11 +16,11 @@ copy: lending: resource: './routes/lending.yml' - prefix: /category/ + prefix: /lending/ library: resource: './routes/library.yml' - prefix: /category/ + prefix: /library/ reader: resource: './routes/reader.yml' From 712f080f4bb2a2f3ad5901826f87a8338a988f5e Mon Sep 17 00:00:00 2001 From: Dorian Date: Fri, 20 Dec 2019 11:44:50 +0100 Subject: [PATCH 3/3] Correction de prefix --- src/Controller/LendingController.php | 12 ++++++------ src/Controller/ReaderController.php | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Controller/LendingController.php b/src/Controller/LendingController.php index f5cc412..f232aa0 100644 --- a/src/Controller/LendingController.php +++ b/src/Controller/LendingController.php @@ -54,16 +54,16 @@ public function update(Request $request, int $id) { } if ($startDate != null) { try { - $formatedStartDate = new DateTime($startDate); - $lending->setStartDate($formatedStartDate->format('Y-m-d')); + $formatedStartDate = DateTime::createFromFormat("Y-m-d",$startDate); + $lending->setStartDate($formatedStartDate); } catch (\Exception $e) { return $this->json("startDate format not correct", 409); } } if ($endDate != null) { try { - $formatedEndDate = new DateTime($endDate); - $lending->setEndDate($formatedEndDate->format('Y-m-d')); + $formatedEndDate = DateTime::createFromFormat("Y-m-d",$startDate);; + $lending->setEndDate($formatedEndDate); } catch (\Exception $e) { return $this->json("EndDate format not correct", 409); } @@ -79,13 +79,13 @@ public function add(Request $request) { $startDate = $request->get("startDate"); $endDate = $request->get("endDate"); try { - $formattedStartDate = new DateTime($startDate); + $formattedStartDate = DateTime::createFromFormat("Y-m-d",$startDate); } catch (\Exception $e) { return $this->json("StartDate format not correct", 409); } try { - $formattedEndDate = new DateTime($endDate); + $formattedEndDate = DateTime::createFromFormat("Y-m-d",$endDate); } catch (\Exception $e) { return $this->json("EndDate format not correct", 409); } diff --git a/src/Controller/ReaderController.php b/src/Controller/ReaderController.php index f6749d9..6fafdbe 100644 --- a/src/Controller/ReaderController.php +++ b/src/Controller/ReaderController.php @@ -54,8 +54,8 @@ public function update(Request $request, int $id) { } if ($birthDate != null) { try { - $formatteBirthDate = new DateTime($birthDate); - $reader->setBirthDate($formatteBirthDate->format('Y-m-d')); + $formatteBirthDate = DateTime::createFromFormat("Y-m-d",$birthDate); + $reader->setBirthDate($formatteBirthDate); } catch (\Exception $e) { return $this->json("BirthDate format not correct", 409); } @@ -74,7 +74,7 @@ public function add(Request $request) { $birthDate = $request->get("birthDate"); $email = $request->get("email"); try { - $formatteBirthDate = new DateTime($birthDate); + $formatteBirthDate = DateTime::createFromFormat("Y-m-d",$birthDate); } catch (\Exception $e) { return $this->json("BirthDate format not correct", 409); }