Skip to content

Commit

Permalink
Merge pull request #21 from Skaylan/carlos-feat
Browse files Browse the repository at this point in the history
Criação da rota get_movie e atualização do schema
  • Loading branch information
Skaylan committed Jan 29, 2024
2 parents 0a969a7 + 0bc876b commit 40debc4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
26 changes: 26 additions & 0 deletions app/controllers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from app.config.app_config import *
from app.models.tables.user import User
from app.models.tables.category import Category
from app.models.tables.movie import Movie
from app.models.schemas.user_schema import UserSchema
from app.models.schemas.category_schema import CategorySchema
from app.models.schemas.movie_schema import MovieSchema
from werkzeug.security import generate_password_hash, check_password_hash
import jwt

Expand Down Expand Up @@ -371,4 +373,28 @@ def get_one_category():
'error_cause': str(error.__cause__)
}), 500


@app.route('/api/v1/get_movies')
def get_movies():
try:
movies = Movie.query.all()
movies_schema = MovieSchema(many=True)
payload = movies_schema.dump(movies)

return jsonify({
'movies': payload
}),200

except Exception as error:
print(f'error class: {error.__class__} | error cause: {error.__cause__}')
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno)
return jsonify({
'status': 'error',
'message': 'An error has occurred!',
'error_class': str(error.__class__),
'error_cause': str(error.__cause__)
}), 500


2 changes: 1 addition & 1 deletion app/models/schemas/category_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
class CategorySchema(ma.SQLAlchemyAutoSchema):
class Meta:
model = Category
load_intance = True
load_instance = True
12 changes: 12 additions & 0 deletions app/models/schemas/movie_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from app.config.app_config import *
from app.config.db_config import *
from app.models.tables.movie import Movie
from app.models.schemas.category_schema import CategorySchema


class MovieSchema(ma.SQLAlchemyAutoSchema):
category = ma.Nested(CategorySchema, many=True)

class Meta:
model = Movie
load_instance = True

0 comments on commit 40debc4

Please sign in to comment.