Skip to content

Commit 1c82ccf

Browse files
committed
merged
2 parents e455656 + 1e145d5 commit 1c82ccf

273 files changed

Lines changed: 1668 additions & 1629 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/V1Module/presenters/AssignmentSolutionReviewsPresenter.php

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,15 @@
33
namespace App\V1Module\Presenters;
44

55
use App\Helpers\MetaFormats\Attributes\Post;
6-
use App\Helpers\MetaFormats\Attributes\Query;
76
use App\Helpers\MetaFormats\Attributes\Path;
8-
use App\Helpers\MetaFormats\Type;
9-
use App\Helpers\MetaFormats\Validators\VArray;
107
use App\Helpers\MetaFormats\Validators\VBool;
11-
use App\Helpers\MetaFormats\Validators\VDouble;
12-
use App\Helpers\MetaFormats\Validators\VEmail;
138
use App\Helpers\MetaFormats\Validators\VInt;
14-
use App\Helpers\MetaFormats\Validators\VMixed;
159
use App\Helpers\MetaFormats\Validators\VString;
16-
use App\Helpers\MetaFormats\Validators\VTimestamp;
1710
use App\Helpers\MetaFormats\Validators\VUuid;
1811
use App\Exceptions\BadRequestException;
1912
use App\Exceptions\InternalServerException;
20-
use App\Exceptions\InvalidArgumentException;
21-
use App\Exceptions\InvalidStateException;
22-
use App\Exceptions\NotFoundException;
23-
use App\Exceptions\NotReadyException;
2413
use App\Exceptions\ForbiddenRequestException;
2514
use App\Helpers\Notifications\ReviewsEmailsSender;
26-
use App\Helpers\Validators;
2715
use App\Model\Entity\AssignmentSolution;
2816
use App\Model\Entity\ReviewComment;
2917
use App\Model\Repository\AssignmentSolutions;
@@ -103,7 +91,7 @@ public function checkDefault(string $id)
10391
* @GET
10492
* @throws InternalServerException
10593
*/
106-
#[Path("id", new VString(), "identifier of the solution", required: true)]
94+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
10795
public function actionDefault(string $id)
10896
{
10997
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -127,7 +115,7 @@ public function checkUpdate(string $id)
127115
* @throws InternalServerException
128116
*/
129117
#[Post("close", new VBool(), "If true, the review is closed. If false, the review is (re)opened.")]
130-
#[Path("id", new VString(), "identifier of the solution", required: true)]
118+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
131119
public function actionUpdate(string $id)
132120
{
133121
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -196,7 +184,7 @@ public function checkRemove(string $id)
196184
* @DELETE
197185
* @throws InternalServerException
198186
*/
199-
#[Path("id", new VString(), "identifier of the solution", required: true)]
187+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
200188
public function actionRemove(string $id)
201189
{
202190
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -285,7 +273,7 @@ private function verifyCodeLocation(AssignmentSolution $solution, string $file,
285273
"If true, no email notification will be sent (only applies when the review has been closed)",
286274
required: false,
287275
)]
288-
#[Path("id", new VString(), "identifier of the solution", required: true)]
276+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
289277
public function actionNewComment(string $id)
290278
{
291279
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -312,7 +300,7 @@ public function actionNewComment(string $id)
312300
$this->reviewComments->persist($comment);
313301

314302
if ($solution->getReviewedAt() !== null) {
315-
// review is already closed, this needs special treatement
303+
// review is already closed, this needs special treatment
316304
if ($issue) {
317305
$solution->setIssuesCount($solution->getIssuesCount() + 1);
318306
$this->assignmentSolutions->persist($solution);
@@ -358,7 +346,7 @@ public function checkEditComment(string $id, string $commentId)
358346
"If true, no email notification will be sent (only applies when the review has been closed)",
359347
required: false,
360348
)]
361-
#[Path("id", new VString(), "identifier of the solution", required: true)]
349+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
362350
#[Path("commentId", new VString(), "identifier of the review comment", required: true)]
363351
public function actionEditComment(string $id, string $commentId)
364352
{
@@ -385,7 +373,7 @@ public function actionEditComment(string $id, string $commentId)
385373
$this->reviewComments->persist($comment);
386374

387375
if ($solution->getReviewedAt() !== null) {
388-
// review is already closed, this needs special treatement
376+
// review is already closed, this needs special treatment
389377
if ($issueChanged) {
390378
$solution->setIssuesCount($solution->getIssuesCount() + ($issue ? 1 : -1));
391379
$this->assignmentSolutions->persist($solution);
@@ -418,7 +406,7 @@ public function checkDeleteComment(string $id, string $commentId)
418406
* Remove one comment from a review.
419407
* @DELETE
420408
*/
421-
#[Path("id", new VString(), "identifier of the solution", required: true)]
409+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
422410
#[Path("commentId", new VString(), "identifier of the review comment", required: true)]
423411
public function actionDeleteComment(string $id, string $commentId)
424412
{
@@ -428,7 +416,7 @@ public function actionDeleteComment(string $id, string $commentId)
428416

429417
$solution = $this->assignmentSolutions->findOrThrow($id);
430418
if ($solution->getReviewedAt() !== null) {
431-
// review is already closed, this needs special treatement
419+
// review is already closed, this needs special treatment
432420
if ($isIssue) {
433421
$solution->setIssuesCount($solution->getIssuesCount() - 1);
434422
$this->assignmentSolutions->persist($solution);
@@ -454,7 +442,7 @@ public function checkPending(string $id)
454442
* Along with that it returns all assignment entities of the corresponding solutions.
455443
* @GET
456444
*/
457-
#[Path("id", new VString(), "of the user whose pending reviews are listed", required: true)]
445+
#[Path("id", new VUuid(), "of the user whose pending reviews are listed", required: true)]
458446
public function actionPending(string $id)
459447
{
460448
$user = $this->users->findOrThrow($id);

app/V1Module/presenters/AssignmentSolutionsPresenter.php

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
namespace App\V1Module\Presenters;
44

55
use App\Helpers\MetaFormats\Attributes\Post;
6-
use App\Helpers\MetaFormats\Attributes\Query;
76
use App\Helpers\MetaFormats\Attributes\Path;
8-
use App\Helpers\MetaFormats\Type;
9-
use App\Helpers\MetaFormats\Validators\VArray;
107
use App\Helpers\MetaFormats\Validators\VBool;
11-
use App\Helpers\MetaFormats\Validators\VDouble;
12-
use App\Helpers\MetaFormats\Validators\VEmail;
138
use App\Helpers\MetaFormats\Validators\VInt;
149
use App\Helpers\MetaFormats\Validators\VMixed;
1510
use App\Helpers\MetaFormats\Validators\VString;
16-
use App\Helpers\MetaFormats\Validators\VTimestamp;
1711
use App\Helpers\MetaFormats\Validators\VUuid;
1812
use App\Exceptions\BadRequestException;
1913
use App\Exceptions\InternalServerException;
20-
use App\Exceptions\InvalidArgumentException;
14+
use App\Exceptions\InvalidApiArgumentException;
2115
use App\Exceptions\InvalidStateException;
2216
use App\Exceptions\NotFoundException;
2317
use App\Exceptions\NotReadyException;
@@ -157,7 +151,7 @@ public function checkSolution(string $id)
157151
* @GET
158152
* @throws InternalServerException
159153
*/
160-
#[Path("id", new VString(), "Identifier of the solution", required: true)]
154+
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
161155
public function actionSolution(string $id)
162156
{
163157
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -189,7 +183,7 @@ public function checkUpdateSolution(string $id)
189183
* @throws InternalServerException
190184
*/
191185
#[Post("note", new VString(0, 1024), "A note by the author of the solution")]
192-
#[Path("id", new VString(), "Identifier of the solution", required: true)]
186+
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
193187
public function actionUpdateSolution(string $id)
194188
{
195189
$req = $this->getRequest();
@@ -213,7 +207,7 @@ public function checkDeleteSolution(string $id)
213207
* @DELETE
214208
* @throws ForbiddenRequestException
215209
*/
216-
#[Path("id", new VString(), "identifier of assignment solution", required: true)]
210+
#[Path("id", new VUuid(), "identifier of assignment solution", required: true)]
217211
public function actionDeleteSolution(string $id)
218212
{
219213
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -250,7 +244,7 @@ public function checkSubmissions(string $id)
250244
* Get list of all submissions of a solution
251245
* @GET
252246
*/
253-
#[Path("id", new VString(), "Identifier of the solution", required: true)]
247+
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
254248
public function actionSubmissions(string $id)
255249
{
256250
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -341,7 +335,7 @@ public function checkSetBonusPoints(string $id)
341335
* Returns array of solution entities that has been changed by this.
342336
* @POST
343337
* @throws NotFoundException
344-
* @throws InvalidArgumentException
338+
* @throws InvalidApiArgumentException
345339
* @throws InvalidStateException
346340
*/
347341
#[Post("bonusPoints", new VInt(), "New amount of bonus points, can be negative number")]
@@ -352,37 +346,37 @@ public function checkSetBonusPoints(string $id)
352346
required: false,
353347
nullable: true,
354348
)]
355-
#[Path("id", new VString(), "Identifier of the solution", required: true)]
349+
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
356350
public function actionSetBonusPoints(string $id)
357351
{
358352
$solution = $this->assignmentSolutions->findOrThrow($id);
359353
$assignment = $solution->getAssignment();
360354
$author = $solution->getSolution()->getAuthor();
361355
$oldBonusPoints = $solution->getBonusPoints();
362-
$oldOverridenPoints = $solution->getOverriddenPoints();
356+
$oldOverriddenPoints = $solution->getOverriddenPoints();
363357

364358
$newBonusPoints = $this->getRequest()->getPost("bonusPoints");
365359
$overriddenPoints = $this->getRequest()->getPost("overriddenPoints");
366360

367361
// remember, who was the best in case the new points will change that
368362
$oldBest = null;
369-
if ($assignment && ($oldBonusPoints !== $newBonusPoints || $oldOverridenPoints !== $overriddenPoints)) {
363+
if ($assignment && ($oldBonusPoints !== $newBonusPoints || $oldOverriddenPoints !== $overriddenPoints)) {
370364
$oldBest = $this->assignmentSolutions->findBestSolution($assignment, $author);
371365
}
372366

373367
$solution->setBonusPoints($newBonusPoints);
374368

375-
// TODO: validations 'null|numericint' for overridenPoints cannot be used, because null is converted to empty
376-
// TODO: string which immediately breaks stated validation... in the future, this behaviour has to change
369+
// TODO: validations 'null|numericint' for overriddenPoints cannot be used, because null is converted to empty
370+
// TODO: string which immediately breaks stated validation... in the future, this behavior has to change
377371
// TODO: lucky third TODO
378372
if (Validators::isNumericInt($overriddenPoints)) {
379373
$solution->setOverriddenPoints($overriddenPoints);
380374
} else {
381375
if (empty($overriddenPoints)) {
382376
$solution->setOverriddenPoints(null);
383377
} else {
384-
throw new InvalidArgumentException(
385-
"overridenPoints",
378+
throw new InvalidApiArgumentException(
379+
'overriddenPoints',
386380
"The value '$overriddenPoints' is not null|numericint"
387381
);
388382
}
@@ -391,7 +385,7 @@ public function actionSetBonusPoints(string $id)
391385
$this->assignmentSolutions->flush();
392386

393387
$changedSolutions = []; // list of changed solutions reported back in payload
394-
if ($oldBonusPoints !== $newBonusPoints || $oldOverridenPoints !== $overriddenPoints) {
388+
if ($oldBonusPoints !== $newBonusPoints || $oldOverriddenPoints !== $overriddenPoints) {
395389
$this->pointsChangedEmailsSender->solutionPointsUpdated($solution);
396390
$changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($solution);
397391
if ($assignment) {
@@ -445,7 +439,7 @@ public function checkSetFlag(string $id, string $flag)
445439
* @throws \Exception
446440
*/
447441
#[Post("value", new VBool(), "True or false which should be set to given flag name", required: true)]
448-
#[Path("id", new VString(), "identifier of the solution", required: true)]
442+
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
449443
#[Path("flag", new VString(), "name of the flag which should to be changed", required: true)]
450444
public function actionSetFlag(string $id, string $flag)
451445
{
@@ -484,7 +478,7 @@ public function actionSetFlag(string $id, string $flag)
484478
);
485479

486480
// handle unique flags
487-
$resetedSolution = null; // remeber original holder of a unique flag (for an email notification)
481+
$previousHolder = null; // remember original holder of a unique flag (for an email notification)
488482
/* @phpstan-ignore-next-line */
489483
if ($unique && $value) {
490484
// flag has to be set to false for all other solutions of a user
@@ -494,7 +488,7 @@ public function actionSetFlag(string $id, string $flag)
494488
);
495489
foreach ($assignmentSolutions as $assignmentSolution) {
496490
if ($assignmentSolution->getFlag($flag)) {
497-
$resetedSolution = $assignmentSolution;
491+
$previousHolder = $assignmentSolution;
498492
}
499493
$assignmentSolution->setFlag($flag, false);
500494
}
@@ -513,21 +507,21 @@ public function actionSetFlag(string $id, string $flag)
513507
$this->getCurrentUser(),
514508
$solution,
515509
$value,
516-
$resetedSolution
510+
$previousHolder
517511
);
518512
}
519513

520-
// assemble response (all entites and stats that may have changed)
514+
// assemble response (all entities and stats that may have changed)
521515
$assignmentId = $solution->getAssignment()->getId();
522516
$groupOfSolution = $solution->getAssignment()->getGroup();
523517
if ($groupOfSolution === null) {
524518
throw new NotFoundException("Group for assignment '$id' was not found");
525519
}
526520

527-
$resSolutions = [ $id => $this->assignmentSolutionViewFactory->getSolutionData($solution) ];
528-
if ($resetedSolution) {
529-
$resSolutions[$resetedSolution->getId()] =
530-
$this->assignmentSolutionViewFactory->getSolutionData($resetedSolution);
521+
$resSolutions = [$id => $this->assignmentSolutionViewFactory->getSolutionData($solution)];
522+
if ($previousHolder) {
523+
$resSolutions[$previousHolder->getId()] =
524+
$this->assignmentSolutionViewFactory->getSolutionData($previousHolder);
531525
}
532526

533527
$bestSolution = $this->assignmentSolutions->findBestSolution(
@@ -567,7 +561,7 @@ public function checkDownloadSolutionArchive(string $id)
567561
* @throws \Nette\Application\BadRequestException
568562
* @throws \Nette\Application\AbortException
569563
*/
570-
#[Path("id", new VString(), "of assignment solution", required: true)]
564+
#[Path("id", new VUuid(), "of assignment solution", required: true)]
571565
public function actionDownloadSolutionArchive(string $id)
572566
{
573567
$solution = $this->assignmentSolutions->findOrThrow($id);
@@ -592,7 +586,7 @@ public function checkFiles(string $id)
592586
* @throws ForbiddenRequestException
593587
* @throws NotFoundException
594588
*/
595-
#[Path("id", new VString(), "of assignment solution", required: true)]
589+
#[Path("id", new VUuid(), "of assignment solution", required: true)]
596590
public function actionFiles(string $id)
597591
{
598592
$solution = $this->assignmentSolutions->findOrThrow($id)->getSolution();
@@ -672,7 +666,7 @@ public function checkReviewRequests(string $id)
672666
* Along with that it returns all assignment entities of the corresponding solutions.
673667
* @GET
674668
*/
675-
#[Path("id", new VString(), "of the user whose solutions with requested reviews are listed", required: true)]
669+
#[Path("id", new VUuid(), "of the user whose solutions with requested reviews are listed", required: true)]
676670
public function actionReviewRequests(string $id)
677671
{
678672
$user = $this->users->findOrThrow($id);

app/V1Module/presenters/AssignmentSolversPresenter.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@
22

33
namespace App\V1Module\Presenters;
44

5-
use App\Helpers\MetaFormats\Attributes\Post;
65
use App\Helpers\MetaFormats\Attributes\Query;
7-
use App\Helpers\MetaFormats\Attributes\Path;
8-
use App\Helpers\MetaFormats\Type;
9-
use App\Helpers\MetaFormats\Validators\VArray;
10-
use App\Helpers\MetaFormats\Validators\VBool;
11-
use App\Helpers\MetaFormats\Validators\VDouble;
12-
use App\Helpers\MetaFormats\Validators\VEmail;
13-
use App\Helpers\MetaFormats\Validators\VInt;
14-
use App\Helpers\MetaFormats\Validators\VMixed;
15-
use App\Helpers\MetaFormats\Validators\VString;
16-
use App\Helpers\MetaFormats\Validators\VTimestamp;
176
use App\Helpers\MetaFormats\Validators\VUuid;
187
use App\Exceptions\BadRequestException;
19-
use App\Model\Entity\AssignmentSolutionSubmission;
208
use App\Model\Repository\Assignments;
219
use App\Model\Repository\AssignmentSolvers;
2210
use App\Model\Repository\Users;

0 commit comments

Comments
 (0)