diff --git a/api_v1/README.md b/api_v1/README.md deleted file mode 100644 index c5b68ca..0000000 --- a/api_v1/README.md +++ /dev/null @@ -1,138 +0,0 @@ - -# ZED API - -This is a reference to ZED API v1 - - - - - -## User - -### User authentication - -```http - POST /api/v1/token -``` -Pass parameters as `JSON` in body -| Parameter | Type | Description | -| :-------- | :------- | :------------------------- | -| `username` | `string` | **Required**. Username | -| `password` | `string` | **Required**. Password | - -#### Response - -| Parameter | Type | Description | -| :-------- | :------- | :------------------------- | -| `access` | `string` | access token to authenticate user | -| `refresh` | `string` | refresh token to refresh access token | - -```http - POST /api/v1/refresh -``` -| Parameter | Type | Description | -| :-------- | :------- | :------------------------- | -| `refresh` | `string` | **Required**. refresh token to get new access token | - - -#### Response - -| Parameter | Type | Description | -| :-------- | :------- | :------------------------- | -| `access` | `string` | access token to authenticate user | - -### User Profile - -#### Retrieve User Profile -- **URL:** `/api/v1/user/profile` -- **Method:** `GET` -- **Description:** Retrieves authenticated user profile -- **Authentication:** Required -- **Response:** - Returns user profile. - - -Example using curl: -```bash -curl -X GET \ - -H "Authorization: Bearer " \ - http://example.com/api/v1/user/profile -``` - -### User Posts - -#### Retrieve User Posts -- **URL:** `/api/v1/user/posts` -- **Method:** `GET` -- **Description:** Retrieves authenticated user posts -- **Authentication:** Required -- **Response:** - Returns user posts in pagination. - - -Example using curl: -```bash -curl -X GET \ - -H "Authorization: Bearer " \ - http://example.com/api/v1/user/posts -``` - - ### User Follower list - -#### Retrieve User follower list -- **URL:** `/api/v1/user/followerlist` -- **Method:** `GET` -- **Description:** Retrieves authenticated user follower list -- **Authentication:** Required -- **Response:** - Returns user follower list. - - -Example using curl: -```bash -curl -X GET \ - -H "Authorization: Bearer " \ - http://example.com/api/v1/user/followerlist -``` - - ### User Following list - -#### Retrieve User following list -- **URL:** `/api/v1/user/followinglist` -- **Method:** `GET` -- **Description:** Retrieves authenticated user following list -- **Authentication:** Required -- **Response:** - Returns user following list - - -Example using curl: -```bash -curl -X GET \ - -H "Authorization: Bearer " \ - http://example.com/api/v1/user/followinglist -``` - ### User suggestions - -#### Retrieve User Topic and who to follow data -- **URL:** `/api/v1/user/suggestions` -- **Method:** `GET` -- **Description:** Retrieves authenticated user suggestions -- **Authentication:** Required -- **Response:** - Returns user suggestions - -| Parameter | Type | Description | -| :-------- | :------- | :------------------------- | -| `follow_suggests` | `array of user` | List of users suggested to follow | -| `topics_suggest` | `array of topics` | List of topics suggested | - - - - -Example using curl: -```bash -curl -X GET \ - -H "Authorization: Bearer " \ - http://example.com/api/v1/user/suggestions -``` \ No newline at end of file diff --git a/api_v1/__init__.py b/api_v1/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/api_v1/admin.py b/api_v1/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/api_v1/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/api_v1/apps.py b/api_v1/apps.py deleted file mode 100644 index 25d545a..0000000 --- a/api_v1/apps.py +++ /dev/null @@ -1,6 +0,0 @@ -from django.apps import AppConfig - - -class ApiV1Config(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'api_v1' diff --git a/api_v1/migrations/__init__.py b/api_v1/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/api_v1/models.py b/api_v1/models.py deleted file mode 100644 index 71a8362..0000000 --- a/api_v1/models.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.db import models - -# Create your models here. diff --git a/api_v1/serializers.py b/api_v1/serializers.py deleted file mode 100644 index 1e000ea..0000000 --- a/api_v1/serializers.py +++ /dev/null @@ -1,69 +0,0 @@ -from rest_framework import serializers - -from user.models import User -from content.models import Post, Topic -from relation.models import Relation - - -# serialize user model to just return the fields we want -class UserSerialized(serializers.ModelSerializer): - - follower_count = serializers.SerializerMethodField() - following_count = serializers.SerializerMethodField() - - class Meta: - model = User - fields = ('username', 'email', 'first_name', 'last_name','profile_photo','banner_photo','bio','follower_count','following_count') - - def get_follower_count(self, obj): - return Relation.objects.filter(following=obj).count() - - def get_following_count(self, obj): - return Relation.objects.filter(follower=obj).count() - -# serialize posts model to just return the fields we want -class PostSerialized(serializers.ModelSerializer): - class Meta: - model = Post - exclude = ('author','topic') - -class FollowerListSerialized(serializers.ModelSerializer): - - follower__full_name = serializers.SerializerMethodField() - follower__username = serializers.CharField(source='follower.username') - follower__profile_photo = serializers.CharField(source='follower.profile_photo') - - class Meta: - model = Relation - fields = ('follower__full_name', 'follower__username','follower__profile_photo') - - def get_follower__full_name(self, obj): - if (obj.follower.first_name and obj.follower.last_name): - full_name = "%s %s" % (obj.follower.first_name, obj.follower.last_name) - return full_name.strip() - else: - username = "%s" % (obj.follower.username, ) - return username.strip() - -class FollowingListSerialized(serializers.ModelSerializer): - - following__full_name = serializers.SerializerMethodField() - following__username = serializers.CharField(source='following.username') - following__profile_photo = serializers.CharField(source='following.profile_photo') - - class Meta: - model = Relation - fields = ('following__full_name', 'following__username','following__profile_photo') - - def get_following__full_name(self, obj): - if (obj.following.first_name and obj.following.last_name): - full_name = "%s %s" % (obj.following.first_name, obj.following.last_name) - return full_name.strip() - else: - username = "%s" % (obj.following.username, ) - return username.strip() - -class TopicSerialized(serializers.ModelSerializer): - class Meta: - model = Topic - fields = ('id', 'name') \ No newline at end of file diff --git a/api_v1/tests.py b/api_v1/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/api_v1/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/api_v1/urls.py b/api_v1/urls.py deleted file mode 100644 index 9b1a867..0000000 --- a/api_v1/urls.py +++ /dev/null @@ -1,34 +0,0 @@ -from django.urls import path, include -from rest_framework_simplejwt.views import TokenObtainPairView, TokenRefreshView -from .views import index - -urlpatterns = [ - - # index - path('', index, name='index'), - - # Get Access Token and Refresh Token - path('token', TokenObtainPairView.as_view(), name='token_obtain_pair'), - path('token/refresh', TokenRefreshView.as_view(), name='token_refresh'), - - # user endpoints - path('user/', include('api_v1.urls_user')), - - # post endpoints - - # comment endpoints - - # like endpoints - - # follow endpoints - - # search endpoints - - # notification endpoints - - - - - - -] \ No newline at end of file diff --git a/api_v1/urls_user.py b/api_v1/urls_user.py deleted file mode 100644 index ea83134..0000000 --- a/api_v1/urls_user.py +++ /dev/null @@ -1,61 +0,0 @@ -from django.urls import path -from .views import user_profile, user_posts, user_followerlist, user_followinglist, user_suggestions - -urlpatterns = [ - # user enpoints - - # User profile - # - # POST /api/v1/user/profile - # - # headers: { - # Authorization Bearer - # } - # response: { - # "username": "zed", - # "email": "email", - # "first_name": "first_name", - # "last_name": "last_name", - # "profile_photo": "profile_photo", - # "banner_photo": "banner_photo", - # "bio": "bio", - # "follower_count": 0, - # "following_count": 0 - # } - path('profile',user_profile, name='user_profile'), - - # User posts - # - # POST /api/v1/user/posts - # - # headers: { - # Authorization Bearer - # } - # response: { - # count: 1, - # next: null, - # previous: null, - # results: [ - # { - # "id": 1, - # "content": "content", - # "image": "image", - # "created_at": "created_at", - # "updated_at": "updated_at", - # } - # ] - # } - path('posts',user_posts, name='user_posts'), - - # User followers list - path('followerlist',user_followerlist, name='user_followlist'), - - # User following list - path('followinglist',user_followinglist, name='user_followlist'), - - # User topic and follow suggestions - path('suggestions',user_suggestions, name='user_suggestions'), - - - -] \ No newline at end of file diff --git a/api_v1/views.py b/api_v1/views.py deleted file mode 100644 index 4962684..0000000 --- a/api_v1/views.py +++ /dev/null @@ -1,75 +0,0 @@ -from django.http import JsonResponse -from rest_framework.decorators import api_view, permission_classes -from rest_framework.pagination import PageNumberPagination -from rest_framework.permissions import IsAuthenticated - -from relation.models import Relation -from user.models import User -from utils.base_utils import get_random_topics -from .serializers import UserSerialized, PostSerialized, FollowerListSerialized, FollowingListSerialized, \ - TopicSerialized - - -def index(request): - return JsonResponse({'message': 'ZED API v1'}) - - -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -def user_profile(request): - user = request.user - user = UserSerialized(user) - return JsonResponse(user.data, safe=False) - - -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -def user_posts(request): - user = request.user - posts = user.posts.all().order_by('-created_time') - - paginator = PageNumberPagination() - paginator.page_size = 10 - paginated_posts = paginator.paginate_queryset(posts, request) - result = PostSerialized(paginated_posts, many=True) - return paginator.get_paginated_response(result.data) - - -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -def user_followerlist(request): - user = request.user - - followers = Relation.objects.filter(following=user) - - followers = FollowerListSerialized(followers, many=True) - - return JsonResponse(followers.data, safe=False) - - -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -def user_followinglist(request): - user = request.user - - following = Relation.objects.filter(follower=user) - - following = FollowingListSerialized(following, many=True) - - return JsonResponse(following.data, safe=False) - - -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -def user_suggestions(request): - current_user = request.user - - topics = get_random_topics() - - following_users = Relation.objects.filter(follower__id=current_user.id).values_list('following__id', flat=True) - random_suggestions = User.objects.exclude(id__in=following_users).exclude(id=current_user.id).order_by('?')[:5] - - serializedTopics = TopicSerialized(topics, many=True) - suggestions = UserSerialized(random_suggestions, many=True) - - return JsonResponse({'topics': serializedTopics.data, 'suggests': suggestions.data}, safe=False) diff --git a/config/settings.py b/config/settings.py index 0cd7561..dfb354f 100644 --- a/config/settings.py +++ b/config/settings.py @@ -36,8 +36,6 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', - 'rest_framework', - 'api_v1', *DJANGO_APPS, *THIRD_PARTY_PACKAGES, ] @@ -141,15 +139,3 @@ # Default primary key field type DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' - -REST_FRAMEWORK = { - 'DEFAULT_AUTHENTICATION_CLASSES': [ - 'rest_framework_simplejwt.authentication.JWTAuthentication', - 'rest_framework.authentication.SessionAuthentication', - ], -} - -SIMPLE_JWT = { - 'ACCESS_TOKEN_LIFETIME': timedelta(days=1), - 'REFRESH_TOKEN_LIFETIME': timedelta(days=30), -} diff --git a/config/urls.py b/config/urls.py index 9f497ee..f757989 100644 --- a/config/urls.py +++ b/config/urls.py @@ -9,7 +9,6 @@ path('', include('engagement.urls')), path('', include('relation.urls')), path('', include('user.urls')), - path('api/v1/', include('api_v1.urls')), path('__debug__/', include('debug_toolbar.urls')), ] diff --git a/requirements.txt b/requirements.txt index 059dbe6..16c7d91 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,11 +2,8 @@ asgiref==3.7.2 async-timeout==4.0.3 Django==5.0.3 django-debug-toolbar==4.3.0 -djangorestframework==3.15.1 -djangorestframework-simplejwt==5.3.1 pillow==10.2.0 psycopg2==2.9.9 -PyJWT==2.8.0 python-decouple==3.8 redis==5.0.3 sqlparse==0.4.4