diff --git a/app.py b/app.py index 11e2013..e3a56a4 100644 --- a/app.py +++ b/app.py @@ -1,10 +1,12 @@ -from flask import Flask, jsonify, request, Response, render_template +from flask import Flask, jsonify, request, Response, render_template, make_response from models.pydantic.models import AnimalCreate, AnimalResponse from typing import Union from settings import settings from database import init_db from models.sqlalchemy.models import Animal +from datetime import datetime + app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = settings.sqlalchemy_database_uri @@ -23,13 +25,27 @@ def index() -> Response: return jsonify({"animals": [AnimalResponse.model_validate(animal).model_dump(mode='json') for animal in animals]}) +@app.route('/health', methods=['GET']) +def get_health() -> Response: + response = make_response("Hi") + response.status_code = 200 + return response + + @app.route('/animal', methods=['POST']) def add_animal() -> tuple[Response, int]: data = AnimalCreate(**request.get_json()) + new_animal = Animal( animal_type=data.animal_type, name=data.name, - birth_date=data.birth_date + birth_date=data.birth_date, + breed=data.breed, + foto=data.foto, + age=data.age + + + ) db.session.add(new_animal) db.session.commit() @@ -51,6 +67,9 @@ def update_animal(pk: int) -> Union[Response, tuple[Response, int]]: animal.animal_type = data.animal_type animal.name = data.name animal.birth_date = data.birth_date + animal.foto = data.foto + animal.breed = data.breed + animal.age = data.age db.session.commit() return jsonify( { @@ -91,4 +110,4 @@ def initialize_app(): if __name__ == '__main__': initialize_app() - app.run(debug=True) + app.run(debug=True, port=8000) diff --git a/models/pydantic/models.py b/models/pydantic/models.py index 91e66db..4494d19 100644 --- a/models/pydantic/models.py +++ b/models/pydantic/models.py @@ -1,4 +1,4 @@ -from datetime import date +from datetime import date, datetime from pydantic import BaseModel, ConfigDict @@ -6,6 +6,9 @@ class AnimalCreate(BaseModel): animal_type: str name: str birth_date: date + breed: str + foto: str + age: int class AnimalResponse(BaseModel): @@ -15,3 +18,6 @@ class AnimalResponse(BaseModel): animal_type: str name: str birth_date: date + breed: str + foto: str + age: int diff --git a/models/sqlalchemy/__init__.py b/models/sqlalchemy/__init__.py index 4fee0e2..5be6b3b 100644 --- a/models/sqlalchemy/__init__.py +++ b/models/sqlalchemy/__init__.py @@ -6,3 +6,6 @@ class Animal(db.Model): animal_type = db.Column(db.String, nullable=False) name = db.Column(db.String, nullable=False) birth_date = db.Column(db.Date, nullable=False) + breed = db.Column(db.String, nullable=False) + foto = db.Column(db.String, nullable=False) + age = db.Column(db.Integer, nullable=False) diff --git a/models/sqlalchemy/models.py b/models/sqlalchemy/models.py index dc6e14a..5de3cd6 100644 --- a/models/sqlalchemy/models.py +++ b/models/sqlalchemy/models.py @@ -9,3 +9,7 @@ class Animal(db.Model): animal_type = db.Column(db.String, nullable=False) name = db.Column(db.String, nullable=False) birth_date = db.Column(db.Date, nullable=False) + breed = db.Column(db.String, nullable=False) + foto = db.Column(db.String, nullable=False) + age = db.Column(db.Integer, nullable=False) + diff --git a/templates/home.html b/templates/home.html index 80b942e..3f5df53 100644 --- a/templates/home.html +++ b/templates/home.html @@ -33,6 +33,13 @@

Animals in the Shelter

+
+ + +
+
+ +
@@ -46,6 +53,9 @@

List of animals:

Animal Type Name Birth Date + Age + Breed + Foto Actions @@ -80,6 +90,14 @@ +
+ + +
+
+ + +