Skip to content

Commit

Permalink
Add support for external mod lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jskowronski39 committed Nov 27, 2024
1 parent 89c9bf6 commit 2104dc9
Show file tree
Hide file tree
Showing 90 changed files with 2,266 additions and 827 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
resources:
App\Mods\Entity\ModList\ModList:
App\Mods\Entity\ModList\StandardModList:
operations:
ApiPlatform\Metadata\GetCollection:
provider: 'App\Mods\Api\Provider\ModList\ModListDataProvider'
output: 'App\Mods\Api\Output\ModList\ModListOutput'
uriTemplate: '/mod-lists'
filters:
- 'mod_list.search_filter'
- 'mod_list.date_filter'
Expand All @@ -12,14 +13,15 @@ resources:
ApiPlatform\Metadata\Get:
provider: 'App\Mods\Api\Provider\ModList\ModListDetailsDataProvider'
output: 'App\Mods\Api\Output\ModList\ModListDetailsOutput'
uriTemplate: '/mod-lists/{id}'

get_by_name:
output: 'App\Mods\Api\Output\ModList\ModListDetailsOutput'
class: 'ApiPlatform\Metadata\Get'
uriTemplate: '/mod-lists/by-name/{name}'
uriVariables:
name:
fromClass: 'App\Mods\Entity\ModList\ModList'
fromClass: 'App\Mods\Entity\ModList\StandardModList'
fromProperty: 'name'
controller: 'App\Mods\Api\Controller\ModList\GetModListByNameOperation'
read: false
32 changes: 32 additions & 0 deletions config/doctrine/Mods/ModList.AbstractModList.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="App\Mods\Entity\ModList\AbstractModList" table="mod_lists" repository-class="App\Mods\Repository\ModList\ModListRepository" inheritance-type="SINGLE_TABLE">
<field name="name" type="string" length="255"/>
<field name="description" type="string" length="255" nullable="true"/>

<field name="active" type="boolean"/>

<unique-constraints>
<unique-constraint columns="name"/>
</unique-constraints>

<discriminator-column name="type" type="string" length="255"/>
<discriminator-map>
<discriminator-mapping value="standard" class="App\Mods\Entity\ModList\StandardModList"/>
<discriminator-mapping value="external" class="App\Mods\Entity\ModList\ExternalModList"/>
</discriminator-map>

<indexes>
<!-- This is needed because child index mappings override parent index mappings -->
<index columns="created_at"/>
<index columns="last_updated_at"/>

<index columns="approved"/>
</indexes>
</entity>

</doctrine-mapping>
11 changes: 11 additions & 0 deletions config/doctrine/Mods/ModList.ExternalModList.orm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="App\Mods\Entity\ModList\ExternalModList" repository-class="App\Mods\Repository\ModList\ExternalModListRepository">
<field name="url" type="string" length="255"/>
</entity>

</doctrine-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

<entity name="App\Mods\Entity\ModList\ModList" table="mod_lists" repository-class="App\Mods\Repository\ModList\ModListRepository">
<field name="name" type="string" length="255"/>
<field name="description" type="string" length="255" nullable="true"/>

<entity name="App\Mods\Entity\ModList\StandardModList" repository-class="App\Mods\Repository\ModList\StandardModListRepository">
<many-to-many field="mods" target-entity="App\Mods\Entity\Mod\AbstractMod">
<join-table name="mod_lists_to_mods">
<join-columns>
Expand Down Expand Up @@ -54,20 +51,7 @@
<join-column name="owner_id" referenced-column-name="id" nullable="true" on-delete="SET NULL"/>
</many-to-one>

<field name="active" type="boolean"/>
<field name="approved" type="boolean"/>

<unique-constraints>
<unique-constraint columns="name"/>
</unique-constraints>

<indexes>
<!-- This is needed because child index mappings override parent index mappings -->
<index columns="created_at"/>
<index columns="last_updated_at"/>

<index columns="approved"/>
</indexes>
</entity>

</doctrine-mapping>
15 changes: 10 additions & 5 deletions config/doctrine/Users/Permissions.AbstractPermissions.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,16 @@

