33namespace App \V1Module \Presenters ;
44
55use App \Helpers \MetaFormats \Attributes \Post ;
6- use App \Helpers \MetaFormats \Attributes \Query ;
76use App \Helpers \MetaFormats \Attributes \Path ;
8- use App \Helpers \MetaFormats \Type ;
9- use App \Helpers \MetaFormats \Validators \VArray ;
107use App \Helpers \MetaFormats \Validators \VBool ;
11- use App \Helpers \MetaFormats \Validators \VDouble ;
12- use App \Helpers \MetaFormats \Validators \VEmail ;
138use App \Helpers \MetaFormats \Validators \VInt ;
149use App \Helpers \MetaFormats \Validators \VMixed ;
1510use App \Helpers \MetaFormats \Validators \VString ;
16- use App \Helpers \MetaFormats \Validators \VTimestamp ;
1711use App \Helpers \MetaFormats \Validators \VUuid ;
1812use App \Exceptions \BadRequestException ;
1913use App \Exceptions \InternalServerException ;
20- use App \Exceptions \InvalidArgumentException ;
14+ use App \Exceptions \InvalidApiArgumentException ;
2115use App \Exceptions \InvalidStateException ;
2216use App \Exceptions \NotFoundException ;
2317use 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 );
0 commit comments