Skip to content

Commit

Permalink
Added OpenAPI specification. Created template files and methods to co…
Browse files Browse the repository at this point in the history
…mplete routes and database functions. Added views to urls.py. Added requirements.txt.
  • Loading branch information
xxmistacruzxx committed Feb 8, 2024
1 parent cde12d6 commit 37b589a
Show file tree
Hide file tree
Showing 25 changed files with 562 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/books
/covers
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Gets a list of books from database
```
[
{
uuid: string,
title: string,
description: string,
cover: string,
Expand All @@ -46,6 +47,7 @@ Adds a book to the database and starts initial processing

```
{
uuid: string,
title: string,
description: string,
cover: string,
Expand All @@ -60,6 +62,14 @@ Adds a book to the database and starts initial processing

#### DELETE

### /books/:bookid/export

#### GET

### /books/:bookid/analyze

#### GET

### /books/:bookid/images

#### GET
Expand Down
Binary file modified alttextbackend/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified alttextbackend/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified alttextbackend/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified alttextbackend/__pycache__/views.cpython-311.pyc
Binary file not shown.
Binary file modified alttextbackend/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
Empty file added alttextbackend/data/books.py
Empty file.
Empty file added alttextbackend/data/images.py
Empty file.
14 changes: 12 additions & 2 deletions alttextbackend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@

from django.contrib import admin
from django.urls import path, include
from .views import BooksView # , ImagesView
from .views.books import BooksView
from .views.books_bookid import BooksBookidView
from .views.books_bookid_export import BooksBookidExportView
from .views.books_bookid_images import BooksBookidImagesView
from .views.books_bookid_src import BooksBookidSrcView
from .views.images_hash import ImagesHashView

urlpatterns = [
# path("admin/", admin.site.urls),
# path("api-auth/", include("rest_framework.urls")),
path("api/books", BooksView.as_view()),
path("books", BooksView.as_view()),
path("books/<str:bookId>", BooksBookidView.as_view()),
path("books/<str:bookId>/export", BooksBookidExportView.as_view()),
path("books/<str:bookId>/images", BooksBookidImagesView.as_view()),
path("books/<str:bookId>/<str:src>", BooksBookidSrcView.as_view()),
path("images/<str:hash>", ImagesHashView.as_view()),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
35 changes: 5 additions & 30 deletions alttextbackend/views.py → alttextbackend/views/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class BooksView(APIView):
serializer_class = BookSerializer

def get(self, request, *args, **kwargs):
# TODO: get's list of books given limits
data = {"books": []}
return Response(data, status=status.HTTP_200_OK)
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)

def post(self, request, *args, **kwargs):
# validate request data
Expand All @@ -41,6 +39,10 @@ def post(self, request, *args, **kwargs):
books_path = "./books/"
default_storage.save(f"{books_path}{str(id)}.zip", ContentFile(file.read()))

# TODO: ensure book has valid root html file

# TODO: start analyzing book

# save cover image
covers_path = "./covers/"
default_storage.save(
Expand All @@ -55,30 +57,3 @@ def post(self, request, *args, **kwargs):
},
status=status.HTTP_201_CREATED,
)


# class ImageSerializer(serializers.Serializer):
# imagedata = serializers.CharField()
# beforeContext = serializers.CharField(required=False)
# afterContext = serializers.CharField(required=False)

# class ImagesView(APIView):
# def get(self, request, *args, **kwargs):
# data = {"images": "this is an image"}
# return Response(data, status=status.HTTP_200_OK)

# def post(self, request, *args, **kwargs):
# serializer = ImageSerializer(data=request.data)
# if serializer.is_valid():
# validated_data = serializer.validated_data
# res = {"book": validated_data.get("imagedata")}
# if validated_data.get("beforeContext"):
# res["beforeContext"] = validated_data.get("beforeContext")
# if validated_data.get("afterContext"):
# res["afterContext"] = validated_data.get("afterContext")
# return Response(
# res,
# status=status.HTTP_201_CREATED,
# )
# else:
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
23 changes: 23 additions & 0 deletions alttextbackend/views/books_bookid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions, serializers
from rest_framework.exceptions import ValidationError
from rest_framework.parsers import FormParser, MultiPartParser
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from uuid import uuid4

class BooksBookidView(APIView):
parser_classes = (FormParser, MultiPartParser)

def get(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)

def post(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)

def put(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)

def delete(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)
14 changes: 14 additions & 0 deletions alttextbackend/views/books_bookid_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions, serializers
from rest_framework.exceptions import ValidationError
from rest_framework.parsers import FormParser, MultiPartParser
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from uuid import uuid4

class BooksBookidExportView(APIView):
parser_classes = (FormParser, MultiPartParser)

def get(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)
14 changes: 14 additions & 0 deletions alttextbackend/views/books_bookid_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions, serializers
from rest_framework.exceptions import ValidationError
from rest_framework.parsers import FormParser, MultiPartParser
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from uuid import uuid4

class BooksBookidImagesView(APIView):
parser_classes = (FormParser, MultiPartParser)

def get(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)
20 changes: 20 additions & 0 deletions alttextbackend/views/books_bookid_src.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions, serializers
from rest_framework.exceptions import ValidationError
from rest_framework.parsers import FormParser, MultiPartParser
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from uuid import uuid4

class BooksBookidSrcView(APIView):
parser_classes = (FormParser, MultiPartParser)

def get(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)

def patch(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)

def put(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)
14 changes: 14 additions & 0 deletions alttextbackend/views/images_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status, permissions, serializers
from rest_framework.exceptions import ValidationError
from rest_framework.parsers import FormParser, MultiPartParser
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
from uuid import uuid4

class ImagesHashView(APIView):
parser_classes = (FormParser, MultiPartParser)

def get(self, request, *args, **kwargs):
return Response({"TODO": "TODO"}, status=status.HTTP_200_OK)
2 changes: 0 additions & 2 deletions installdependencies.sh

This file was deleted.

Loading

0 comments on commit 37b589a

Please sign in to comment.