Skip to content

Commit

Permalink
new: Allow to create and list the organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Oct 14, 2022
2 parents d0f9ca1 + 5336181 commit d141c61
Show file tree
Hide file tree
Showing 29 changed files with 813 additions and 28 deletions.
4 changes: 4 additions & 0 deletions assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
@import "./utils/flow.css";
@import "./utils/wrapper.css";
@import "./components/alerts.css";
@import "./components/anchors.css";
@import "./components/buttons.css";
@import "./components/cards.css";
@import "./components/forms.css";
@import "./components/grid.css";
@import "./components/layout.css";
@import "./components/text.css";

*,
*::before,
Expand Down
25 changes: 25 additions & 0 deletions assets/stylesheets/components/anchors.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This file is part of Bileto. */
/* Copyright 2022 Probesys */
/* SPDX-License-Identifier: AGPL-3.0-or-later */

a {
color: var(--color-primary11);
}

.anchor--action {
display: inline-block;
padding: 0.5rem 1.75rem;

text-decoration: none;

background-color: var(--color-primary3);
border: 0.25rem solid currentcolor;
border-radius: 0.5rem;

transition: background-color 0.2s ease-in-out;
}

.anchor--action:hover,
.anchor--action:focus {
background-color: var(--color-primary4);
}
18 changes: 18 additions & 0 deletions assets/stylesheets/components/cards.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* This file is part of Bileto. */
/* Copyright 2022 Probesys */
/* SPDX-License-Identifier: AGPL-3.0-or-later */

.card {
overflow: hidden;

padding: 1rem;

background-color: var(--color-grey4);
box-shadow: 0 1px 2px var(--color-grey8);
border-radius: 0.5rem;
}

.card__title {
font-weight: bold;
overflow-wrap: anywhere;
}
18 changes: 18 additions & 0 deletions assets/stylesheets/components/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ input:focus {
border-color: var(--color-primary8);
}

input[aria-invalid] {
background-color: var(--color-error2);
border-color: var(--color-error11);
}

.form__error {
padding-left: 1.25em;

color: var(--color-error11);
font-size: 0.9em;
font-weight: bold;

background-image: url("../../icons/circle-exclamation-error.svg");
background-repeat: no-repeat;
background-position: left center;
background-size: 1em;
}

.form__actions {
display: flex;

Expand Down
31 changes: 31 additions & 0 deletions assets/stylesheets/components/grid.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* This file is part of Bileto. */
/* Copyright 2022 Probesys */
/* SPDX-License-Identifier: AGPL-3.0-or-later */

.grid {
display: grid;

grid-gap: 2rem;
}

.grid > * {
min-width: 0;
}

@media (min-width: 800px) {
.grid--cols2 {
grid-template-columns: repeat(2, 1fr);
}

.grid--cols3 {
grid-template-columns: repeat(3, 1fr);
}

.grid--cols4 {
grid-template-columns: repeat(4, 1fr);
}

.grid--cols5 {
grid-template-columns: repeat(5, 1fr);
}
}
28 changes: 27 additions & 1 deletion assets/stylesheets/components/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,44 @@
flex: 1;
}

.layout__back {
max-width: 1200px;
margin-top: -1rem;
margin-right: auto;
margin-left: auto;
}

.layout__back a {
display: inline-block;
padding: 2rem 1.5rem;

outline-offset: -0.3rem;
}

.layout__back a::before {
content: "←";
}

.layout__body {
padding: 2rem 1rem;
padding: 2rem 1rem 4rem;

background-color: var(--color-grey1);
box-shadow: 0 1px 3px var(--color-grey7);
}

.layout__body--small {
max-width: 600px;
margin-right: auto;
margin-left: auto;
}

@media (min-width: 800px) {
.layout__body {
padding-right: 2rem;
padding-left: 2rem;
}

.layout__body--small {
border-radius: 0.5rem;
}
}
Expand Down
15 changes: 15 additions & 0 deletions assets/stylesheets/components/text.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* This file is part of Bileto. */
/* Copyright 2022 Probesys */
/* SPDX-License-Identifier: AGPL-3.0-or-later */