<!-- Mod List -->
<field name="modListList" type="boolean"/>
<field name="modListCreate" type="boolean"/>
<field name="modListUpdate" type="boolean"/>
<field name="modListDelete" type="boolean"/>
<field name="modListCopy" type="boolean"/>
<field name="modListApprove" type="boolean"/>

<field name="standardModListCreate" type="boolean"/>
<field name="standardModListUpdate" type="boolean"/>
<field name="standardModListDelete" type="boolean"/>
<field name="standardModListCopy" type="boolean"/>
<field name="standardModListApprove" type="boolean"/>

<field name="externalModListCreate" type="boolean"/>
<field name="externalModListUpdate" type="boolean"/>
<field name="externalModListDelete" type="boolean"/>

<discriminator-column name="type" type="string" length="255"/>
<discriminator-map>
Expand Down
66 changes: 66 additions & 0 deletions migrations/Version20241117133108.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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 Version20241117133108 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add support for external mod lists';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE mod_lists ADD type VARCHAR(255)');
$this->addSql("UPDATE mod_lists SET type = 'standard'");
$this->addSql('ALTER TABLE mod_lists ALTER type SET NOT NULL');

$this->addSql('ALTER TABLE mod_lists ADD url VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE mod_lists ALTER approved DROP NOT NULL');

$this->addSql('ALTER TABLE permissions RENAME COLUMN mod_list_create TO standard_mod_list_create');
$this->addSql('ALTER TABLE permissions RENAME COLUMN mod_list_update TO standard_mod_list_update');
$this->addSql('ALTER TABLE permissions RENAME COLUMN mod_list_delete TO standard_mod_list_delete');
$this->addSql('ALTER TABLE permissions RENAME COLUMN mod_list_copy TO standard_mod_list_copy');
$this->addSql('ALTER TABLE permissions RENAME COLUMN mod_list_approve TO standard_mod_list_approve');

$this->addSql('ALTER TABLE permissions ADD external_mod_list_create BOOLEAN');
$this->addSql('ALTER TABLE permissions ADD external_mod_list_update BOOLEAN');
$this->addSql('ALTER TABLE permissions ADD external_mod_list_delete BOOLEAN');
$this->addSql('UPDATE permissions SET external_mod_list_create = false');
$this->addSql('UPDATE permissions SET external_mod_list_update = false');
$this->addSql('UPDATE permissions SET external_mod_list_delete = false');
$this->addSql('ALTER TABLE permissions ALTER external_mod_list_create SET NOT NULL');
$this->addSql('ALTER TABLE permissions ALTER external_mod_list_update SET NOT NULL');
$this->addSql('ALTER TABLE permissions ALTER external_mod_list_delete SET NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql("DELETE FROM mod_lists WHERE type = 'external'");

$this->addSql('ALTER TABLE mod_lists DROP type');
$this->addSql('ALTER TABLE mod_lists DROP url');
$this->addSql('ALTER TABLE mod_lists ALTER approved SET NOT NULL');

$this->addSql('ALTER TABLE permissions RENAME COLUMN standard_mod_list_create TO mod_list_create');
$this->addSql('ALTER TABLE permissions RENAME COLUMN standard_mod_list_update TO mod_list_update');
$this->addSql('ALTER TABLE permissions RENAME COLUMN standard_mod_list_delete TO mod_list_delete');
$this->addSql('ALTER TABLE permissions RENAME COLUMN standard_mod_list_copy TO mod_list_copy');
$this->addSql('ALTER TABLE permissions RENAME COLUMN standard_mod_list_approve TO mod_list_approve');

$this->addSql('ALTER TABLE permissions DROP external_mod_list_create');
$this->addSql('ALTER TABLE permissions DROP external_mod_list_update');
$this->addSql('ALTER TABLE permissions DROP external_mod_list_delete');
}
}
10 changes: 5 additions & 5 deletions src/Mods/Api/Controller/ModList/GetModListByNameOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@

use App\Mods\Api\DataTransformer\ModList\ModListDetailsOutputDataTransformer;
use App\Mods\Api\Output\ModList\ModListOutput;
use App\Mods\Repository\ModList\ModListRepository;
use App\Mods\Repository\ModList\StandardModListRepository;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

