-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(complaint): add complaint creation
- Loading branch information
Showing
20 changed files
with
1,017 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,9 @@ p { | |
margin-top: $size-spacer-lg; | ||
} | ||
} | ||
|
||
ol { | ||
li { | ||
margin: 1em 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20240609192945 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE TABLE complaint (id UUID NOT NULL, status_id UUID NOT NULL, email VARCHAR(200) NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, money_sent DOUBLE PRECISION DEFAULT NULL, country VARCHAR(100) NOT NULL, code VARCHAR(200) NOT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('CREATE INDEX IDX_5F2732B56BF700BD ON complaint (status_id)'); | ||
$this->addSql('COMMENT ON COLUMN complaint.id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN complaint.status_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN complaint.created_at IS \'(DC2Type:datetime_immutable)\''); | ||
$this->addSql('CREATE TABLE complaint_report (id UUID NOT NULL, complaint_id UUID NOT NULL, report_id UUID NOT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('CREATE INDEX IDX_E66CBA46EDAE188E ON complaint_report (complaint_id)'); | ||
$this->addSql('CREATE UNIQUE INDEX UNIQ_E66CBA464BD2A4C0 ON complaint_report (report_id)'); | ||
$this->addSql('COMMENT ON COLUMN complaint_report.id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN complaint_report.complaint_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('COMMENT ON COLUMN complaint_report.report_id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('CREATE TABLE complaint_status (id UUID NOT NULL, name VARCHAR(100) NOT NULL, has_replied BOOLEAN NOT NULL, has_sent_sensitive_data BOOLEAN NOT NULL, has_sent_money BOOLEAN NOT NULL, PRIMARY KEY(id))'); | ||
$this->addSql('COMMENT ON COLUMN complaint_status.id IS \'(DC2Type:uuid)\''); | ||
$this->addSql('ALTER TABLE complaint ADD CONSTRAINT FK_5F2732B56BF700BD FOREIGN KEY (status_id) REFERENCES complaint_status (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE complaint_report ADD CONSTRAINT FK_E66CBA46EDAE188E FOREIGN KEY (complaint_id) REFERENCES complaint (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
$this->addSql('ALTER TABLE complaint_report ADD CONSTRAINT FK_E66CBA464BD2A4C0 FOREIGN KEY (report_id) REFERENCES report (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE complaint DROP CONSTRAINT FK_5F2732B56BF700BD'); | ||
$this->addSql('ALTER TABLE complaint_report DROP CONSTRAINT FK_E66CBA46EDAE188E'); | ||
$this->addSql('ALTER TABLE complaint_report DROP CONSTRAINT FK_E66CBA464BD2A4C0'); | ||
$this->addSql('DROP TABLE complaint'); | ||
$this->addSql('DROP TABLE complaint_report'); | ||
$this->addSql('DROP TABLE complaint_status'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Controller; | ||
|
||
use App\Entity\Complaint\Complaint; | ||
use App\Entity\Complaint\ComplaintReport; | ||
use App\Form\NewComplaintType; | ||
use App\Service\DomainService; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\Form\FormError; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
#[Route('/report', name: 'complaint_')] | ||
class ComplaintController extends AbstractController | ||
{ | ||
#[Route('/new', name: 'create')] | ||
public function create(Request $request, EntityManagerInterface $em, DomainService $domainService): Response | ||
{ | ||
|
||
$complaint = new Complaint(); | ||
$complaintForm = $this->createForm(NewComplaintType::class, $complaint); | ||
$complaintForm->handleRequest($request); | ||
|
||
if ($complaintForm->isSubmitted() && $complaintForm->isValid()) { | ||
|
||
$element = $complaintForm->get('element'); | ||
$report = $domainService->getReport($element->getData()); | ||
|
||
if($report->isSafe()){ | ||
$element->addError(new FormError("This is not a fraudulent element.")); | ||
}else{ | ||
|
||
$complaintReport = new ComplaintReport($complaint, $report); | ||
|
||
$em->persist($complaintReport); | ||
$em->flush(); | ||
|
||
return $this->redirectToRoute('complaint_edit', [ | ||
'id' => $complaint->getId(), | ||
'code' => $complaint->getCode() | ||
]); | ||
|
||
|
||
} | ||
} | ||
|
||
return $this->renderForm('complaint/index.html.twig', [ | ||
'complaintForm' => $complaintForm, | ||
]); | ||
} | ||
|
||
|
||
#[Route('/{id}/{code}/edit', name: 'edit')] | ||
public function edit(Complaint $complaint, $code): Response | ||
{ | ||
if($complaint->getCode() !== $code) { | ||
throw $this->createNotFoundException('The code is not valid'); | ||
} | ||
|
||
return $this->renderForm('complaint/show.html.twig', [ | ||
'complaint' => $complaint, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Entity\Complaint\Complaint; | ||
use App\Entity\Complaint\ComplaintReport; | ||
use App\Repository\Complaint\ComplaintStatusRepository; | ||
use App\Repository\DomainRepository; | ||
use App\Service\DomainService; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
use Symfony\Component\Intl\Countries; | ||
|
||
class ComplaintFixtures extends Fixture implements DependentFixtureInterface | ||
{ | ||
|
||
public function __construct(private ComplaintStatusRepository $complaintStatusRepository, | ||
private DomainRepository $domainRepository, | ||
private DomainService $domainService) | ||
{ | ||
} | ||
|
||
public function load(ObjectManager $manager): void | ||
{ | ||
|
||
$statuses = $this->complaintStatusRepository->findAll(); | ||
$countries = Countries::getCountryCodes(); | ||
$domains = $this->domainRepository->findAll(); | ||
|
||
|
||
$letters = range("a", "z"); | ||
foreach ($letters as $letter) { | ||
|
||
$complaint = new Complaint(); | ||
$complaint->setCountry($countries[array_rand($countries)]); | ||
|
||
$complaint->setEmail("$letter@example.com"); | ||
|
||
$complaint->setStatus($statuses[array_rand($statuses)]); | ||
|
||
shuffle($domains); | ||
for ($i = 0; $i < rand(1, 5); $i++) { | ||
|
||
$domain = $domains[$i]; | ||
|
||
$report = $this->domainService->getReport("http://$domain"); | ||
$complaintReport = new ComplaintReport($complaint, $report); | ||
$manager->persist($complaintReport); | ||
|
||
} | ||
|
||
$manager->persist($complaint); | ||
} | ||
|
||
$manager->flush(); | ||
} | ||
|
||
public function getDependencies() | ||
{ | ||
return [ | ||
DomainFixtures::class, | ||
ComplaintStatusFixtures::class, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\DataFixtures; | ||
|
||
use App\Entity\Complaint\ComplaintStatus; | ||
use Doctrine\Bundle\FixturesBundle\Fixture; | ||
use Doctrine\Persistence\ObjectManager; | ||
|
||
class ComplaintStatusFixtures extends Fixture | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
|
||
$statuses = [ | ||
0 => "Got contacted", | ||
1 => "Got contacted, replied", | ||
2 => "Got contacted, replied, sent sensitive data", | ||
3 => "Got contacted, replied, sent sensitive data, sent money", | ||
]; | ||
|
||
foreach ($statuses as $index => $name) { | ||
$status = new ComplaintStatus(); | ||
$status->setName($name); | ||
|
||
$status->setHasReplied($index > 0); | ||
$status->setHasSentSensitiveData($index > 1); | ||
$status->setHasSentMoney($index > 2); | ||
|
||
$manager->persist($status); | ||
} | ||
|
||
$manager->flush(); | ||
} | ||
} |
Oops, something went wrong.