Skip to content

Shadowing: use DTO's #2331

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

Merged
merged 20 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8f40818
Shadow differences: redirect to configure page if not set up yet.
nickygerritsen Feb 13, 2024
b35e850
Also create submission if the source is not a ZIP.
nickygerritsen Feb 13, 2024
948dae4
Show import errors as shadow differences in menu count.
nickygerritsen Feb 13, 2024
30a4448
Install and enable serializer.
nickygerritsen Feb 13, 2024
69f46c3
Add provider data to API info.
nickygerritsen Feb 13, 2024
20687ae
Use DTO's for cached contest and API info data in external contest se…
nickygerritsen Feb 13, 2024
9ffb0ba
Use DTO's and the Symfony Serializer component for reading external c…
nickygerritsen Feb 14, 2024
7f883d8
Fix test for general info API.
nickygerritsen Feb 15, 2024
30032d4
Update webapp/src/Controller/API/GeneralInfoController.php
nickygerritsen Feb 15, 2024
2b9b930
Update webapp/src/Service/ExternalContestSourceService.php
nickygerritsen Feb 15, 2024
34c2cfe
Get rid of all fields from event DTO's we don't (currently) use.
nickygerritsen Feb 15, 2024
6eb5709
Add todo for checking some contest times.
nickygerritsen Feb 16, 2024
d10ca54
Don't use negation in ternary.
nickygerritsen Feb 26, 2024
cbd96f6
Restore formatting of file to not have a big diff.
nickygerritsen Feb 26, 2024
23e7726
Rename event data normalizer to denormalizer since that is all it does.
nickygerritsen Feb 26, 2024
78c1edc
Add tests for event parsing.
nickygerritsen Feb 26, 2024
7570245
Get rid of unused event classes.
nickygerritsen Feb 26, 2024
356e8ee
When calculating external source warning, the entity ID might be null.
nickygerritsen Feb 27, 2024
59719ff
State events do no not have an ID.
nickygerritsen Feb 27, 2024
7b13e51
Fix missing change from array to DTO.
nickygerritsen Feb 27, 2024
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
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"mbostock/d3": "^3.5",
"nelmio/api-doc-bundle": "^4.11",
"novus/nvd3": "^1.8",
"phpdocumentor/reflection-docblock": "^5.3",
"phpstan/phpdoc-parser": "^1.25",
"promphp/prometheus_client_php": "^2.6",
"ramsey/uuid": "^4.2",
"select2/select2": "4.*",
Expand All @@ -89,9 +91,12 @@
"symfony/intl": "6.4.*",
"symfony/mime": "6.4.*",
"symfony/monolog-bundle": "^3.8.0",
"symfony/property-access": "6.4.*",
"symfony/property-info": "6.4.*",
"symfony/runtime": "6.4.*",
"symfony/security-bundle": "6.4.*",
"symfony/security-csrf": "6.4.*",
"symfony/serializer": "6.4.*",
"symfony/stopwatch": "6.4.*",
"symfony/twig-bundle": "6.4.*",
"symfony/validator": "6.4.*",
Expand Down
102 changes: 100 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions webapp/config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ framework:
http_method_override: true
annotations: true
handle_all_throwables: true
serializer:
enabled: true
name_converter: serializer.name_converter.camel_case_to_snake_case

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
Expand Down
6 changes: 6 additions & 0 deletions webapp/src/Controller/API/GeneralInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller\API;

use App\DataTransferObject\ApiInfo;
use App\DataTransferObject\ApiInfoProvider;
use App\DataTransferObject\ApiVersion;
use App\DataTransferObject\DomJudgeApiInfo;
use App\DataTransferObject\ExtendedContestStatus;
Expand Down Expand Up @@ -99,6 +100,11 @@ public function getInfoAction(
version: self::CCS_SPEC_API_VERSION,
versionUrl: self::CCS_SPEC_API_URL,
name: 'DOMjudge',
//TODO: Add DOMjudge logo
provider: new ApiInfoProvider(
name: 'DOMjudge',
version: $this->getParameter('domjudge.version'),
),
domjudge: $domjudge
);
}
Expand Down
14 changes: 14 additions & 0 deletions webapp/src/Controller/Jury/ShadowDifferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller\Jury;

use App\DataTransferObject\SubmissionRestriction;
use App\Entity\ExternalContestSource;
use App\Service\ConfigurationService;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
Expand Down Expand Up @@ -64,6 +65,19 @@ public function indexAction(
return $this->redirectToRoute('jury_index');
}

/** @var ExternalContestSource|null $externalContestSource */
$externalContestSource = $this->em->createQueryBuilder()
->from(ExternalContestSource::class, 'ecs')
->select('ecs')
->andWhere('ecs.contest = :contest')
->setParameter('contest', $this->dj->getCurrentContest())
->getQuery()->getOneOrNullResult();

