feat: Add a new user API for discussions (#29287)

Adds a new user API for discussion that returns the discussion stats across the course.
This commit is contained in:
Kshitij Sobti
2022-02-01 12:51:01 +00:00
committed by GitHub
parent 429cee1fb2
commit 23be63309b
8 changed files with 349 additions and 19 deletions

View File

@@ -2,8 +2,9 @@
"""Provides base Commentable model class"""
from __future__ import annotations
from typing import Dict
from typing import Dict, Optional
from edx_django_utils.monitoring import function_trace
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.django_comment_common.comment_client import settings
@@ -39,3 +40,50 @@ def get_course_commentable_counts(course_key: CourseKey) -> Dict[str, Dict[str,
metric_action='commentable_stats.retrieve',
)
return response
@function_trace("get_course_user_stats")
def get_course_user_stats(course_key: CourseKey, params: Optional[Dict] = None) -> Dict[str, Dict[str, int]]:
"""
Get stats about a user's participation in a course.
Args:
course_key (str|CourseKey): course key for which stats are needed.
params (Optional[Dict]): pagination and sorting query parameters.
Returns:
A mapping of user ids to stats about the user.
e.g.
{
"user_stats" [
{
"active_flags": 2,
"inactive_flags": 0,
"replies": 3,
"responses": 2,
"threads": 7,
"username": "edx"
},
...
],
"num_pages": 12,
"page": 3,
"count": 124
...
}
"""
if params is None:
params = {}
url = f"{settings.PREFIX}/users/{course_key}/stats"
return perform_request(
'get',
url,
params,
metric_action='user.course_stats',
metric_tags=[
f"course_key:{course_key}",
"function:get_course_user_stats",
],
)