Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DTO's for POST/PUT request bodies. #2321

Merged
merged 5 commits into from
Mar 13, 2024

Conversation

nickygerritsen
Copy link
Member

Some notes:

  • We need the Symfony built in serializer for request mapping, so that is why I'm adding it. We can't get rid of the JMS one, since we use virtualproperty and type annotations, which the Symfony one doesn't support.
  • For adding submissions it's a bit ugly, since we have both the CLICS format and our own, so all fields are optional. Also our format uses file uploads, which the Symfony request mapper doesn't support.
  • I haven't done anything to the judgehost controller, but should we? We can add way more typing there this way as well.
  • All file uploads (logo's, etc) have also not been done.
  • The contest patch call can't use the assert\callback to check for values, since there CLICS has a distinction between not passing a variable and setting it to null. A bit ugly.
  • Some tests needed to be updated since the error messages are a bit different. Not a big issue I think.
  • If you supply no body, the Symfony request mapper produces an empty 400 error. Also not a big issue I think.

After this we should discuss what more to change to DTO's @vmcj, you have gone through most code.

@vmcj
Copy link
Member

vmcj commented Feb 9, 2024

After this we should discuss what more to change to DTO's @vmcj, you have gone through most code.

The first candidates would be the *TwigData arrays, collect*Table arrays and the *Stats arrays, the DOMJudgeService file also has a lot of ugly arrays

The other individual functions:

  • getConfigSpecification
  • findExecutableOptions
  • dataForEditor
  • getStats

@vmcj
Copy link
Member

vmcj commented Feb 9, 2024

Some notes:

* We need the Symfony built in serializer for request mapping, so that is why I'm adding it. We can't get rid of the JMS one, since we use virtualproperty and type annotations, which the Symfony one doesn't support.

What is the new way of working with them? Is one the superset of the other or do they overlap?

* I haven't done anything to the judgehost controller, but should we? We can add way more typing there this way as well.

I would say so? It would make it much easier for people to create an IOI judge or if we plan to change the judgedaemon to another implementation?

* All file uploads (logo's, etc) have also not been done.

* The contest patch call can't use the assert\callback to check for values, since there CLICS has a distinction between not passing a variable and setting it to `null`. A bit ugly.

Can we change the CLICS spec or is CLICS correct here?

* Some tests needed to be updated since the error messages are a bit different. Not a big issue I think.

Agree

* If you supply no body, the Symfony request mapper produces an empty 400 error. Also not a big issue I think.

That makes sense right, don't repeat that request if we can't do anything with it.

@nickygerritsen
Copy link
Member Author

Some notes:

* We need the Symfony built in serializer for request mapping, so that is why I'm adding it. We can't get rid of the JMS one, since we use virtualproperty and type annotations, which the Symfony one doesn't support.

What is the new way of working with them? Is one the superset of the other or do they overlap?

Nope they have different skillsets... Just use the JMS stuff like we used to and for request params the Symfony one will be used. Hopefully in the future the Symfony one is more nature and we can replace the JMS one.

* I haven't done anything to the judgehost controller, but should we? We can add way more typing there this way as well.

I would say so? It would make it much easier for people to create an IOI judge or if we plan to change the judgedaemon to another implementation?

Well the API itself won't change right, only the parsing logic. But I agree, it might be better.

* All file uploads (logo's, etc) have also not been done.

* The contest patch call can't use the assert\callback to check for values, since there CLICS has a distinction between not passing a variable and setting it to `null`. A bit ugly.

Can we change the CLICS spec or is CLICS correct here?

I don't think we can easily change the CLICS spec. This is just a drawback of the serializer: there is no easy way to distinguish between null and that a value has not been set. What I can think of is to use an actual setter (and not a constructor argument) and then keep track there if it is actually called, but not sure if that's better.

* Some tests needed to be updated since the error messages are a bit different. Not a big issue I think.

Agree

* If you supply no body, the Symfony request mapper produces an empty 400 error. Also not a big issue I think.

That makes sense right, don't repeat that request if we can't do anything with it.

Copy link
Member

@vmcj vmcj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

public function addAction(Request $request, ImportExportService $importExport): Response
{
public function addAction(
#[MapRequestPayload(validationFailedStatusCode: Response::HTTP_BAD_REQUEST)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to add this everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is a 422. If you can live with that we can drop the validationFailedStatusCode part, but then we need to update the tests (since we sometimes return a 400 and sometimes a 422) or we always need to return a 422.

}

public function provideAddInvalidData(): Generator
{
yield ['demo', [], "Argument 'text' is mandatory."];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't display any text anymore?

Copy link
Member Author

@nickygerritsen nickygerritsen Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you submit nothing there is an empty 400 (or 422 if we change the above thing) since Symfony doesn't know what to do. As soon as you supply any field (even an unknown one) we do display an error. It's a bit annoying but IMHO not a very big deal.

@nickygerritsen nickygerritsen added this pull request to the merge queue Mar 13, 2024
Merged via the queue into DOMjudge:main with commit ae3d6ea Mar 13, 2024
21 checks passed
@nickygerritsen nickygerritsen deleted the more-dtos branch March 13, 2024 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants