From 95d114c478828ee79e2e12b81c887a6aea450c74 Mon Sep 17 00:00:00 2001 From: insssomniac Date: Sun, 8 Jun 2025 14:53:37 +0000 Subject: [PATCH 1/5] hw_3-1 --- app.py | 13 +++-- models/pydantic/models.py | 5 ++ models/sqlalchemy/models.py | 2 + pyproject.toml | 2 +- templates/home.html | 109 ++++++++++++++++++++++++++++-------- 5 files changed, 101 insertions(+), 30 deletions(-) diff --git a/app.py b/app.py index 11e2013..d71138c 100644 --- a/app.py +++ b/app.py @@ -5,11 +5,13 @@ from settings import settings from database import init_db from models.sqlalchemy.models import Animal +from flask_migrate import Migrate app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = settings.sqlalchemy_database_uri db = init_db(app) +migrate = Migrate(app, db) @app.route('/') @@ -17,6 +19,11 @@ def home() -> str: return render_template('home.html') +@app.route('/health') +def health() -> tuple[Response, int]: + return jsonify({"status": "ok"}), 200 + + @app.route('/animals', methods=['GET']) def index() -> Response: animals = Animal.query.all() @@ -84,11 +91,5 @@ def delete_animal(pk: int) -> Union[Response, tuple[Response, int]]: return jsonify({"message": "Animal deleted successfully!"}) -def initialize_app(): - with app.app_context(): - db.create_all() - - if __name__ == '__main__': - initialize_app() app.run(debug=True) diff --git a/models/pydantic/models.py b/models/pydantic/models.py index 91e66db..21c193a 100644 --- a/models/pydantic/models.py +++ b/models/pydantic/models.py @@ -1,4 +1,5 @@ from datetime import date +from typing import Optional from pydantic import BaseModel, ConfigDict @@ -6,6 +7,8 @@ class AnimalCreate(BaseModel): animal_type: str name: str birth_date: date + breed: Optional[str] = None + photo_url: Optional[str] = None class AnimalResponse(BaseModel): @@ -15,3 +18,5 @@ class AnimalResponse(BaseModel): animal_type: str name: str birth_date: date + breed: Optional[str] = None + photo_url: Optional[str] = None diff --git a/models/sqlalchemy/models.py b/models/sqlalchemy/models.py index dc6e14a..fb2d503 100644 --- a/models/sqlalchemy/models.py +++ b/models/sqlalchemy/models.py @@ -9,3 +9,5 @@ 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=True) + photo_url = db.Column(db.String, nullable=True) diff --git a/pyproject.toml b/pyproject.toml index 156df2c..83caf77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ version = "0.1.0" description = "" authors = ["marcustas "] readme = "README.md" +package-mode = false [tool.poetry.dependencies] python = "^3.11" @@ -13,7 +14,6 @@ flask-sqlalchemy = "^3.1.1" flask-migrate = "^4.0.5" pydantic-settings = "^2.0.3" - [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" diff --git a/templates/home.html b/templates/home.html index 80b942e..da927aa 100644 --- a/templates/home.html +++ b/templates/home.html @@ -33,6 +33,14 @@

Animals in the Shelter

+
+ + +
+
+ + +
@@ -46,6 +54,8 @@

List of animals:

Animal Type Name Birth Date + Breed + Photo Actions @@ -80,6 +90,15 @@ +
+ + +
+
+ + +
+