-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate APIs from HTTPs to python calls (#90)
* feat: add python methods to use instead of APIs - add pin, unpin, commentables count_stats and get user's data by user id python calls that'll be used by edx-platform instead of HTTPs * feat: code refactor - call python native APIs in V2 HTTPs APIs * feat: add comments APIs and enhance APIs structure - add create_child_comment, create_parent_comment, delete_comment, get_parent_comment, update_comment, python calls that'll be used by edx-platform instead of HTTPs * feat: code refactoring - code refactor - pass params instead of a single dict to python native APIs - add proper docstrings - move those functions to model_utils which are accessing models * docs: add doc for tracking native APIs responses - add responses for create_parent_comment, create_child_comment, update_comment, get_commentables_stats, get_parent_comment, get_user, pin_thread, unpin_thread native APIs * feat: remove ObjectId, use str instead * fix: quality checks * feat: migrate views * fix: mypy issues - https://github.com/edly-io/forum/actions/runs/11101805065/job/30840222003?pr=90 * fix: e2e tests * fix: linting issues * fix: active threads * fix: apis * fix: serailizers, export APIs and fix CI * refactor: revert str to objectId --------- Co-authored-by: Muhammad Faraz Maqsood <[email protected]> Co-authored-by: Muhammad Faraz Maqsood <[email protected]> Co-authored-by: Ali-Salman29 <[email protected]>
- Loading branch information
1 parent
764c53a
commit d8f109a
Showing
34 changed files
with
2,918 additions
and
1,333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,382 @@ | ||
=========================== | ||
Python Native API Responses | ||
=========================== | ||
|
||
This document outlines the structure of responses for various Python native APIs related to comments, threads, and user information in the context of course discussions. | ||
|
||
Create Parent Comment(create_parent_comment) API | ||
================================================ | ||
Creates a parent comment in the course discussion. | ||
|
||
Response Example: | ||
----------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66eaf98e6592735b5a38129f", | ||
"body": "<p>parent comment</p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": false, | ||
"anonymous_to_peers": false, | ||
"created_at": "2024-09-18T16:02:22Z", | ||
"updated_at": "2024-09-18T16:02:22Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 0, | ||
"up_count": 0, | ||
"down_count": 0, | ||
"point": 0 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [], | ||
"closed": false, | ||
"type": "comment", | ||
"endorsed": false, | ||
"depth": 0, | ||
"thread_id": "66df3056d77f29ace2ff201d", | ||
"parent_id": null, | ||
"child_count": 0 | ||
} | ||
Create Child Comment(create_child_comment) API | ||
============================================== | ||
Creates a child comment in response to a parent comment. | ||
|
||
Response Example: | ||
----------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66eafa538e98584d34d47969", | ||
"body": "<p>child comment</p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": false, | ||
"anonymous_to_peers": false, | ||
"created_at": "2024-09-18T16:05:39Z", | ||
"updated_at": "2024-09-18T16:05:39Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 0, | ||
"up_count": 0, | ||
"down_count": 0, | ||
"point": 0 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [], | ||
"closed": false, | ||
"type": "comment", | ||
"endorsed": false, | ||
"depth": 1, | ||
"thread_id": "66df3056d77f29ace2ff201d", | ||
"parent_id": "66eaf98e6592735b5a38129f", | ||
"child_count": 0 | ||
} | ||
Update Comment(update_comment) API | ||
================================== | ||
Updates the content of an existing comment. | ||
|
||
Response Example (Edit Content): | ||
-------------------------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66eaf98e6592735b5a38129f", | ||
"body": "<p>parent comment editing</p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": false, | ||
"anonymous_to_peers": false, | ||
"created_at": "2024-09-18T16:02:22Z", | ||
"updated_at": "2024-09-18T16:07:59Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 0, | ||
"up_count": 0, | ||
"down_count": 0, | ||
"point": 0 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [ | ||
{ | ||
"original_body": "<p>parent comment</p>", | ||
"reason_code": null, | ||
"editor_username": "faraz1", | ||
"created_at": "2024-09-18T16:07:59Z" | ||
} | ||
], | ||
"closed": false, | ||
"type": "comment", | ||
"endorsed": false, | ||
"depth": 0, | ||
"thread_id": "66df3056d77f29ace2ff201d", | ||
"parent_id": null, | ||
"child_count": 1, | ||
"endorsement": null | ||
} | ||
Response Example (Endorse Comment): | ||
----------------------------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66eaf98e6592735b5a38129f", | ||
"body": "<p>parent comment editing</p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": false, | ||
"anonymous_to_peers": false, | ||
"created_at": "2024-09-18T16:02:22Z", | ||
"updated_at": "2024-09-18T16:08:51Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 0, | ||
"up_count": 0, | ||
"down_count": 0, | ||
"point": 0 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [ | ||
{ | ||
"original_body": "<p>parent comment</p>", | ||
"reason_code": null, | ||
"editor_username": "faraz1", | ||
"created_at": "2024-09-18T16:07:59Z" | ||
} | ||
], | ||
"closed": false, | ||
"type": "comment", | ||
"endorsed": true, | ||
"depth": 0, | ||
"thread_id": "66df3056d77f29ace2ff201d", | ||
"parent_id": null, | ||
"child_count": 1, | ||
"endorsement": { | ||
"user_id": "8", | ||
"time": "2024-09-18T16:08:51Z" | ||
} | ||
} | ||
Get Commentables Stats(get_commentables_stats) API | ||
================================================== | ||
Returns the statistics for the commentable objects in a course. | ||
|
||
Response Example: | ||
----------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"course": { | ||
"discussion": 1, | ||
"question": 1 | ||
} | ||
} | ||
Get Parent Comment(get_parent_comment) API | ||
========================================== | ||
Retrieves a parent comment in the course discussion. | ||
|
||
Response Example (Endorsed): | ||
---------------------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66eaf98e6592735b5a38129f", | ||
"body": "<p>parent comment editing</p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": false, | ||
"anonymous_to_peers": false, | ||
"created_at": "2024-09-18T16:02:22Z", | ||
"updated_at": "2024-09-18T16:08:51Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 0, | ||
"up_count": 0, | ||
"down_count": 0, | ||
"point": 0 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [ | ||
{ | ||
"original_body": "<p>parent comment</p>", | ||
"reason_code": null, | ||
"editor_username": "faraz1", | ||
"created_at": "2024-09-18T16:07:59Z" | ||
} | ||
], | ||
"closed": false, | ||
"type": "comment", | ||
"endorsed": true, | ||
"depth": 0, | ||
"thread_id": "66df3056d77f29ace2ff201d", | ||
"parent_id": null, | ||
"child_count": 1, | ||
"endorsement": { | ||
"user_id": "8", | ||
"time": "2024-09-18T16:08:51Z" | ||
} | ||
} | ||
Response Example (Not Endorsed): | ||
-------------------------------- | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66eaf98e6592735b5a38129f", | ||
"body": "<p>parent comment editing</p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": false, | ||
"anonymous_to_peers": false, | ||
"created_at": "2024-09-18T16:02:22Z", | ||
"updated_at": "2024-09-18T16:21:00Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 0, | ||
"up_count": 0, | ||
"down_count": 0, | ||
"point": 0 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [ | ||
{ | ||
"original_body": "<p>parent comment</p>", | ||
"reason_code": null, | ||
"editor_username": "faraz1", | ||
"created_at": "2024-09-18T16:07:59Z" | ||
} | ||
], | ||
"closed": false, | ||
"type": "comment", | ||
"endorsed": false, | ||
"depth": 0, | ||
"thread_id": "66df3056d77f29ace2ff201d", | ||
"parent_id": null, | ||
"child_count": 1 | ||
} | ||
Get User(get_user) API | ||
====================== | ||
|
||
The `get_user` API retrieves user-specific data such as their username, followed threads, and upvoted content. | ||
|
||
**Response Example:** | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "8", | ||
"username": "faraz1", | ||
"external_id": "8", | ||
"subscribed_thread_ids": ["66df3056d77f29ace2ff201d", "66df1595a3a68c001d742c05"], | ||
"subscribed_commentable_ids": [], | ||
"subscribed_user_ids": [], | ||
"follower_ids": [], | ||
"upvoted_ids": ["66df1595a3a68c001d742c05", "66df3056d77f29ace2ff201d"], | ||
"downvoted_ids": [], | ||
"default_sort_key": "date" | ||
} | ||
Pin Thread(pin_thread) API | ||
========================== | ||
|
||
The `pin_thread` API pins a discussion thread at the top for users to easily access. | ||
|
||
**Response Example:** | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66df1595a3a68c001d742c05", | ||
"body": "<p>test question </p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": False, | ||
"anonymous_to_peers": False, | ||
"created_at": "2024-09-09T15:34:45Z", | ||
"updated_at": "2024-09-18T16:27:05Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 1, | ||
"up_count": 1, | ||
"down_count": 0, | ||
"point": 1 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [], | ||
"closed": False, | ||
"type": "thread", | ||
"thread_type": "question", | ||
"title": "test question", | ||
"context": "course", | ||
"last_activity_at": "2024-09-18T09:19:38Z", | ||
"closed_by": None, | ||
"tags": [], | ||
"group_id": None, | ||
"pinned": True | ||
} | ||
Unpin Thread(unpin_thread) API | ||
============================== | ||
|
||
The `unpin_thread` API unpins a previously pinned thread, removing its elevated visibility. | ||
|
||
**Response Example:** | ||
|
||
.. code-block:: json | ||
{ | ||
"id": "66df1595a3a68c001d742c05", | ||
"body": "<p>test question </p>", | ||
"course_id": "course-v1:Arbisoft+SE002+2024_S2", | ||
"anonymous": False, | ||
"anonymous_to_peers": False, | ||
"created_at": "2024-09-09T15:34:45Z", | ||
"updated_at": "2024-09-18T16:27:49Z", | ||
"at_position_list": [], | ||
"user_id": "8", | ||
"username": "faraz1", | ||
"commentable_id": "course", | ||
"votes": { | ||
"count": 1, | ||
"up_count": 1, | ||
"down_count": 0, | ||
"point": 1 | ||
}, | ||
"abuse_flaggers": [], | ||
"edit_history": [], | ||
"closed": False, | ||
"type": "thread", | ||
"thread_type": "question", | ||
"title": "test question", | ||
"context": "course", | ||
"last_activity_at": "2024-09-18T09:19:38Z", | ||
"closed_by": None, | ||
"tags": [], | ||
"group_id": None, | ||
"pinned": False | ||
} |
Oops, something went wrong.