Skip to content

Commit

Permalink
Merge 3444351 into 0d62be2
Browse files Browse the repository at this point in the history
  • Loading branch information
engjames committed May 14, 2019
2 parents 0d62be2 + 3444351 commit 3be6043
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 2 deletions.
8 changes: 8 additions & 0 deletions authors/apps/articles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .permissions import IsOwnerOrReadOnly
from .pagination import ArticlePageNumberPagination
from .readtime_engine import ArticleTimeEngine
from drf_yasg.utils import swagger_auto_schema


class ListArticles(generics.ListAPIView):
Expand Down Expand Up @@ -249,6 +250,7 @@ def post(self, request, **kwargs):
class Reports(APIView):
"""POST articles/:id/report/ to report an article"""
permission_classes = (IsAuthenticated, )
serializer_class = ReportSerializer

def get_article_object(self, article_id):
""" Method to search for an article object by its id"""
Expand All @@ -264,6 +266,12 @@ def get_report_object(self, article_id, username):
except Report.DoesNotExist:
return None

@swagger_auto_schema(
operation_description="Report an article.",
operation_id="Report an article.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, **kwargs):
""" Method to post a report"""
article = self.get_article_object(kwargs['article_id'])
Expand Down
44 changes: 44 additions & 0 deletions authors/apps/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from drf_yasg.utils import swagger_auto_schema

import facebook
import twitter
Expand All @@ -36,6 +37,12 @@ class RegistrationAPIView(APIView):
renderer_classes = (UserJSONRenderer,)
serializer_class = RegistrationSerializer

@swagger_auto_schema(
operation_description="Regester a new User.",
operation_id="Sign up as a new user",
request_body=serializer_class,
responses={201: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request):
user = request.data.get('user', {})
# The create serializer, validate serializer, save serializer pattern
Expand Down Expand Up @@ -72,6 +79,12 @@ class LoginAPIView(APIView):
renderer_classes = (UserJSONRenderer,)
serializer_class = LoginSerializer

@swagger_auto_schema(
operation_description="Login a User.",
operation_id="Login a user",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request):
user = request.data.get('user', {})
# Notice here that we do not call `serializer.save()` like we did for
Expand Down Expand Up @@ -151,13 +164,20 @@ def get(self, request, uid):
"error": "Activation link is invalid.",
}, status=status.HTTP_400_BAD_REQUEST)


class PasswordReset(APIView):
# Allow any user (authenticated or not) to hit this endpoint.
permission_classes = (AllowAny,)
authentication_classes = ()
renderer_classes = (UserJSONRenderer,)
serializer_class = ResetPasswordTokenSerializer

@swagger_auto_schema(
operation_description="Reset password.",
operation_id="Resest password using your email address",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request):
# request to reset email

Expand Down Expand Up @@ -194,6 +214,12 @@ class PasswordResetToken(APIView):
authentication_classes = ()
serializer_class = ResetPasswordSerializer