if (!$externalContestSource) {
$this->addFlash('warning', 'No external contest present yet, please configure one first');
return $this->redirectToRoute('jury_external_contest_manage');
}

// Close the session, as this might take a while and we don't need the session below.
$this->requestStack->getSession()->save();

Expand Down
1 change: 1 addition & 0 deletions webapp/src/DataTransferObject/ApiInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function __construct(
public readonly string $version,
public readonly string $versionUrl,
public readonly string $name,
public readonly ?ApiInfoProvider $provider,
#[Serializer\Exclude(if: '!object.domjudge')]
public readonly ?DomJudgeApiInfo $domjudge,
) {}
Expand Down
15 changes: 15 additions & 0 deletions webapp/src/DataTransferObject/ApiInfoProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject;

use JMS\Serializer\Annotation as Serializer;

class ApiInfoProvider
{
public function __construct(
public readonly string $name,
public readonly string $version,
#[Serializer\Exclude(if: '!object.buildDate')]
public readonly ?string $buildDate = null,
) {}
}
16 changes: 16 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/ClarificationEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

class ClarificationEvent implements EventData
{
public function __construct(
public readonly string $id,
public readonly string $text,
public readonly string $time,
public readonly ?string $fromTeamId,
public readonly ?string $toTeamId,
public readonly ?string $replyToId,
public readonly ?string $problemId,
) {}
}
16 changes: 16 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/ContestData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

class ContestData
{
public function __construct(
public readonly string $id,
public readonly string $name,
public readonly string $duration,
public readonly ?string $scoreboardFreezeDuration,
public readonly int $penaltyTime,
public readonly ?string $startTime,
// TODO: check for end time and scoreboard thaw time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to resolve before merging?

Copy link
Member Author

@nickygerritsen nickygerritsen Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. @vmcj wanted this comment. It would be a new “feature”

) {}
}
19 changes: 19 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/ContestEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

class ContestEvent implements EventData
{
public function __construct(
public readonly string $id,
public readonly string $name,
public readonly string $duration,
public readonly ?string $scoreboardType,
public readonly int $penaltyTime,
public readonly ?string $formalName,
public readonly ?string $startTime,
public readonly ?int $countdownPauseTime,
public readonly ?string $scoreboardFreezeDuration,
public readonly ?string $scoreboardThawTime,
) {}
}
20 changes: 20 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

/**
* @template-covariant T of EventData
*/
class Event
{
/**
* @param T[] $data
*/
public function __construct(
public readonly ?string $id,
public readonly EventType $type,
public readonly Operation $operation,
public readonly ?string $objectId,
public readonly array $data,
) {}
}
8 changes: 8 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/EventData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

interface EventData
{

}
65 changes: 65 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/EventType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

enum EventType: string
{
case ACCOUNTS = 'accounts';
case AWARDS = 'awards';
case CLARIFICATIONS = 'clarifications';
case CONTESTS = 'contests';
case GROUPS = 'groups';
case JUDGEMENTS = 'judgements';
case JUDGEMENT_TYPES = 'judgement-types';
case LANGUAGES = 'languages';
case ORGANIZATIONS = 'organizations';
case PROBLEMS = 'problems';
case RUNS = 'runs';
case STATE = 'state';
case SUBMISSIONS = 'submissions';
case TEAMS = 'teams';
case TEAM_MEMBERS = 'team-members';

public static function fromString(string $value): EventType
{
if ($value === 'contest') {
return EventType::CONTESTS;
}

return EventType::from($value);
}

/**
* @return class-string<EventData>|null
*/
public function getEventClass(): ?string
{
switch ($this) {
case self::CLARIFICATIONS:
return ClarificationEvent::class;
case self::CONTESTS:
return ContestEvent::class;
case self::GROUPS:
return GroupEvent::class;
case self::JUDGEMENTS:
return JudgementEvent::class;
case self::JUDGEMENT_TYPES:
return JudgementTypeEvent::class;
case self::LANGUAGES:
return LanguageEvent::class;
case self::ORGANIZATIONS:
return OrganizationEvent::class;
case self::PROBLEMS:
return ProblemEvent::class;
case self::RUNS:
return RunEvent::class;
case self::STATE:
return StateEvent::class;
case self::SUBMISSIONS:
return SubmissionEvent::class;
case self::TEAMS:
return TeamEvent::class;
}
return null;
}
}
15 changes: 15 additions & 0 deletions webapp/src/DataTransferObject/Shadowing/GroupEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php declare(strict_types=1);

namespace App\DataTransferObject\Shadowing;

class GroupEvent implements EventData
{
public function __construct(
public readonly string $id,
public readonly string $name,
public readonly ?string $icpcId,
public readonly ?bool $hidden,
public readonly ?int $sortorder,
public readonly ?string $color,
) {}
}
Loading