Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
24 changes: 24 additions & 0 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -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: /lending/

library:
resource: './routes/library.yml'
prefix: /library/

reader:
resource: './routes/reader.yml'
prefix: /reader/
38 changes: 38 additions & 0 deletions config/routes/book.yml
Original file line number Diff line number Diff line change
@@ -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+
30 changes: 30 additions & 0 deletions config/routes/category.yml
Original file line number Diff line number Diff line change
@@ -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+
30 changes: 30 additions & 0 deletions config/routes/copy.yml
Original file line number Diff line number Diff line change
@@ -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+
30 changes: 30 additions & 0 deletions config/routes/lending.yml
Original file line number Diff line number Diff line change
@@ -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+
30 changes: 30 additions & 0 deletions config/routes/library.yml
Original file line number Diff line number Diff line change
@@ -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+
30 changes: 30 additions & 0 deletions config/routes/reader.yml
Original file line number Diff line number Diff line change
@@ -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+
80 changes: 80 additions & 0 deletions src/Controller/BookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php


namespace Alexandrie\Controller;


use Alexandrie\Entity\Book;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class BookController extends AbstractController implements ObjectController {

public function displayAll() {
$book = $this->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);
}
}
67 changes: 67 additions & 0 deletions src/Controller/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php


namespace Alexandrie\Controller;


use Alexandrie\Entity\Category;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

class CategoryController extends AbstractController implements ObjectController {

public function displayAll() {
$category = $this->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);
}
}
Loading