Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Enhancement/endpoints cleanup #61

Merged
merged 32 commits into from
Mar 9, 2024

Conversation

AronBuzogany
Copy link
Contributor

No description provided.

@AronBuzogany AronBuzogany marked this pull request as ready for review March 7, 2024 08:27
"""
This function will return all the admins of a course
"""
abort_url = API_URL + "/courses/" + str(course_id) + "/admins"
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

"""
Api endpoint for adding new admins to a course, can only be done by the teacher
"""
abort_url = API_URL + "/courses/" + str(course_id) + "/admins"
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

"""
Api endpoint for removing admins of a course, can only be done by the teacher
"""
abort_url = API_URL + "/courses/" + str(course_id) + "/admins"
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

}

return {
"message": "Succesfully retrieved course with course_id: " + str(course_id),
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

to get all the users assigned to a course
everyone can get this data so no need to have uid query in the link
"""
abort_url = API_URL + "/courses/" + str(course_id) + "/students"
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

return json_message(message), 400
add_abort_if_error(CourseStudent(uid=uid, course_id=course_id), abort_url)
commit_abort_if_error(abort_url)
response = json_message("User were succesfully added to the course")
Copy link
Contributor

Choose a reason for hiding this comment

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

User -> Users

delete_abort_if_error(student_relation, abort_url)
commit_abort_if_error(abort_url)

response = json_message("User were succesfully removed from the course")
Copy link
Contributor

Choose a reason for hiding this comment

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

User -> Users

HTTPException: If the current user is not authorized or
if the UID of the person to be made an admin is missing in the request body.
"""
url = API_URL + "/courses/" + str(course_id) + "/admins"
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

403: If the user is not authorized to assign new students to the course.
400: If the request body does not contain the required 'students' field.
"""
url = API_URL + "/courses/" + str(course_id) + "/students"
Copy link
Contributor

Choose a reason for hiding this comment

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

use f-strings

@@ -0,0 +1,76 @@
"""
This module contains functions that are not related to anything specific but
are ought to be used throughout the project.
Copy link
Contributor

Choose a reason for hiding this comment

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

but are ought is wrong, you can say the functions ought to be used if they should be used, or the functions are usable if they can be used

@AronBuzogany AronBuzogany requested a review from Vucis March 8, 2024 11:42
return jsonify({
"data": new_instance,
"message": "Object created succesfully.",
"url": urljoin(response_url_base, str(getattr(new_instance, url_id_field)))}), 201
Copy link
Contributor

Choose a reason for hiding this comment

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

should be
url": urljoin(response_url_base + "/", str(getattr(new_instance, url_id_field)))}), 201
otherwise the response url won't be returned correctly

@AronBuzogany AronBuzogany self-assigned this Mar 8, 2024
@AronBuzogany AronBuzogany merged commit a394736 into development Mar 9, 2024
4 checks passed
@AronBuzogany AronBuzogany deleted the enhancement/endpoints-cleanup branch March 9, 2024 09:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup code duplication in endpoints and create file for eacht endpoint seperately
4 participants