-
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.
Update folder structure and add dockerfile
- Loading branch information
Showing
18 changed files
with
327 additions
and
181 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
#TEMP disabled - because it doesn't work well. | ||
|
||
#FROM ubuntu:latest | ||
#LABEL authors="idanlevian" | ||
# | ||
#RUN apt-get update && apt-get install -y \ | ||
# python3-pip \ | ||
# python3-dev \ | ||
# build-essential \ | ||
# libpq-dev \ | ||
# python3-venv \ | ||
# curl \ | ||
# && apt-get clean | ||
# | ||
#WORKDIR /code | ||
# | ||
#RUN python3 -m venv /code/venv | ||
#ENV PATH="/code/venv/bin:$PATH" | ||
# | ||
#RUN pip install pipenv | ||
# | ||
#COPY Pipfile Pipfile.lock /code/ | ||
#RUN pipenv install --system --deploy | ||
# | ||
#COPY . /code/ | ||
# | ||
#EXPOSE 8000 | ||
# | ||
#ENV PYTHONDONTWRITEBYTECODE=1 | ||
#ENV PYTHONUNBUFFERED=1 | ||
# | ||
#COPY /.env /code/.env | ||
# | ||
#SHELL ["/bin/bash", "-c"] | ||
#RUN if [ -f /code/.env ]; then \ | ||
# set -a && . /code/.env && set +a; \ | ||
# fi | ||
# | ||
#CMD ["pipenv", "run", "gunicorn", "--bind", "0.0.0.0:8000", "pokedexServer.wsgi:application"] | ||
##CMD ["pipenv", "run", "gunicorn", "pokedexServer.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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
10 changes: 10 additions & 0 deletions
10
server/pokedexServer/serializers/pokemon_detail_serializers.py
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,10 @@ | ||
from rest_framework import serializers | ||
|
||
class PokemonDetailSerializer(serializers.Serializer): | ||
id = serializers.IntegerField() | ||
name = serializers.CharField(max_length=100) | ||
padded_id = serializers.CharField(max_length=10) | ||
types = serializers.ListField(child=serializers.CharField(max_length=50)) | ||
color = serializers.CharField(max_length=50) | ||
sprite_url = serializers.URLField() | ||
|
22 changes: 0 additions & 22 deletions
22
server/pokedexServer/serializers.py → ...r/serializers/pokemon_info_serializers.py
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
11 changes: 11 additions & 0 deletions
11
server/pokedexServer/serializers/pokemon_list_serializers.py
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,11 @@ | ||
from rest_framework import serializers | ||
|
||
class PokemonListSerializer(serializers.Serializer): | ||
id = serializers.IntegerField() | ||
name = serializers.CharField(max_length=100) | ||
number = serializers.CharField(max_length=50) | ||
types = serializers.ListField(child=serializers.CharField(max_length=50)) | ||
boxBg = serializers.CharField(max_length=100) | ||
svg = serializers.URLField() | ||
error = serializers.CharField(max_length=200, required=False) | ||
|
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
Empty file.
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,48 @@ | ||
import pokebase as pb | ||
|
||
from drf_spectacular.utils import extend_schema | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from rest_framework.views import APIView | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
from pokedexServer.models.pokemon.Colors import Colors | ||
from pokedexServer.models.pokemon.PokemonModel import PokemonModel | ||
from pokedexServer.models.pokemon.PokemonTypeModel import PokemonTypeModel | ||
from pokedexServer.serializers.pokemon_detail_serializers import PokemonDetailSerializer | ||
from pokedexServer.utils import pad | ||
|
||
|
||
class PokemonDetailView(APIView): | ||
serializer_class = PokemonDetailSerializer | ||
|
||
@extend_schema(operation_id="pokemon_detail", summary="Retrieve a Pokémon by ID") | ||
def get(self, request, id): | ||
pokemonModel = self.fetchAndMapPokemon(id) | ||
if pokemonModel.error: # Now correctly checking for an error | ||
return Response({"error": pokemonModel.error}, status=status.HTTP_404_NOT_FOUND) | ||
serializer = self.serializer_class(pokemonModel) | ||
return Response(serializer.data, status=status.HTTP_200_OK) | ||
|
||
def fetchAndMapPokemon(self, id): | ||
try: | ||
pokeAPIPokemon = pb.pokemon(id) | ||
if not pokeAPIPokemon: | ||
return PokemonModel(error="Pokemon not found") | ||
return PokemonModel( | ||
id=pokeAPIPokemon.id, | ||
name=pokeAPIPokemon.name, | ||
number=pad(pokeAPIPokemon.id), | ||
types=[type.type.name for type in pokeAPIPokemon.types], | ||
boxBg=Colors[PokemonTypeModel(pokeAPIPokemon.types[0].type.name).value].value[0], | ||
gif=f'https://github.com/eidan66/pokemon-api-sprites/blob/master/sprites/pokemon/other/showdown/{pokeAPIPokemon.id}.gif?raw=true' | ||
) | ||
except Exception as e: | ||
logger.error(f"Error fetching Pokemon: {e}") | ||
return PokemonModel(error="Error fetching Pokemon") | ||
|
||
def mapToPokemonTypeModel(self, pokeAPIPokemonType): | ||
return PokemonTypeModel(pokeAPIPokemonType.type.name) |
Oops, something went wrong.