-
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.
Merge pull request #240 from ZUS666/develop
a
- Loading branch information
Showing
32 changed files
with
907 additions
and
241 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
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
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
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,6 @@ | ||
def subscribe_service(self, error, bool): | ||
user = self.request.user | ||
if user.is_subscribed is bool: | ||
raise error | ||
user.is_subscribed = bool | ||
user.save(update_fields=['is_subscribed']) |
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
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
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
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,30 @@ | ||
from drf_spectacular.utils import extend_schema | ||
from rest_framework import status | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from api.exceptions import NotSubscribedUserError, SubscribedUserError | ||
from api.services.subscribe import subscribe_service | ||
|
||
|
||
@extend_schema( | ||
tags=('subscribe',) | ||
) | ||
class SubscireAPIView(APIView): | ||
""" | ||
Представление подписки и отписки на новостную рассылку. | ||
""" | ||
permission_classes = (IsAuthenticated,) | ||
|
||
def post(self, request): | ||
subscribe_service(self, SubscribedUserError, True) | ||
return Response( | ||
{'message': 'Вы успешно подписались'}, status=status.HTTP_200_OK | ||
) | ||
|
||
def delete(self, request): | ||
subscribe_service(self, NotSubscribedUserError, False) | ||
return Response( | ||
{'message': 'Вы успешно отписались'}, status=status.HTTP_200_OK | ||
) |
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
Oops, something went wrong.