Skip to content

Commit 9ffb0ba

Browse files
Use DTO's and the Symfony Serializer component for reading external contest sources.
1 parent 20687ae commit 9ffb0ba

23 files changed

+1029
-507
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class Account implements EventData
6+
{
7+
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class Award implements EventData
6+
{
7+
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class ClarificationEvent implements EventData
6+
{
7+
public function __construct(
8+
public readonly string $id,
9+
public readonly string $text,
10+
public readonly string $time,
11+
public readonly string $contestTime,
12+
public readonly ?string $fromTeamId,
13+
public readonly ?string $toTeamId,
14+
public readonly ?string $replyToId,
15+
public readonly ?string $problemId,
16+
) {}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class ContestEvent implements EventData
6+
{
7+
public function __construct(
8+
public readonly string $id,
9+
public readonly string $name,
10+
public readonly string $duration,
11+
public readonly ?string $scoreboardType,
12+
public readonly int $penaltyTime,
13+
public readonly ?string $formalName,
14+
public readonly ?string $startTime,
15+
public readonly ?int $countdownPauseTime,
16+
public readonly ?string $scoreboardFreezeDuration,
17+
public readonly ?string $scoreboardThawTime,
18+
) {}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
/**
6+
* @template-covariant T of EventData
7+
*/
8+
class Event
9+
{
10+
/**
11+
* @param T[] $data
12+
*/
13+
public function __construct(
14+
public readonly ?string $id,
15+
public readonly EventType $type,
16+
public readonly Operation $operation,
17+
public readonly ?string $objectId,
18+
public readonly array $data,
19+
) {}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
interface EventData
6+
{
7+
8+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
enum EventType: string
6+
{
7+
case ACCOUNTS = 'accounts';
8+
case AWARDS = 'awards';
9+
case CLARIFICATIONS = 'clarifications';
10+
case CONTESTS = 'contests';
11+
case GROUPS = 'groups';
12+
case JUDGEMENTS = 'judgements';
13+
case JUDGEMENT_TYPES = 'judgement-types';
14+
case LANGUAGES = 'languages';
15+
case ORGANIZATIONS = 'organizations';
16+
case PROBLEMS = 'problems';
17+
case RUNS = 'runs';
18+
case STATE = 'state';
19+
case SUBMISSIONS = 'submissions';
20+
case TEAMS = 'teams';
21+
case TEAM_MEMBERS = 'team-members';
22+
23+
public static function fromString(string $value): EventType
24+
{
25+
if ($value === 'contest') {
26+
return EventType::CONTESTS;
27+
}
28+
29+
return EventType::from($value);
30+
}
31+
32+
/**
33+
* @return class-string<EventData>
34+
*/
35+
public function getEventClass(): string
36+
{
37+
switch ($this) {
38+
case self::ACCOUNTS:
39+
return Account::class;
40+
case self::AWARDS:
41+
return Award::class;
42+
case self::CLARIFICATIONS:
43+
return ClarificationEvent::class;
44+
case self::CONTESTS:
45+
return ContestEvent::class;
46+
case self::GROUPS:
47+
return GroupEvent::class;
48+
case self::JUDGEMENTS:
49+
return JudgementEvent::class;
50+
case self::JUDGEMENT_TYPES:
51+
return JudgementTypeEvent::class;
52+
case self::LANGUAGES:
53+
return LanguageEvent::class;
54+
case self::ORGANIZATIONS:
55+
return OrganizationEvent::class;
56+
case self::PROBLEMS:
57+
return ProblemEvent::class;
58+
case self::RUNS:
59+
return RunEvent::class;
60+
case self::STATE:
61+
return StateEvent::class;
62+
case self::SUBMISSIONS:
63+
return SubmissionEvent::class;
64+
case self::TEAMS:
65+
return TeamEvent::class;
66+
case self::TEAM_MEMBERS:
67+
return TeamMember::class;
68+
}
69+
}
70+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class GroupEvent implements EventData
6+
{
7+
public function __construct(
8+
public readonly string $id,
9+
public readonly string $name,
10+
public readonly ?string $icpcId,
11+
public readonly ?string $type,
12+
public readonly ?string $location,
13+
public readonly ?bool $hidden,
14+
public readonly ?int $sortorder,
15+
public readonly ?string $color,
16+
) {}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class JudgementEvent implements EventData
6+
{
7+
public function __construct(
8+
public readonly string $startTime,
9+
public readonly string $startContestTime,
10+
public readonly string $id,
11+
public readonly string $submissionId,
12+
public readonly ?float $maxRunTime,
13+
public readonly ?string $endTime,
14+
public readonly ?string $outputCompileAsString,
15+
public readonly ?string $judgementTypeId,
16+
) {}
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject\Shadowing;
4+
5+
class JudgementTypeEvent implements EventData
6+
{
7+
public function __construct(
8+
public readonly string $id,
9+
public readonly string $name,
10+
public readonly bool $penalty,
11+
public readonly bool $solved,
12+
) {}
13+
}

0 commit comments

Comments
 (0)