Rename "nexus raw data" to "page view", mark unused fields as nullable
Details: - rename `nexus_raw_data` table to `page_view` - rename `NexusRawData` entity to `PageView` - approprietly rename repository class, method arguments, and local variables - mark `requestStartedAt` and `responseCompletedAt` fields as nullable - rename `submitter` property to `owner` to match `UserAccessToken` entity
This commit is contained in:
parent
dd4ee4579a
commit
965a66d448
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version0008 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Rename "nexus_raw_data" table to "page_view", minor redesign of table columns';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER TABLE nexus_raw_data RENAME TO page_view');
|
||||
$this->addSql('ALTER TABLE page_view RENAME COLUMN submitter_id TO owner_id');
|
||||
$this->addSql('ALTER TABLE page_view ALTER request_started_at DROP NOT NULL');
|
||||
$this->addSql('ALTER TABLE page_view ALTER response_completed_at DROP NOT NULL');
|
||||
$this->addSql('ALTER INDEX nexus_raw_data_sorting_idx RENAME TO page_view_sorting_idx');
|
||||
$this->addSql('ALTER INDEX nexus_raw_data_submitter_idx RENAME TO page_view_owner_idx');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('ALTER INDEX page_view_owner_idx RENAME TO nexus_raw_data_submitter_idx');
|
||||
$this->addSql('ALTER INDEX page_view_sorting_idx RENAME TO nexus_raw_data_sorting_idx');
|
||||
$this->addSql('ALTER TABLE page_view ALTER response_completed_at SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE page_view ALTER request_started_at SET NOT NULL');
|
||||
$this->addSql('ALTER TABLE page_view RENAME COLUMN owner_id TO submitter_id');
|
||||
$this->addSql('ALTER TABLE page_view RENAME TO nexus_raw_data');
|
||||
}
|
||||
}
|
|
@ -5,10 +5,10 @@ declare(strict_types=1);
|
|||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Contract\Config\AppRoutes;
|
||||
use App\Doctrine\Entity\NexusRawData;
|
||||
use App\Doctrine\Entity\PageView;
|
||||
use App\Doctrine\Entity\User;
|
||||
use App\Doctrine\Entity\UserAccessToken;
|
||||
use App\Doctrine\Repository\NexusRawDataRepository;
|
||||
use App\Doctrine\Repository\PageViewRepository;
|
||||
use App\Doctrine\Repository\UserAccessTokenRepository;
|
||||
use App\Doctrine\Repository\UserRepository;
|
||||
use DateTimeImmutable;
|
||||
|
@ -28,7 +28,7 @@ final class DashboardController extends AbstractDashboardController
|
|||
private Environment $twigEnvironment,
|
||||
private UserRepository $userRepository,
|
||||
private UserAccessTokenRepository $userAccessTokenRepository,
|
||||
private NexusRawDataRepository $nexusRawDataRepository
|
||||
private PageViewRepository $pageViewRepository
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -37,12 +37,12 @@ final class DashboardController extends AbstractDashboardController
|
|||
{
|
||||
$userTotalCount = $this->userRepository->getTotalCount();
|
||||
$tokenTotalCount = $this->userAccessTokenRepository->getTotalCount();
|
||||
$dataTotalCount = $this->nexusRawDataRepository->getTotalCount();
|
||||
$dataWeeklyCount = $this->nexusRawDataRepository->getPartialCount(
|
||||
$dataTotalCount = $this->pageViewRepository->getTotalCount();
|
||||
$dataWeeklyCount = $this->pageViewRepository->getPartialCount(
|
||||
new DateTimeImmutable(datetime: 'midnight UTC - 1 week'),
|
||||
new DateTimeImmutable(datetime: 'midnight UTC')
|
||||
);
|
||||
$dataDailyCount = $this->nexusRawDataRepository->getPartialCount(
|
||||
$dataDailyCount = $this->pageViewRepository->getPartialCount(
|
||||
new DateTimeImmutable(datetime: 'midnight UTC - 1 day'),
|
||||
new DateTimeImmutable(datetime: 'midnight UTC')
|
||||
);
|
||||
|
@ -50,9 +50,9 @@ final class DashboardController extends AbstractDashboardController
|
|||
$context = [
|
||||
'user_total_count' => $userTotalCount,
|
||||
'token_total_count' => $tokenTotalCount,
|
||||
'data_total_count' => $dataTotalCount,
|
||||
'data_weekly_count' => $dataWeeklyCount,
|
||||
'data_daily_count' => $dataDailyCount,
|
||||
'page_view_total_count' => $dataTotalCount,
|
||||
'page_view_weekly_count' => $dataWeeklyCount,
|
||||
'page_view_daily_count' => $dataDailyCount,
|
||||
];
|
||||
|
||||
$content = $this->twigEnvironment->render(name: 'admin/dashboard/index.html.twig', context: $context);
|
||||
|
@ -71,8 +71,8 @@ final class DashboardController extends AbstractDashboardController
|
|||
public function configureMenuItems(): iterable
|
||||
{
|
||||
yield MenuItem::linkToDashboard(label: 'Dashboard', icon: 'fa fa-home');
|
||||
yield MenuItem::section(label: 'Raw data');
|
||||
yield MenuItem::linkToCrud(label: 'Raw data', icon: 'fas fa-list', entityFqcn: NexusRawData::class);
|
||||
yield MenuItem::section(label: 'Page views');
|
||||
yield MenuItem::linkToCrud(label: 'Page views', icon: 'fas fa-list', entityFqcn: PageView::class);
|
||||
yield MenuItem::section(label: 'Users');
|
||||
yield MenuItem::linkToCrud(label: 'Users', icon: 'fas fa-users', entityFqcn: User::class);
|
||||
yield MenuItem::linkToCrud(
|
||||
|
|
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Admin\Field\JsonField;
|
||||
use App\Doctrine\Entity\NexusRawData;
|
||||
use App\Doctrine\Entity\PageView;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
|
@ -21,11 +21,11 @@ use Symfony\Component\HttpFoundation\Request;
|
|||
|
||||
use function json_encode;
|
||||
|
||||
final class NexusRawDataCrudController extends AbstractCrudController
|
||||
final class PageViewCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return NexusRawData::class;
|
||||
return PageView::class;
|
||||
}
|
||||
|
||||
public function configureCrud(Crud $crud): Crud
|
||||
|
@ -43,7 +43,7 @@ final class NexusRawDataCrudController extends AbstractCrudController
|
|||
|
||||
yield IdField::new(propertyName: 'id')->setMaxLength(length: -1)->setDisabled(disabled: true);
|
||||
yield DateTimeField::new(propertyName: 'createdAt');
|
||||
yield AssociationField::new(propertyName: 'submitter')->onlyOnDetail();
|
||||
yield AssociationField::new(propertyName: 'owner')->onlyOnDetail();
|
||||
yield DateTimeField::new(propertyName: 'requestStartedAt')->onlyOnDetail();
|
||||
yield DateTimeField::new(propertyName: 'responseCompletedAt')->onlyOnDetail();
|
||||
yield TextField::new(propertyName: 'method');
|
||||
|
@ -62,7 +62,7 @@ final class NexusRawDataCrudController extends AbstractCrudController
|
|||
return parent::configureFilters(filters: $filters)
|
||||
->add(propertyNameOrFilter: 'id')
|
||||
->add(propertyNameOrFilter: 'createdAt')
|
||||
->add(propertyNameOrFilter: 'submitter')
|
||||
->add(propertyNameOrFilter: 'owner')
|
||||
->add(propertyNameOrFilter: $methodFilter)
|
||||
->add(propertyNameOrFilter: 'url')
|
||||
->add(propertyNameOrFilter: 'parsedAt');
|
|
@ -6,7 +6,7 @@ namespace App\Doctrine\Entity;
|
|||
|
||||
use App\Contract\Doctrine\Entity\DatedEntityInterface;
|
||||
use App\Contract\Doctrine\Entity\UuidPrimaryKeyInterface;
|
||||
use App\Doctrine\Repository\NexusRawDataRepository;
|
||||
use App\Doctrine\Repository\PageViewRepository;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
|
@ -14,26 +14,26 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
use JsonSerializable;
|
||||
|
||||
#[
|
||||
ORM\Entity(repositoryClass: NexusRawDataRepository::class),
|
||||
ORM\Table(name: 'nexus_raw_data'),
|
||||
ORM\Index(columns: ['created_at', 'request_started_at', 'id'], name: 'nexus_raw_data_sorting_idx'),
|
||||
ORM\Index(columns: ['submitter_id'], name: 'nexus_raw_data_submitter_idx'),
|
||||
ORM\Entity(repositoryClass: PageViewRepository::class),
|
||||
ORM\Table(name: 'page_view'),
|
||||
ORM\Index(columns: ['created_at', 'request_started_at', 'id'], name: 'page_view_sorting_idx'),
|
||||
ORM\Index(columns: ['owner_id'], name: 'page_view_owner_idx'),
|
||||
]
|
||||
class NexusRawData implements UuidPrimaryKeyInterface, DatedEntityInterface, JsonSerializable
|
||||
class PageView implements UuidPrimaryKeyInterface, DatedEntityInterface, JsonSerializable
|
||||
{
|
||||
use UuidPrimaryKeyTrait;
|
||||
use DatedEntityTrait;
|
||||
|
||||
#[
|
||||
ORM\ManyToOne(targetEntity: User::class),
|
||||
ORM\JoinColumn(name: 'submitter_id', referencedColumnName: 'id', nullable: false),
|
||||
ORM\JoinColumn(name: 'owner_id', referencedColumnName: 'id', nullable: false),
|
||||
]
|
||||
private ?User $submitter = null;
|
||||
private ?User $owner = null;
|
||||
|
||||
#[ORM\Column(name: 'request_started_at', type: Types::DATETIMETZ_IMMUTABLE, nullable: false)]
|
||||
#[ORM\Column(name: 'request_started_at', type: Types::DATETIMETZ_IMMUTABLE, nullable: true)]
|
||||
private ?DateTimeImmutable $requestStartedAt = null;
|
||||
|
||||
#[ORM\Column(name: 'response_completed_at', type: Types::DATETIMETZ_IMMUTABLE, nullable: false)]
|
||||
#[ORM\Column(name: 'response_completed_at', type: Types::DATETIMETZ_IMMUTABLE, nullable: true)]
|
||||
private ?DateTimeImmutable $responseCompletedAt = null;
|
||||
|
||||
#[ORM\Column(name: 'method', type: Types::TEXT, nullable: false)]
|
||||
|
@ -64,7 +64,7 @@ class NexusRawData implements UuidPrimaryKeyInterface, DatedEntityInterface, Jso
|
|||
return [
|
||||
'id' => $this->getId(),
|
||||
'createdAt' => $this->getCreatedAt()?->format(DateTimeInterface::ISO8601),
|
||||
'submitterId' => $this->getSubmitter()?->getId(),
|
||||
'ownerId' => $this->getOwner()?->getId(),
|
||||
'requestStartedAt' => $this->getRequestStartedAt()?->format(DateTimeInterface::ISO8601),
|
||||
'responseCompletedAt' => $this->getResponseCompletedAt()?->format(DateTimeInterface::ISO8601),
|
||||
'method' => $this->getMethod(),
|
||||
|
@ -74,14 +74,14 @@ class NexusRawData implements UuidPrimaryKeyInterface, DatedEntityInterface, Jso
|
|||
];
|
||||
}
|
||||
|
||||
public function getSubmitter(): ?User
|
||||
public function getOwner(): ?User
|
||||
{
|
||||
return $this->submitter;
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
public function setSubmitter(?User $submitter): void
|
||||
public function setOwner(?User $owner): void
|
||||
{
|
||||
$this->submitter = $submitter;
|
||||
$this->owner = $owner;
|
||||
}
|
||||
|
||||
public function getRequestStartedAt(): ?DateTimeImmutable
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Doctrine\Repository;
|
||||
|
||||
use App\Doctrine\Entity\NexusRawData;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method NexusRawData|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method NexusRawData|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method NexusRawData[] findAll()
|
||||
* @method NexusRawData[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
final class NexusRawDataRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct(registry: $registry, entityClass: NexusRawData::class);
|
||||
}
|
||||
|
||||
public function getTotalCount(): int
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder(alias: 'nrd')
|
||||
->select(select: 'COUNT(nrd)');
|
||||
|
||||
$query = $queryBuilder->getQuery();
|
||||
|
||||
return $query->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function getPartialCount(DateTimeImmutable $from, DateTimeImmutable $to): int
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder(alias: 'nrd')
|
||||
->select(select: 'COUNT(nrd)')
|
||||
->where(predicates: 'nrd.createdAt BETWEEN :from AND :to')
|
||||
->setParameter(key: 'from', value: $from)
|
||||
->setParameter(key: 'to', value: $to);
|
||||
|
||||
$query = $queryBuilder->getQuery();
|
||||
|
||||
return $query->getSingleScalarResult();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Doctrine\Repository;
|
||||
|
||||
use App\Doctrine\Entity\PageView;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method PageView|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method PageView|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method PageView[] findAll()
|
||||
* @method PageView[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
final class PageViewRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct(registry: $registry, entityClass: PageView::class);
|
||||
}
|
||||
|
||||
public function getTotalCount(): int
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder(alias: 'pv')
|
||||
->select(select: 'COUNT(pv)');
|
||||
|
||||
$query = $queryBuilder->getQuery();
|
||||
|
||||
return $query->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function getPartialCount(DateTimeImmutable $from, DateTimeImmutable $to): int
|
||||
{
|
||||
$queryBuilder = $this->createQueryBuilder(alias: 'pv')
|
||||
->select(select: 'COUNT(pv)')
|
||||
->where(predicates: 'pv.createdAt BETWEEN :from AND :to')
|
||||
->setParameter(key: 'from', value: $from)
|
||||
->setParameter(key: 'to', value: $to);
|
||||
|
||||
$query = $queryBuilder->getQuery();
|
||||
|
||||
return $query->getSingleScalarResult();
|
||||
}
|
||||
}
|
|
@ -4,44 +4,43 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Service;
|
||||
|
||||
use App\Doctrine\Entity\NexusRawData;
|
||||
use App\Doctrine\Entity\PageView;
|
||||
use DateTimeImmutable;
|
||||
|
||||
use DateTimeZone;
|
||||
|
||||
use function array_key_exists;
|
||||
|
||||
final class NexusRawDataFactory
|
||||
{
|
||||
public function createFromJsonDataSubmission(object $decodedJsonData, DateTimeZone $timeZone): NexusRawData
|
||||
public function createFromJsonDataSubmission(object $decodedJsonData, DateTimeZone $timeZone): PageView
|
||||
{
|
||||
$nexusRawData = new NexusRawData();
|
||||
$pageView = new PageView();
|
||||
|
||||
$data = get_object_vars(object: $decodedJsonData);
|
||||
|
||||
if (array_key_exists(key: 'requestStartedAt', array: $data)) {
|
||||
$requestStartedAt = new DateTimeImmutable(datetime: $data['requestStartedAt']);
|
||||
$requestStartedAt->setTimezone(timezone: $timeZone);
|
||||
$nexusRawData->setRequestStartedAt(requestStartedAt: $requestStartedAt);
|
||||
$pageView->setRequestStartedAt(requestStartedAt: $requestStartedAt);
|
||||
}
|
||||
if (array_key_exists(key: 'responseCompletedAt', array: $data)) {
|
||||
$responseCompletedAt = new DateTimeImmutable(datetime: $data['responseCompletedAt']);
|
||||
$responseCompletedAt->setTimezone(timezone: $timeZone);
|
||||
$nexusRawData->setResponseCompletedAt(responseCompletedAt: $responseCompletedAt);
|
||||
$pageView->setResponseCompletedAt(responseCompletedAt: $responseCompletedAt);
|
||||
}
|
||||
if (array_key_exists(key: 'method', array: $data)) {
|
||||
$nexusRawData->setMethod(method: $data['method']);
|
||||
$pageView->setMethod(method: $data['method']);
|
||||
}
|
||||
if (array_key_exists(key: 'url', array: $data)) {
|
||||
$nexusRawData->setUrl(url: $data['url']);
|
||||
$pageView->setUrl(url: $data['url']);
|
||||
}
|
||||
if (array_key_exists(key: 'formData', array: $data)) {
|
||||
$nexusRawData->setFormData(formData: $data['formData']);
|
||||
$pageView->setFormData(formData: $data['formData']);
|
||||
}
|
||||
if (array_key_exists(key: 'responseBody', array: $data)) {
|
||||
$nexusRawData->setResponseBody(responseBody: $data['responseBody']);
|
||||
$pageView->setResponseBody(responseBody: $data['responseBody']);
|
||||
}
|
||||
|
||||
return $nexusRawData;
|
||||
return $pageView;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,11 +43,11 @@ final class NexusRawDataManager
|
|||
);
|
||||
}
|
||||
|
||||
$submitter = $userAccessToken->getOwner();
|
||||
$owner = $userAccessToken->getOwner();
|
||||
|
||||
$nexusRawData->setCreatedAt(createdAt: $currentDateTime);
|
||||
$nexusRawData->setLastModifiedAt(lastModifiedAt: $currentDateTime);
|
||||
$nexusRawData->setSubmitter(submitter: $submitter);
|
||||
$nexusRawData->setOwner(owner: $owner);
|
||||
|
||||
$this->entityManager->persist($nexusRawData);
|
||||
$this->entityManager->flush();
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
<dd>{{ user_total_count }}</dd>
|
||||
<dt>Total user access tokens:</dt>
|
||||
<dd>{{ token_total_count }}</dd>
|
||||
<dt>Total submits:</dt>
|
||||
<dd>{{ data_total_count }}</dd>
|
||||
<dt>Last week submits:</dt>
|
||||
<dd>{{ data_weekly_count }}</dd>
|
||||
<dt>Yesterday submits:</dt>
|
||||
<dd>{{ data_daily_count }}</dd>
|
||||
<dt>Total submitted page views:</dt>
|
||||
<dd>{{ page_view_total_count }}</dd>
|
||||
<dt>Last week page views:</dt>
|
||||
<dd>{{ page_view_weekly_count }}</dd>
|
||||
<dt>Yesterday page views:</dt>
|
||||
<dd>{{ page_view_daily_count }}</dd>
|
||||
</dl>
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
|
Reference in New Issue