Skip to content

Commit

Permalink
Use location.description for location to be spec compliant.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickygerritsen committed Jan 19, 2024
1 parent 6ee27fb commit d90f594
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions doc/manual/import.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ fields:
- ``display_name`` (optional): the team display name. If provided, will display
this instead of the team name in certain places, like the scoreboard
- ``organization_id``: the ID of the team affiliation this team belongs to
- ``location`` (optional): the location of the team
- ``location.description`` (optional): the location of the team

If the ``data_source`` setting of DOMjudge is set to external, the ``id`` field will be the
ID used for the team and the ``group_ids`` and ``organization_id`` fields are the values as
Expand All @@ -183,7 +183,7 @@ Example ``teams.json``::
"group_ids": ["24"],
"name": "¡i¡i¡",
"organization_id": "INST-42",
"location": "AUD 10"
"location": {"description": "AUD 10"}
}, {
"id": "2",
"icpc_id": "447837",
Expand Down
11 changes: 10 additions & 1 deletion webapp/src/Entity/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Entity;

use App\Controller\API\AbstractRestController as ARC;
use App\Helpers\TeamLocation;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
Expand Down Expand Up @@ -88,7 +89,7 @@ class Team extends BaseApiEntity implements ExternalRelationshipEntityInterface,

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

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

#[Serializer\Groups([ARC::GROUP_NONSTRICT])]
#[Serializer\VirtualProperty]
#[Serializer\SerializedName('location')]
public function getLocationForApi(): ?TeamLocation
{
return $this->location ? new TeamLocation($this->location) : null;
}

public function setInternalComments(?string $comments): Team
{
$this->internalComments = $comments;
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/Helpers/TeamLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types=1);

namespace App\Helpers;

class TeamLocation
{
public function __construct(
public readonly string $description
) {}
}
2 changes: 1 addition & 1 deletion webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ public function importTeamsJson(array $data, ?string &$message = null, ?array &$
'name' => @$team['name'],
'display_name' => @$team['display_name'],
'publicdescription' => $team['public_description'] ?? @$team['members'],
'location' => @$team['location'],
'location' => @$team['location']['description'],
],
'team_affiliation' => [
'externalid' => $team['organization_id'] ?? null,
Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/Unit/Controller/API/TeamControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TeamControllerTest extends BaseTestCase
'display_name' => null,
'members' => null,
'photo' => null,
'location' => 'Utrecht',
'location' => ['description' => 'Utrecht'],
],
];

Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/Unit/Service/ImportExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ public function testImportTeamsJson(): void
"group_ids": ["24"],
"name": "¡i¡i¡",
"organization_id": "INST-42",
"location": "AUD 10"
"location": {"description": "AUD 10"}
}, {
"id": "12",
"icpc_id": "447837",
Expand Down

0 comments on commit d90f594

Please sign in to comment.