Skip to content

Commit d90f594

Browse files
Use location.description for location to be spec compliant.
1 parent 6ee27fb commit d90f594

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

doc/manual/import.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fields:
166166
- ``display_name`` (optional): the team display name. If provided, will display
167167
this instead of the team name in certain places, like the scoreboard
168168
- ``organization_id``: the ID of the team affiliation this team belongs to
169-
- ``location`` (optional): the location of the team
169+
- ``location.description`` (optional): the location of the team
170170

171171
If the ``data_source`` setting of DOMjudge is set to external, the ``id`` field will be the
172172
ID used for the team and the ``group_ids`` and ``organization_id`` fields are the values as
@@ -183,7 +183,7 @@ Example ``teams.json``::
183183
"group_ids": ["24"],
184184
"name": "¡i¡i¡",
185185
"organization_id": "INST-42",
186-
"location": "AUD 10"
186+
"location": {"description": "AUD 10"}
187187
}, {
188188
"id": "2",
189189
"icpc_id": "447837",

webapp/src/Entity/Team.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Entity;
44

55
use App\Controller\API\AbstractRestController as ARC;
6+
use App\Helpers\TeamLocation;
67
use Doctrine\Common\Collections\ArrayCollection;
78
use Doctrine\Common\Collections\Collection;
89
use Doctrine\ORM\Mapping as ORM;
@@ -88,7 +89,7 @@ class Team extends BaseApiEntity implements ExternalRelationshipEntityInterface,
8889

8990
#[ORM\Column(nullable: true, options: ['comment' => 'Physical location of team'])]
9091
#[OA\Property(nullable: true)]
91-
#[Serializer\Groups([ARC::GROUP_NONSTRICT])]
92+
#[Serializer\Exclude]
9293
private ?string $location = null;
9394

9495
#[ORM\Column(
@@ -297,6 +298,14 @@ public function getLocation(): ?string
297298
return $this->location;
298299
}
299300

301+
#[Serializer\Groups([ARC::GROUP_NONSTRICT])]
302+
#[Serializer\VirtualProperty]
303+
#[Serializer\SerializedName('location')]
304+
public function getLocationForApi(): ?TeamLocation
305+
{
306+
return $this->location ? new TeamLocation($this->location) : null;
307+
}
308+
300309
public function setInternalComments(?string $comments): Team
301310
{
302311
$this->internalComments = $comments;

webapp/src/Helpers/TeamLocation.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Helpers;
4+
5+
class TeamLocation
6+
{
7+
public function __construct(
8+
public readonly string $description
9+
) {}
10+
}

webapp/src/Service/ImportExportService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$
854854
'name' => @$team['name'],
855855
'display_name' => @$team['display_name'],
856856
'publicdescription' => $team['public_description'] ?? @$team['members'],
857-
'location' => @$team['location'],
857+
'location' => @$team['location']['description'],
858858
],
859859
'team_affiliation' => [
860860
'externalid' => $team['organization_id'] ?? null,

webapp/tests/Unit/Controller/API/TeamControllerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TeamControllerTest extends BaseTestCase
2222
'display_name' => null,
2323
'members' => null,
2424
'photo' => null,
25-
'location' => 'Utrecht',
25+
'location' => ['description' => 'Utrecht'],
2626
],
2727
];
2828

webapp/tests/Unit/Service/ImportExportServiceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public function testImportTeamsJson(): void
697697
"group_ids": ["24"],
698698
"name": "¡i¡i¡",
699699
"organization_id": "INST-42",
700-
"location": "AUD 10"
700+
"location": {"description": "AUD 10"}
701701
}, {
702702
"id": "12",
703703
"icpc_id": "447837",

0 commit comments

Comments
 (0)