events: fix Schema for query params for top_per_user
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
56260cd23f
commit
c70f6e3122
|
@ -29,6 +29,18 @@ class EventSerializer(ModelSerializer):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class EventTopPerUserParams(Serializer):
|
||||||
|
"""Query params for top_per_user"""
|
||||||
|
|
||||||
|
top_n = IntegerField(default=15)
|
||||||
|
|
||||||
|
def create(self, request: Request) -> Response:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def update(self, request: Request) -> Response:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
class EventTopPerUserSerializer(Serializer):
|
class EventTopPerUserSerializer(Serializer):
|
||||||
"""Response object of Event's top_per_user"""
|
"""Response object of Event's top_per_user"""
|
||||||
|
|
||||||
|
@ -60,12 +72,14 @@ class EventViewSet(ReadOnlyModelViewSet):
|
||||||
filterset_fields = ["action"]
|
filterset_fields = ["action"]
|
||||||
|
|
||||||
@swagger_auto_schema(
|
@swagger_auto_schema(
|
||||||
method="GET", responses={200: EventTopPerUserSerializer(many=True)}
|
method="GET",
|
||||||
|
responses={200: EventTopPerUserSerializer(many=True)},
|
||||||
|
query_serializer=EventTopPerUserParams,
|
||||||
)
|
)
|
||||||
@action(detail=False, methods=["GET"])
|
@action(detail=False, methods=["GET"])
|
||||||
def top_per_user(self, request: Request):
|
def top_per_user(self, request: Request):
|
||||||
"""Get the top_n events grouped by user count"""
|
"""Get the top_n events grouped by user count"""
|
||||||
filtered_action = request.query_params.get("filter_action", EventAction.LOGIN)
|
filtered_action = request.query_params.get("action", EventAction.LOGIN)
|
||||||
top_n = request.query_params.get("top_n", 15)
|
top_n = request.query_params.get("top_n", 15)
|
||||||
return Response(
|
return Response(
|
||||||
Event.objects.filter(action=filtered_action)
|
Event.objects.filter(action=filtered_action)
|
||||||
|
|
|
@ -1854,6 +1854,11 @@ paths:
|
||||||
description: Page Size
|
description: Page Size
|
||||||
required: false
|
required: false
|
||||||
type: integer
|
type: integer
|
||||||
|
- name: top_n
|
||||||
|
in: query
|
||||||
|
required: false
|
||||||
|
type: integer
|
||||||
|
default: 15
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: Response object of Event's top_per_user
|
description: Response object of Event's top_per_user
|
||||||
|
|
Reference in New Issue