Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review 1 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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: 2 additions & 0 deletions config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#index:
# path: /
# controller: App\Controller\DefaultController::index


5 changes: 5 additions & 0 deletions config/routes/library.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


app_welcome:
path: /library
controller: App\Controller\LibraryController::libraryAction
112 changes: 112 additions & 0 deletions src/Controller/AuthorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace App\Controller;

use App\Entity\Author;
use App\Form\AuthorType;
use App\Repository\AuthorRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;


/**
* @Route("/author")
*/
class AuthorController extends AbstractController
{
/**
* @Route("/", name="author_index", methods={"GET"})
*/
public function index(AuthorRepository $authorRepository): Response
{
return $this->render('author/index.html.twig', [
'authors' => $authorRepository->findAll(),
]);
}

/**
* @Route("/new", name="author_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$author = new author();
$form = $this->createForm(AuthorType::class, $author);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($author);
$entityManager->flush();

$this->addFlash('notice',
' Author was added!');

return $this->redirectToRoute('author_index');
}

return $this->render('author/new.html.twig', [
'author' => $author,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="author_show", methods={"GET"})
*/
public function show(Author $author): Response
{

$this->addFlash('notice',
'This is your author!');

return $this->render('author/show.html.twig', [
'author' => $author,
]);
}

/**
* @Route("/{id}/edit", name="author_edit", methods={"GET","POST"})
*/
public function edit(Request $request, Author $author): Response
{
$form = $this->createForm(AuthorType::class, $author);
$form->handleRequest($request);


if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();

$this->addFlash('notice',
'Your changes about an author have been saved!');


return $this->redirectToRoute('author_index', [
'id' => $author->getId(),
]);
}

return $this->render('author/edit.html.twig', [
'author' => $author,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="author_delete", methods={"DELETE"})
*/
public function delete(Request $request, Author $author): Response
{
if ($this->isCsrfTokenValid('delete'.$author->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($author);
$entityManager->flush();

$this->addFlash('notice',
'You have been deleted an author!');
}

return $this->redirectToRoute('author_index');
}
}
114 changes: 114 additions & 0 deletions src/Controller/BookController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

namespace App\Controller;

use App\Entity\Book;
use App\Form\BookType;
use App\Repository\BookRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
* @Route("/book")
*/
class BookController extends AbstractController
{
/**
* @Route("/", name="book_index", methods={"GET"})
*/
public function index(BookRepository $bookRepository): Response
{
return $this->render('book/index.html.twig', [
'books' => $bookRepository->findAll(),
]);
}

/**
* @Route("/new", name="book_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$book = new Book();
$form = $this->createForm(BookType::class, $book);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($book);
$entityManager->flush();




return $this->redirectToRoute('book_index');
}

return $this->render('book/new.html.twig', [
'book' => $book,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="book_show", methods={"GET"})
*/
public function show(Book $book): Response
{

$this->addFlash('notice',
'This is your book!'

);

return $this->render('book/show.html.twig', [
'book' => $book,
]);
}

/**
* @Route("/{id}/edit", name="book_edit", methods={"GET","POST"})
*/
public function edit(Request $request, Book $book): Response
{
$form = $this->createForm(BookType::class, $book);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();

$this->addFlash('notice',
'Book has been edited!'
);

return $this->redirectToRoute('book_index', [
'id' => $book->getId(),
]);
}

return $this->render('book/edit.html.twig', [
'book' => $book,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="book_delete", methods={"DELETE"})
*/
public function delete(Request $request, Book $book): Response
{
if ($this->isCsrfTokenValid('delete'.$book->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($book);
$entityManager->flush();

$this->addFlash('notice',
'Book has been deleted!'
);
}

return $this->redirectToRoute('book_index');

}
}
116 changes: 116 additions & 0 deletions src/Controller/GenreController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

namespace App\Controller;

use App\Entity\Genre;
use App\Form\GenreType;
use App\Repository\GenreRepository;
use function Sodium\add;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;


/**
* @Route("/genre")
*/
class GenreController extends AbstractController
{
/**
* @Route("/", name="genre_index", methods={"GET"})
*/
public function index(GenreRepository $genreRepository): Response
{


return $this->render('genre/index.html.twig', [
'genres' => $genreRepository->findAll(),
]);
}

/**
* @Route("/new", name="genre_new", methods={"GET","POST"})
*/
public function new(Request $request): Response
{
$genre = new Genre();
$form = $this->createForm(GenreType::class, $genre);
$form->handleRequest($request);




if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($genre);
$entityManager->flush();


$this->addFlash('notice',
' Genre {{ path(\'genre_show\', {id: genre.id}) }}"> {{ genre.name }} was added!');

return $this->redirectToRoute('genre_index');
}

return $this->render('genre/new.html.twig', [
'genre' => $genre,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="genre_show", methods={"GET"})
*/
public function show(Genre $genre): Response
{
$this->addFlash('notice',
'This is your genre!');

return $this->render('genre/show.html.twig', [
'genre' => $genre,
]);
}

/**
* @Route("/{id}/edit", name="genre_edit", methods={"GET","POST"})
*/
public function edit(Request $request, Genre $genre): Response
{
$form = $this->createForm(GenreType::class, $genre);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->getDoctrine()->getManager()->flush();

$this->addFlash('notice',
'Genre has been updated!');

return $this->redirectToRoute('genre_index', [
'id' => $genre->getId(),
]);
}

return $this->render('genre/edit.html.twig', [
'genre' => $genre,
'form' => $form->createView(),
]);
}

/**
* @Route("/{id}", name="genre_delete", methods={"DELETE"})
*/
public function delete(Request $request, Genre $genre): Response
{
if ($this->isCsrfTokenValid('delete'.$genre->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($genre);
$entityManager->flush();

$this->addFlash('notice',
'Genre has been deleted!' );
}

return $this->redirectToRoute('genre_index');
}
}
27 changes: 27 additions & 0 deletions src/Controller/LibraryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Created by PhpStorm.
* User: virtua
* Date: 2019-02-20
* Time: 11:57
*/

namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class LibraryController extends AbstractController
{
/**
* @Route("/library/", name="app_library")
*/
public function dataAction()
{
$dataAction = date("l jS \of F Y h:i:s A");

return $this -> render('library.html.twig',[ 'data' => $dataAction]);
}

}
Loading