Skip to content

Commit b1640e9

Browse files
Add endpoint to fetch submissions by internal ID for domlogo
1 parent dc910da commit b1640e9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

webapp/src/Controller/API/SubmissionController.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,41 @@ public function singleAction(Request $request, string $id): Response
9999
return parent::performSingleAction($request, $id);
100100
}
101101

102+
/**
103+
* Get the given submission by external ID
104+
* @throws NonUniqueResultException
105+
*/
106+
#[IsGranted(new Expression("is_granted('ROLE_JUDGEHOST')"))]
107+
#[Rest\Get('submissions/by-internal-id/{internalId}')]
108+
#[OA\Response(
109+
response: 200,
110+
description: 'Returns the given submission for this contest by internal ID',
111+
content: new OA\JsonContent(ref: new Model(type: Submission::class))
112+
)]
113+
#[OA\Parameter(ref: '#/components/parameters/id')]
114+
public function singleByExternalIdAction(Request $request, string $internalId): Response
115+
{
116+
// Make sure we clear the entity manager class, for when this method is called multiple times
117+
// by internal requests.
118+
$this->em->clear();
119+
120+
$object = $this->getQueryBuilder($request)
121+
->andWhere('s.submitid = :id')
122+
->setParameter('id', $internalId)
123+
->getQuery()
124+
->getOneOrNullResult();
125+
126+
if ($object === null) {
127+
throw new NotFoundHttpException(sprintf('Object with internal ID \'%s\' not found', $internalId));
128+
}
129+
130+
if ($this instanceof QueryObjectTransformer) {
131+
$object = $this->transformObject($object);
132+
}
133+
134+
return $this->renderData($request, $object);
135+
}
136+
102137
/**
103138
* Add a submission to this contest.
104139
* @throws NonUniqueResultException

0 commit comments

Comments
 (0)