#[AsController]
class GetModListByNameOperation
{
public function __construct(
private ModListRepository $modListRepository,
private StandardModListRepository $standardModListRepository,
private ModListDetailsOutputDataTransformer $modListDetailsOutputDataTransformer,
) {
}

public function __invoke(string $name): ?ModListOutput
{
$modList = $this->modListRepository->findOneByName($name);
$standardModList = $this->standardModListRepository->findOneByName($name);

if (!$modList) {
if (!$standardModList) {
throw new NotFoundHttpException('Not Found');
}

return $this->modListDetailsOutputDataTransformer->transform($modList);
return $this->modListDetailsOutputDataTransformer->transform($standardModList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Mods\Api\Output\ModList\ModListOutput;
use App\Mods\Entity\Dlc\Dlc;
use App\Mods\Entity\Mod\AbstractMod;
use App\Mods\Entity\ModList\ModList;
use App\Mods\Entity\ModList\StandardModList;
use App\Mods\Repository\Mod\ModRepository;

class ModListDetailsOutputDataTransformer
Expand All @@ -22,22 +22,22 @@ public function __construct(
) {
}

public function transform(ModList $modList): ModListOutput
public function transform(StandardModList $standardModList): ModListOutput
{
return new ModListDetailsOutput(
$modList->getId()->toString(),
$modList->getName(),
$modList->isActive(),
$modList->isApproved(),
$modList->getCreatedAt(),
$modList->getLastUpdatedAt(),
$standardModList->getId()->toString(),
$standardModList->getName(),
$standardModList->isActive(),
$standardModList->isApproved(),
$standardModList->getCreatedAt(),
$standardModList->getLastUpdatedAt(),
array_map(
fn (AbstractMod $mod) => $this->modOutputDataTransformer->transform($mod),
$this->modRepository->findIncludedMods($modList)
$this->modRepository->findIncludedMods($standardModList)
),
array_map(
fn (Dlc $dlc) => $this->dlcOutputDataTransformer->transform($dlc),
$modList->getDlcs()
$standardModList->getDlcs()
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace App\Mods\Api\DataTransformer\ModList;

use App\Mods\Api\Output\ModList\ModListOutput;
use App\Mods\Entity\ModList\ModList;
use App\Mods\Entity\ModList\StandardModList;

class ModListOutputDataTransformer
{
public function transform(ModList $modList): ModListOutput
public function transform(StandardModList $standardModList): ModListOutput
{
return new ModListOutput(
$modList->getId()->toString(),
$modList->getName(),
$modList->isActive(),
$modList->isApproved(),
$modList->getCreatedAt(),
$modList->getLastUpdatedAt(),
$standardModList->getId()->toString(),
$standardModList->getName(),
$standardModList->isActive(),
$standardModList->isApproved(),
$standardModList->getCreatedAt(),
$standardModList->getLastUpdatedAt(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace App\Mods\Controller\ModList;
namespace App\Mods\Controller\ModList\Common;

use App\Mods\Repository\ModList\ModListRepository;
use App\Mods\Query\ModList\ModListListQuery;
use App\Shared\Security\Enum\PermissionsEnum;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -14,18 +14,15 @@
class ListAction extends AbstractController
{
public function __construct(
private ModListRepository $modListRepository,
private ModListListQuery $modListListQuery,
) {
}

#[Route('/mod-list/list', name: 'app_mod_list_list')]
#[IsGranted(PermissionsEnum::MOD_LIST_LIST->value)]
public function __invoke(): Response
{
$modLists = $this->modListRepository->findBy([], [
'approved' => 'DESC',
'name' => 'ASC',
]);
$modLists = $this->modListListQuery->getResult();

return $this->render('mods/mod_list/list.html.twig', [
'modLists' => $modLists,
Expand Down
48 changes: 0 additions & 48 deletions src/Mods/Controller/ModList/CopyAction.php

This file was deleted.

Loading

0 comments on commit 2104dc9

Please sign in to comment.