-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/user skills #499
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
base: dev
Are you sure you want to change the base?
Feature/user skills #499
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,31 @@ class UserList(ListCreateAPIView): | |
| filter_backends = (filters.DjangoFilterBackend,) | ||
| filterset_class = UserFilter | ||
|
|
||
| def list(self, request, *args, **kwargs): | ||
| max_skills = request.query_params.get("max_skills", None) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. давай тут вместо None какой-нибудь разумный дефолт бахнем? сейчас фронт все равно не передает этот квери параметр и после мержа этого ПРа он продолжит забирать кучу лишних данных, а с дефолтом мы этот размер ограничим |
||
| if max_skills is not None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. валидацию квери параметров может сделать через сериалайзер? то, что вьюшка занимается валидацией квери параметров мне кажется не ок |
||
| try: | ||
| max_skills = int(max_skills) | ||
| if max_skills < 0: | ||
| return Response( | ||
| {"error": "max_skills must be a positive integer"}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. да зачем тут ошибку отдавать, давай просто считать что max_skills = 0 и не будем вообще эти скиллы получать из бд |
||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
| except ValueError: | ||
| return Response( | ||
| {"error": "max_skills must be an integer"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
|
|
||
| response = super().list(request, *args, **kwargs) | ||
|
|
||
| if max_skills is not None: | ||
| for user_data in response.data.get("results", []): | ||
| if "skills" in user_data: | ||
| user_data["skills"] = user_data["skills"][:max_skills] | ||
|
|
||
|
Comment on lines
+116
to
+119
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. это должно быть учтено при походе в БД, точно не стоит обрезать кусок ответа во вьюшке) |
||
| return response | ||
|
|
||
| def post(self, request, *args, **kwargs): | ||
| serializer = self.get_serializer(data=request.data) | ||
| serializer.is_valid(raise_exception=True) | ||
|
|
@@ -259,8 +284,27 @@ class CurrentUser(GenericAPIView): | |
|
|
||
| def get(self, request): | ||
| user = request.user | ||
|
|
||
| max_skills = request.query_params.get("max_skills", None) | ||
| if max_skills is not None: | ||
| try: | ||
| max_skills = int(max_skills) | ||
| if max_skills < 0: | ||
| return Response( | ||
| {"error": "max_skills must be a positive integer"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
| except ValueError: | ||
| return Response( | ||
| {"error": "max_skills must be an integer"}, | ||
| status=status.HTTP_400_BAD_REQUEST, | ||
| ) | ||
|
|
||
|
Comment on lines
+288
to
+302
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лютая копипаста, точно нужно убрать это отсюда |
||
| serializer = self.get_serializer(user) | ||
|
|
||
| if max_skills is not None and "skills" in serializer.data: | ||
| serializer.data["skills"] = serializer.data["skills"][:max_skills] | ||
|
|
||
| if settings.DEBUG: | ||
| skills_url_name = ( | ||
| "https://skills.dev.procollab.ru/progress/subscription-data/" | ||
|
|
||
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.
это нужно прокинуть в контекст сериалайзера, чтобы мы из БД тянули скиллы с лимитом, а не вытаскивали ВСЕ и потом обрезали вывод