.text--secondary {
color: var(--color-grey11);
}

.text--center {
text-align: center;
}

.text--big {
font-size: 1.2em;
}
6 changes: 3 additions & 3 deletions assets/stylesheets/utils/flow.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
}

.flow > * + * {
margin-top: 1.5rem;
margin-top: 2rem;
}

.flow-large > * + * {
margin-top: 1.75rem;
margin-top: 3rem;
}

.flow-larger > * + * {
margin-top: 2.5rem;
margin-top: 4rem;
}
3 changes: 3 additions & 0 deletions config/packages/twig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

twig:
default_path: '%kernel.project_dir%/templates'
globals:
errors: []
error: null

when@test:
twig:
Expand Down
59 changes: 59 additions & 0 deletions migrations/Version20221014081029CreateOrganization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

// This file is part of Bileto.
// Copyright 2022 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20221014081029CreateOrganization extends AbstractMigration
{
public function getDescription(): string
{
return 'Create the table organization';
}

public function up(Schema $schema): void
{
$dbPlatform = $this->connection->getDatabasePlatform()->getName();
if ($dbPlatform === 'postgresql') {
$this->addSql('CREATE SEQUENCE organization_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql(<<<SQL
CREATE TABLE organization (
id INT NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
)
SQL);
$this->addSql('CREATE UNIQUE INDEX UNIQ_C1EE637C5E237E06 ON "organization" (name)');
} elseif ($dbPlatform === 'mysql') {
$this->addSql(<<<SQL
CREATE TABLE organization (
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id)
)
DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
SQL);
$this->addSql('CREATE UNIQUE INDEX UNIQ_C1EE637C5E237E06 ON organization (name)');
}
}

public function down(Schema $schema): void
{
$dbPlatform = $this->connection->getDatabasePlatform()->getName();
if ($dbPlatform === 'postgresql') {
$this->addSql('DROP INDEX UNIQ_C1EE637C5E237E06');
$this->addSql('DROP SEQUENCE organization_id_seq CASCADE');
$this->addSql('DROP TABLE organization');
} elseif ($dbPlatform === 'mysql') {
$this->addSql('DROP INDEX UNIQ_C1EE637C5E237E06 on `organization`');
$this->addSql('DROP TABLE organization');
}
}
}
54 changes: 54 additions & 0 deletions src/Controller/BaseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

// This file is part of Bileto.
// Copyright 2022 Probesys
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Component\Validator\ConstraintViolationListInterface;

class BaseController extends AbstractController
{
/**
* @param mixed[] $parameters
*/
protected function renderBadRequest(string $view, array $parameters = [], Response $response = null): Response
{
if ($response === null) {
$response = new Response('', Response::HTTP_BAD_REQUEST);
} else {
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
}

return $this->render($view, $parameters, $response);
}

protected function csrfError(): string
{
return new TranslatableMessage('Invalid CSRF token.', [], 'security');
}

/**
* @return array<string, string>
*/
protected function formatErrors(ConstraintViolationListInterface $errors): array
{
$formattedErrors = [];
foreach ($errors as $error) {
$property = $error->getPropertyPath();
if (isset($formattedErrors[$property])) {
$formattedErrors[$property] = implode(
' ',
[$formattedErrors[$property], $error->getMessage()],
);
} else {
$formattedErrors[$property] = $error->getMessage();
}
}
return $formattedErrors;
}
}
5 changes: 2 additions & 3 deletions src/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

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

class HomeController extends AbstractController
class HomeController extends BaseController
{
#[Route('/', name: 'home', methods: ['GET', 'HEAD'])]
public function show(): Response
{
return $this->render('home/show.html.twig');
return $this->redirectToRoute('organizations');
}
}
3 changes: 1 addition & 2 deletions src/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;

class LoginController extends AbstractController
class LoginController extends BaseController
{
#[Route('/login', name: 'login', methods: ['GET', 'POST'])]
public function new(AuthenticationUtils $authenticationUtils): Response
Expand Down
Loading

0 comments on commit d141c61

Please sign in to comment.