Skip to content
21 changes: 11 additions & 10 deletions app/V1Module/presenters/AssignmentSolutionReviewsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\BadRequestException;
use App\Exceptions\InternalServerException;
use App\Exceptions\ForbiddenRequestException;
Expand Down Expand Up @@ -90,7 +91,7 @@ public function checkDefault(string $id)
* @GET
* @throws InternalServerException
*/
#[Path("id", new VString(), "identifier of the solution", required: true)]
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
public function actionDefault(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand All @@ -114,7 +115,7 @@ public function checkUpdate(string $id)
* @throws InternalServerException
*/
#[Post("close", new VBool(), "If true, the review is closed. If false, the review is (re)opened.")]
#[Path("id", new VString(), "identifier of the solution", required: true)]
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
public function actionUpdate(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand Down Expand Up @@ -183,7 +184,7 @@ public function checkRemove(string $id)
* @DELETE
* @throws InternalServerException
*/
#[Path("id", new VString(), "identifier of the solution", required: true)]
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
public function actionRemove(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand Down Expand Up @@ -272,7 +273,7 @@ private function verifyCodeLocation(AssignmentSolution $solution, string $file,
"If true, no email notification will be sent (only applies when the review has been closed)",
required: false,
)]
#[Path("id", new VString(), "identifier of the solution", required: true)]
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
public function actionNewComment(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand All @@ -299,7 +300,7 @@ public function actionNewComment(string $id)
$this->reviewComments->persist($comment);

if ($solution->getReviewedAt() !== null) {
// review is already closed, this needs special treatement
// review is already closed, this needs special treatment
if ($issue) {
$solution->setIssuesCount($solution->getIssuesCount() + 1);
$this->assignmentSolutions->persist($solution);
Expand Down Expand Up @@ -345,7 +346,7 @@ public function checkEditComment(string $id, string $commentId)
"If true, no email notification will be sent (only applies when the review has been closed)",
required: false,
)]
#[Path("id", new VString(), "identifier of the solution", required: true)]
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
#[Path("commentId", new VString(), "identifier of the review comment", required: true)]
public function actionEditComment(string $id, string $commentId)
{
Expand All @@ -372,7 +373,7 @@ public function actionEditComment(string $id, string $commentId)
$this->reviewComments->persist($comment);

if ($solution->getReviewedAt() !== null) {
// review is already closed, this needs special treatement
// review is already closed, this needs special treatment
if ($issueChanged) {
$solution->setIssuesCount($solution->getIssuesCount() + ($issue ? 1 : -1));
$this->assignmentSolutions->persist($solution);
Expand Down Expand Up @@ -405,7 +406,7 @@ public function checkDeleteComment(string $id, string $commentId)
* Remove one comment from a review.
* @DELETE
*/
#[Path("id", new VString(), "identifier of the solution", required: true)]
#[Path("id", new VUuid(), "identifier of the solution", required: true)]
#[Path("commentId", new VString(), "identifier of the review comment", required: true)]
public function actionDeleteComment(string $id, string $commentId)
{
Expand All @@ -415,7 +416,7 @@ public function actionDeleteComment(string $id, string $commentId)

$solution = $this->assignmentSolutions->findOrThrow($id);
if ($solution->getReviewedAt() !== null) {
// review is already closed, this needs special treatement
// review is already closed, this needs special treatment
if ($isIssue) {
$solution->setIssuesCount($solution->getIssuesCount() - 1);
$this->assignmentSolutions->persist($solution);
Expand All @@ -441,7 +442,7 @@ public function checkPending(string $id)
* Along with that it returns all assignment entities of the corresponding solutions.
* @GET
*/
#[Path("id", new VString(), "of the user whose pending reviews are listed", required: true)]
#[Path("id", new VUuid(), "of the user whose pending reviews are listed", required: true)]
public function actionPending(string $id)
{
$user = $this->users->findOrThrow($id);
Expand Down
50 changes: 22 additions & 28 deletions app/V1Module/presenters/AssignmentSolutionsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
namespace App\V1Module\Presenters;

use App\Helpers\MetaFormats\Attributes\Post;
use App\Helpers\MetaFormats\Attributes\Query;
use App\Helpers\MetaFormats\Attributes\Path;
use App\Helpers\MetaFormats\Type;
use App\Helpers\MetaFormats\Validators\VArray;
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VEmail;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\BadRequestException;
use App\Exceptions\InternalServerException;
Expand Down Expand Up @@ -157,7 +151,7 @@ public function checkSolution(string $id)
* @GET
* @throws InternalServerException
*/
#[Path("id", new VString(), "Identifier of the solution", required: true)]
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
public function actionSolution(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand Down Expand Up @@ -189,7 +183,7 @@ public function checkUpdateSolution(string $id)
* @throws InternalServerException
*/
#[Post("note", new VString(0, 1024), "A note by the author of the solution")]
#[Path("id", new VString(), "Identifier of the solution", required: true)]
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
public function actionUpdateSolution(string $id)
{
$req = $this->getRequest();
Expand All @@ -213,7 +207,7 @@ public function checkDeleteSolution(string $id)
* @DELETE
* @throws ForbiddenRequestException
*/
#[Path("id", new VString(), "identifier of assignment solution", required: true)]
#[Path("id", new VUuid(), "identifier of assignment solution", required: true)]
public function actionDeleteSolution(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand Down Expand Up @@ -250,7 +244,7 @@ public function checkSubmissions(string $id)
* Get list of all submissions of a solution
* @GET
*/
#[Path("id", new VString(), "Identifier of the solution", required: true)]
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
public function actionSubmissions(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand Down Expand Up @@ -352,28 +346,28 @@ public function checkSetBonusPoints(string $id)
required: false,
nullable: true,
)]
#[Path("id", new VString(), "Identifier of the solution", required: true)]
#[Path("id", new VUuid(), "Identifier of the solution", required: true)]
public function actionSetBonusPoints(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
$assignment = $solution->getAssignment();
$author = $solution->getSolution()->getAuthor();
$oldBonusPoints = $solution->getBonusPoints();
$oldOverridenPoints = $solution->getOverriddenPoints();
$oldOverriddenPoints = $solution->getOverriddenPoints();

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

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

$solution->setBonusPoints($newBonusPoints);

// TODO: validations 'null|numericint' for overridenPoints cannot be used, because null is converted to empty
// TODO: string which immediately breaks stated validation... in the future, this behaviour has to change
// TODO: validations 'null|numericint' for overriddenPoints cannot be used, because null is converted to empty
// TODO: string which immediately breaks stated validation... in the future, this behavior has to change
// TODO: lucky third TODO
if (Validators::isNumericInt($overriddenPoints)) {
$solution->setOverriddenPoints($overriddenPoints);
Expand All @@ -382,7 +376,7 @@ public function actionSetBonusPoints(string $id)
$solution->setOverriddenPoints(null);
} else {
throw new InvalidApiArgumentException(
'overridenPoints',
'overriddenPoints',
"The value '$overriddenPoints' is not null|numericint"
);
}
Expand All @@ -391,7 +385,7 @@ public function actionSetBonusPoints(string $id)
$this->assignmentSolutions->flush();

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

// handle unique flags
$resetedSolution = null; // remeber original holder of a unique flag (for an email notification)
$previousHolder = null; // remember original holder of a unique flag (for an email notification)
/* @phpstan-ignore-next-line */
if ($unique && $value) {
// flag has to be set to false for all other solutions of a user
Expand All @@ -494,7 +488,7 @@ public function actionSetFlag(string $id, string $flag)
);
foreach ($assignmentSolutions as $assignmentSolution) {
if ($assignmentSolution->getFlag($flag)) {
$resetedSolution = $assignmentSolution;
$previousHolder = $assignmentSolution;
}
$assignmentSolution->setFlag($flag, false);
}
Expand All @@ -513,21 +507,21 @@ public function actionSetFlag(string $id, string $flag)
$this->getCurrentUser(),
$solution,
$value,
$resetedSolution
$previousHolder
);
}

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

$resSolutions = [$id => $this->assignmentSolutionViewFactory->getSolutionData($solution)];
if ($resetedSolution) {
$resSolutions[$resetedSolution->getId()] =
$this->assignmentSolutionViewFactory->getSolutionData($resetedSolution);
if ($previousHolder) {
$resSolutions[$previousHolder->getId()] =
$this->assignmentSolutionViewFactory->getSolutionData($previousHolder);
}

$bestSolution = $this->assignmentSolutions->findBestSolution(
Expand Down Expand Up @@ -567,7 +561,7 @@ public function checkDownloadSolutionArchive(string $id)
* @throws \Nette\Application\BadRequestException
* @throws \Nette\Application\AbortException
*/
#[Path("id", new VString(), "of assignment solution", required: true)]
#[Path("id", new VUuid(), "of assignment solution", required: true)]
public function actionDownloadSolutionArchive(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id);
Expand All @@ -592,7 +586,7 @@ public function checkFiles(string $id)
* @throws ForbiddenRequestException
* @throws NotFoundException
*/
#[Path("id", new VString(), "of assignment solution", required: true)]
#[Path("id", new VUuid(), "of assignment solution", required: true)]
public function actionFiles(string $id)
{
$solution = $this->assignmentSolutions->findOrThrow($id)->getSolution();
Expand Down Expand Up @@ -672,7 +666,7 @@ public function checkReviewRequests(string $id)
* Along with that it returns all assignment entities of the corresponding solutions.
* @GET
*/
#[Path("id", new VString(), "of the user whose solutions with requested reviews are listed", required: true)]
#[Path("id", new VUuid(), "of the user whose solutions with requested reviews are listed", required: true)]
public function actionReviewRequests(string $id)
{
$user = $this->users->findOrThrow($id);
Expand Down
12 changes: 0 additions & 12 deletions app/V1Module/presenters/AssignmentSolversPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

namespace App\V1Module\Presenters;

use App\Helpers\MetaFormats\Attributes\Post;
use App\Helpers\MetaFormats\Attributes\Query;
use App\Helpers\MetaFormats\Attributes\Path;
use App\Helpers\MetaFormats\Type;
use App\Helpers\MetaFormats\Validators\VArray;
use App\Helpers\MetaFormats\Validators\VBool;
use App\Helpers\MetaFormats\Validators\VDouble;
use App\Helpers\MetaFormats\Validators\VEmail;
use App\Helpers\MetaFormats\Validators\VInt;
use App\Helpers\MetaFormats\Validators\VMixed;
use App\Helpers\MetaFormats\Validators\VString;
use App\Helpers\MetaFormats\Validators\VTimestamp;
use App\Helpers\MetaFormats\Validators\VUuid;
use App\Exceptions\BadRequestException;
use App\Model\Entity\AssignmentSolutionSubmission;
use App\Model\Repository\Assignments;
use App\Model\Repository\AssignmentSolvers;
use App\Model\Repository\Users;
Expand Down
Loading