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

Backend/feature/user endpoint #30

Merged
merged 40 commits into from
Mar 9, 2024
Merged

Conversation

warreprovoost
Copy link
Contributor

User endpoint created

  • REST Api added for get/post/delete/patch of users
  • Tests for all the methods
  • Fixed endpoint tests on github actions
  • Dockerfile edited to run locally

The signature of URL.create(...) should be the same for everyone.
Pycharm added the minimal version in the requirements, is this okay?

@warreprovoost warreprovoost self-assigned this Feb 25, 2024
@warreprovoost warreprovoost linked an issue Feb 25, 2024 that may be closed by this pull request
@warreprovoost warreprovoost added backend Everything related to the backend of our project feature labels Feb 25, 2024
@warreprovoost warreprovoost marked this pull request as draft February 25, 2024 16:20
@warreprovoost warreprovoost marked this pull request as ready for review February 25, 2024 16:29
@warreprovoost warreprovoost requested a review from Vucis February 25, 2024 16:30
Copy link
Contributor

@AronBuzogany AronBuzogany left a comment

Choose a reason for hiding this comment

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

As in comments above, implement the users/{user_id} endpoint. This shouldn't be too much work as you already have the functionality.

backend/project/endpoints/index/OpenAPI_Object.json Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/pylintrc Outdated Show resolved Hide resolved
backend/tests/endpoints/user_test.py Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/tests/endpoints/user_test.py Outdated Show resolved Hide resolved
backend/tests/endpoints/user_test.py Outdated Show resolved Hide resolved
backend/tests/endpoints/user_test.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
backend/project/endpoints/users.py Outdated Show resolved Hide resolved
Copy link
Contributor

@AronBuzogany AronBuzogany left a comment

Choose a reason for hiding this comment

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

To stay consistent with other endpoints, don't capitalize your response keys. In your case Message -> message. Also, next to only a message or only data. In each case provide at least the following 3 fields: message, url and data. Except for delete where there is no data

# Conflicts:
#	backend/project/__init__.py
#	backend/project/__main__.py
#	backend/project/endpoints/index/OpenAPI_Object.json
#	backend/project/models/users.py
#	backend/tests/endpoints/conftest.py
#	backend/tests/models/conftest.py
#	backend/tests/models/course_test.py
Copy link
Contributor

@Gerwoud Gerwoud left a comment

Choose a reason for hiding this comment

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

Looks good in general
Maybe add 200 to the returns for readability
and the returns in try

backend/project/endpoints/users.py Outdated Show resolved Hide resolved
@warreprovoost warreprovoost requested a review from Gerwoud March 8, 2024 14:36
Copy link
Contributor

@AronBuzogany AronBuzogany left a comment

Choose a reason for hiding this comment

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

You also forgot url field for every internal error 500. Don't forget to adjust the OpenAPI object with those changes also

backend/project/endpoints/users.py Outdated Show resolved Hide resolved
if user is None:
return {"message": "User not found!"}, 404

user_js = {
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this extra step, you can pass user as value of "data" field

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests fail if i don't do this

Copy link
Contributor

Choose a reason for hiding this comment

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

That's because you register your endpoints to the API. You should still register them to the blueprint. Calling Api(bp) already sets the appropriate middleware etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the result of user = db.session.get(userModel, user_id) is a User(...) object, how is this supposed to go into the json?

Copy link
Contributor

Choose a reason for hiding this comment

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

See current version of development this is being done all the time. This is the reason you had to make your model a dataclass.


# Save the changes to the database
db.session.commit()
user_js = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

backend/project/endpoints/users.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Gerwoud Gerwoud left a comment

Choose a reason for hiding this comment

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

Some small issues left

@AronBuzogany
Copy link
Contributor

@warreprovoost resolve branch conflicts before asking for a review

@warreprovoost
Copy link
Contributor Author

@warreprovoost resolve branch conflicts before asking for a review

@AronBuzogany my bad did not see it, should be good now

@Vucis Vucis merged commit f2dd5da into development Mar 9, 2024
2 checks passed
@Vucis Vucis deleted the backend/feature/user-endpoint branch March 9, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Everything related to the backend of our project feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creating api endpoint for users
5 participants