@swagger_auto_schema(
operation_description="Password reset.",
operation_id="Password reset.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, token):
# reset password

Expand Down Expand Up @@ -235,6 +261,12 @@ class FacebookAuthenticationAPIView(APIView):
authentication_classes = ()
serializer_class = SocialAuthenticationSerializer

@swagger_auto_schema(
operation_description="Facebook social authentication.",
operation_id="facebook social authentication.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down Expand Up @@ -264,6 +296,12 @@ class GoogleAuthenticationAPIView(APIView):
authentication_classes = ()
serializer_class = SocialAuthenticationSerializer

@swagger_auto_schema(
operation_description="Google social authentication.",
operation_id="Google social authentication.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
Expand All @@ -290,6 +328,12 @@ class TwitterAuthenticationAPIView(APIView):
authentication_classes = ()
serializer_class = TwitterAuthenticationSerializer

@swagger_auto_schema(
operation_description="Twitter social authentication.",
operation_id="Twitter social authentication.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, **kwargs):
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down
7 changes: 7 additions & 0 deletions authors/apps/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .models import Comment, Likes
from .serializers import CommentSerializer, CommentEditHistorySerializer
from .utils import get_article, get_comment
from drf_yasg.utils import swagger_auto_schema


class ListCreateComment(APIView):
Expand All @@ -27,6 +28,12 @@ def get_article(self, article_id):
except Article.DoesNotExist:
raise NotFound({"error": "Article not found."})

@swagger_auto_schema(
operation_description="Add a comment to an article.",
operation_id="Add a comment to an article.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, **kwargs):
"""
This method adds a comment to a particular article.
Expand Down
7 changes: 7 additions & 0 deletions authors/apps/rate_article/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rest_framework.exceptions import NotFound
from authors.apps.articles.models import Article
from authors.apps.rate_article.models import Rate
from drf_yasg.utils import swagger_auto_schema


class CreateArticleRating(APIView):
Expand All @@ -24,6 +25,12 @@ def get_object(self, article_id):
except Article.DoesNotExist:
raise NotFound("article does not exists")

@swagger_auto_schema(
operation_description="Add ratings to an article.",
operation_id="Add ratings to an article.",
request_body=serializer_class,
responses={200: serializer_class(many=False), 400: "BAD REQUEST"},
)
def post(self, request, **kwargs):
""" create article rating"""
#gets article
Expand Down
13 changes: 12 additions & 1 deletion authors/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'rest_framework',
'django_filters',
'simple_history',
'drf_yasg',

'authors.apps.authentication',
'authors.apps.core',
Expand All @@ -55,7 +56,7 @@
'authors.apps.favorites',
'authors.apps.rate_article',
'authors.apps.article_tags',
'authors.apps.bookmarks'
'authors.apps.bookmarks',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -128,6 +129,16 @@
},
]

SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'api_key': {
'type': 'apiKey',
'in': 'header',
'name': 'Authorization'
}
},
}

# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

Expand Down
22 changes: 21 additions & 1 deletion authors/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
"""
from django.urls import include, path
from django.contrib import admin
from drf_yasg import openapi
from drf_yasg.views import get_schema_view
from rest_framework import permissions

schema_view = get_schema_view(
openapi.Info(
title="Author's Haven For Team Invictus",
default_version='v1',
description="Author's Haven is a community of like minded authors to \
foster inspiration and innovation by leveraging the modern web",
license=openapi.License(name="Andela License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
authentication_classes=(),
)


urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -25,5 +42,8 @@
path('api/articles/', include('authors.apps.favorites.urls')),
path('api/', include('authors.apps.rate_article.urls')),
path('api/', include('authors.apps.article_tags.urls')),
path('api/', include('authors.apps.bookmarks.urls'))
path('api/', include('authors.apps.bookmarks.urls')),
path('docs/', schema_view.with_ui('swagger', cache_timeout=0),
name='schema-swagger-ui'),
path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ autopep8==1.4.4
cachetools==3.1.0
certifi==2019.3.9
chardet==3.0.4
coreapi==2.3.3
coreschema==0.0.4
coverage==4.5.3
coveralls==1.7.0
defusedxml==0.6.0
Expand All @@ -15,6 +17,7 @@ django-filter==2.1.0
django-simple-history==2.7.2
djangorestframework==3.9.2
docopt==0.6.2
drf-yasg==1.15.0
entrypoints==0.3
extras==1.0.0
facebook-sdk==3.1.0
Expand All @@ -25,7 +28,11 @@ future==0.17.1
google-auth==1.6.3
gunicorn==19.9.0
idna==2.8
inflection==0.3.1
itypes==1.1.0
Jinja2==2.10.1
linecache2==1.0.0
MarkupSafe==1.1.1
mccabe==0.6.1
more-itertools==7.0.0
oauthlib==3.0.1
Expand All @@ -50,11 +57,13 @@ pytz==2019.1
requests==2.21.0
requests-oauthlib==1.2.0
rsa==4.0
ruamel.yaml==0.15.94
six==1.12.0
social-auth-core==3.1.0
sqlparse==0.3.0
testtools==2.3.0
traceback2==1.4.0
unittest2==1.1.0
uritemplate==3.0.0
urllib3==1.24.2
whitenoise==4.1.2

0 comments on commit 3be6043

Please sign in to comment.