-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(growth): prompts activities endpoint #28008
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
Conversation
| conditions = condition if conditions is None else (conditions | condition) | ||
| if conditions is None: | ||
| return Response({"detail": "No feature specified"}, status=400) | ||
| result = PromptsActivity.objects.filter(conditions, user=request.user).all() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neo-Zhixing Nit: I don't think you need .all() here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, just need tests
EDIT: added an additional comment
| class PromptsActivitiesEndpoint(Endpoint): | ||
| permission_classes = (IsAuthenticated,) | ||
|
|
||
| def post(self, request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neo-Zhixing just noticed this is a post request. Would be nice if we could do this as get request. Could this endpoint take a list of features and list of fields so we could handle this in a get? I don't think we need to map feature too field (we just pass all the fields we need for all the features feature and pick the ones we need based on required_fields)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like if this is what we're going to do, we could totally reuse and modify the old end point so that it accepts multiple features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neo-Zhixing The problem with that approach is that we'll have two different return types. I'm ok with it but make sure you update the PromptResponse type to reflect that it could be an array in your PR.
| data = None if result is None else result.data | ||
| return Response({"data": data, "features": featuredata}) | ||
| else: | ||
| return Response({"features": featuredata}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to maintain backward compatibility with a bunch of tests that mocks the endpoint with {data: xxx}.
Long term we might want to update this so that we can support both promptsCheck and batchedPromptsCheck with a uniform behavior, regardless of the number of features requested.
| return Response({}) | ||
|
|
||
| return Response({"data": result.data}) | ||
| features = request.GET.getlist("feature") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neo-Zhixing Nicely done using getlist here :)
| if len(features) == 1: | ||
| result = result.first() | ||
| data = None if result is None else result.data | ||
| return Response({"data": data, "features": featuredata}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Neo-Zhixing excellent idea also setting features even though we aren't using it, it will make future changes much easier
scefali
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Added endpoint to query multiple PromptActivity features at once.