-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 302d36a
Showing
58 changed files
with
2,799 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#Virtual env | ||
env/ | ||
uploader/__pycache__/ | ||
|
||
#Database | ||
db.sqlite3 | ||
|
||
#Migrations | ||
uploader/migrations/ | ||
|
||
#Credentials | ||
.env | ||
|
||
#Static files | ||
media/ |
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,17 @@ | ||
FROM python:3.10.4 | ||
LABEL MAINTAINER="Amir Keyhani | https://amir.key_" | ||
|
||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN mkdir /imageuploader | ||
WORKDIR /imageuploader | ||
COPY . /imageuploader | ||
|
||
ADD requirements.txt /imageuploader | ||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements.txt | ||
|
||
RUN python manage.py collectstatic --no-input | ||
|
||
CMD ["gunicorn", "--chdir", "imageuploader", "--bind", ":8000", "imageuploader.wsgi:application"] |
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 @@ | ||
web: waitress-serve --port=$PORT imageuploader.wsgi:application |
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ApiConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'api' |
Empty file.
Binary file not shown.
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,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
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,20 @@ | ||
from rest_framework import serializers | ||
from uploader.models import Uploader, Comment, Profile | ||
|
||
|
||
class UploaderSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Uploader | ||
fields = '__all__' | ||
|
||
|
||
class CommentSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Comment | ||
fields = '__all__' | ||
|
||
|
||
class ProfileSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Profile | ||
fields = '__all__' |
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,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
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,25 @@ | ||
from django.urls import path | ||
from .views import * | ||
|
||
urlpatterns = [ | ||
path('uploader-list/', UploaderList.as_view(), name="uploader-list"), | ||
path('uploader-detail/<int:pk>/', UploaderDetail.as_view(), name="uploader-detail"), | ||
path('uploader-create/', UploaderCreate.as_view(), name="uploader-create"), | ||
path('uploader-update/<int:pk>/', UploaderUpdate.as_view(), name="uploader-update"), | ||
path('uploader-patch/<int:pk>/', UploaderUpdate.as_view(), name="uploader-patch"), | ||
path('uploader-delete/<int:pk>/', UploaderDelete.as_view(), name="uploader-delete"), | ||
|
||
path('comment-list/', CommentList.as_view(), name="comment-list"), | ||
path('comment-detail/<int:pk>/', CommentDetail.as_view(), name="comment-detail"), | ||
path('comment-create/', CommentCreate.as_view(), name="comment-create"), | ||
path('comment-update/<int:pk>/', CommentUpdate.as_view(), name="comment-update"), | ||
path('comment-patch/<int:pk>/', CommentUpdate.as_view(), name="comment-patch"), | ||
path('comment-delete/<int:pk>/', CommentDelete.as_view(), name="comment-delete"), | ||
|
||
path('profile-list/', ProfileList.as_view(), name="profile-list"), | ||
path('profile-detail/<int:pk>/', ProfileDetail.as_view(), name="profile-detail"), | ||
path('profile-create/', ProfileCreate.as_view(), name="profile-create"), | ||
path('profile-update/<int:pk>/', ProfileUpdate.as_view(), name="profile-update"), | ||
path('profile-patch/<int:pk>/', ProfileUpdate.as_view(), name="profile-patch"), | ||
path('profile-delete/<int:pk>/', ProfileDelete.as_view(), name="profile-delete"), | ||
] |
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,242 @@ | ||
from django.shortcuts import render | ||
from rest_framework.views import APIView | ||
from rest_framework.decorators import api_view | ||
from uploader.models import Uploader, Comment, Profile | ||
from .serializers import UploaderSerializer, CommentSerializer, ProfileSerializer | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly | ||
from rest_framework.authentication import TokenAuthentication | ||
|
||
# Create your views here. | ||
|
||
class UploaderList(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
|
||
def get(self, request, format=None): | ||
uploaders = Uploader.objects.all() | ||
serializer = UploaderSerializer(uploaders, many=True) | ||
return Response(serializer.data) | ||
|
||
class UploaderCreate(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def post(self, request, format=None): | ||
serializer = UploaderSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class UploaderDetail(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Uploader.objects.get(pk=pk) | ||
except Uploader.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def get(self, request, pk, format=None): | ||
uploader = self.get_object(pk) | ||
serializer = UploaderSerializer(uploader) | ||
return Response(serializer.data) | ||
|
||
class UploaderUpdate(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Uploader.objects.get(pk=pk) | ||
except Uploader.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def put(self, request, pk, format=None): | ||
uploader = self.get_object(pk) | ||
serializer = UploaderSerializer(uploader, data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
def patch(self, request, pk, format=None): | ||
uploader = self.get_object(pk) | ||
serializer = UploaderSerializer( | ||
uploader, data=request.data, partial=True) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class UploaderDelete(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Uploader.objects.get(pk=pk) | ||
except Uploader.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def delete(self, request, pk, format=None): | ||
uploader = self.get_object(pk) | ||
uploader.delete() | ||
return Response('Uploader deleted', status=status.HTTP_204_NO_CONTENT) | ||
|
||
class CommentList(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
|
||
def get(self, request, format=None): | ||
comments = Comment.objects.all() | ||
serializer = CommentSerializer(comments, many=True) | ||
return Response(serializer.data) | ||
|
||
class CommentCreate(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def post(self, request, format=None): | ||
serializer = CommentSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class CommentDetail(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Comment.objects.get(pk=pk) | ||
except Comment.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def get(self, request, pk, format=None): | ||
comment = self.get_object(pk) | ||
serializer = CommentSerializer(comment) | ||
return Response(serializer.data) | ||
|
||
class CommentUpdate(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Comment.objects.get(pk=pk) | ||
except Comment.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def put(self, request, pk, format=None): | ||
comment = self.get_object(pk) | ||
serializer = CommentSerializer(comment, data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
def patch(self, request, pk, format=None): | ||
comment = self.get_object(pk) | ||
serializer = CommentSerializer( | ||
comment, data=request.data, partial=True) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class CommentDelete(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Comment.objects.get(pk=pk) | ||
except Comment.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def delete(self, request, pk, format=None): | ||
comment = self.get_object(pk) | ||
comment.delete() | ||
return Response('Comment deleted', status=status.HTTP_204_NO_CONTENT) | ||
|
||
class ProfileList(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
|
||
def get(self, request, format=None): | ||
profiles = Profile.objects.all() | ||
serializer = ProfileSerializer(profiles, many=True) | ||
return Response(serializer.data) | ||
|
||
class ProfileCreate(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def post(self, request, format=None): | ||
serializer = ProfileSerializer(data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class ProfileDetail(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticatedOrReadOnly] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Profile.objects.get(pk=pk) | ||
except Profile.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def get(self, request, pk, format=None): | ||
profile = self.get_object(pk) | ||
serializer = ProfileSerializer(profile) | ||
return Response(serializer.data) | ||
|
||
class ProfileUpdate(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Profile.objects.get(pk=pk) | ||
except Profile.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def put(self, request, pk, format=None): | ||
profile = self.get_object(pk) | ||
serializer = ProfileSerializer(profile, data=request.data) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
def patch(self, request, pk, format=None): | ||
profile = self.get_object(pk) | ||
serializer = ProfileSerializer( | ||
profile, data=request.data, partial=True) | ||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
class ProfileDelete(APIView): | ||
authentication_classes = [TokenAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_object(self, pk): | ||
try: | ||
return Profile.objects.get(pk=pk) | ||
except Profile.DoesNotExist: | ||
raise Response(status=status.HTTP_404_NOT_FOUND) | ||
|
||
def delete(self, request, pk, format=None): | ||
profile = self.get_object(pk) | ||
profile.delete() | ||
return Response('profile deleted', status=status.HTTP_204_NO_CONTENT) |
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,7 @@ | ||
FROM nginx:1.21.6 | ||
LABEL MAINTAINER="Amir Keyhani | https://amir.key_" | ||
|
||
COPY nginx.conf /etc/nginx/conf.d/default.conf | ||
EXPOSE 80 | ||
|
||
CMD ["nginx", "-g", "daemon off;"] |
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,25 @@ | ||
version: "3.9" | ||
|
||
services: | ||
nginx: | ||
container_name: nginx | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "80:80" | ||
volumes: | ||
- imageuploader_static_volume:/imageuploader/static | ||
- imageuploader_media_volume:/imageuploader/media | ||
networks: | ||
- nginx_network | ||
|
||
|
||
volumes: | ||
imageuploader_static_volume: | ||
external: true | ||
imageuploader_media_volume: | ||
external: true | ||
networks: | ||
nginx_network: | ||
external: true |
Oops, something went wrong.