diff --git a/app.py b/app.py index 11e2013..7c1fb63 100644 --- a/app.py +++ b/app.py @@ -29,7 +29,9 @@ def add_animal() -> tuple[Response, int]: new_animal = Animal( animal_type=data.animal_type, name=data.name, - birth_date=data.birth_date + birth_date=data.birth_date, + breed=data.breed, + image_url=data.image_url ) db.session.add(new_animal) db.session.commit() @@ -51,6 +53,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.breed = data.breed + animal.image_url = data.image_url + db.session.commit() return jsonify( { diff --git a/migrations/versions/c77d65e56e96_add_image_column_to_animal_table.py b/migrations/versions/c77d65e56e96_add_image_column_to_animal_table.py new file mode 100644 index 0000000..a22acef --- /dev/null +++ b/migrations/versions/c77d65e56e96_add_image_column_to_animal_table.py @@ -0,0 +1,32 @@ +"""Add image column to animal table + +Revision ID: c77d65e56e96 +Revises: ed59229175d1 +Create Date: 2025-06-03 22:50:20.353785 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'c77d65e56e96' +down_revision = 'ed59229175d1' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('animal', schema=None) as batch_op: + batch_op.add_column(sa.Column('image_url', sa.String(), nullable=False)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('animal', schema=None) as batch_op: + batch_op.drop_column('image_url') + + # ### end Alembic commands ### diff --git a/migrations/versions/ed59229175d1_add_breed_column_to_animal_table.py b/migrations/versions/ed59229175d1_add_breed_column_to_animal_table.py new file mode 100644 index 0000000..7c5b4ec --- /dev/null +++ b/migrations/versions/ed59229175d1_add_breed_column_to_animal_table.py @@ -0,0 +1,32 @@ +"""Add breed column to animal table + +Revision ID: ed59229175d1 +Revises: e08fc0218f8b +Create Date: 2025-06-03 18:45:44.575523 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'ed59229175d1' +down_revision = 'e08fc0218f8b' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('animal', schema=None) as batch_op: + batch_op.add_column(sa.Column('breed', sa.String(), nullable=False)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('animal', schema=None) as batch_op: + batch_op.drop_column('breed') + + # ### end Alembic commands ### diff --git a/models/pydantic/models.py b/models/pydantic/models.py index 91e66db..4c1eb7e 100644 --- a/models/pydantic/models.py +++ b/models/pydantic/models.py @@ -1,11 +1,13 @@ -from datetime import date -from pydantic import BaseModel, ConfigDict +from datetime import date, timedelta +from pydantic import BaseModel, ConfigDict, computed_field class AnimalCreate(BaseModel): animal_type: str name: str birth_date: date + breed: str + image_url: str class AnimalResponse(BaseModel): @@ -15,3 +17,10 @@ class AnimalResponse(BaseModel): animal_type: str name: str birth_date: date + breed: str + image_url: str + + @computed_field + def age(self) -> int: + today = date.today() + return today.year - self.birth_date.year - ((today.month, today.day) < (self.birth_date.month, self.birth_date.day)) \ No newline at end of file diff --git a/models/sqlalchemy/models.py b/models/sqlalchemy/models.py index dc6e14a..8577b33 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=False) + image_url = db.Column(db.String, nullable=False) diff --git a/templates/home.html b/templates/home.html index 80b942e..d144a1a 100644 --- a/templates/home.html +++ b/templates/home.html @@ -33,6 +33,17 @@

Animals in the Shelter

+
+ + +
+
+ + +
@@ -44,8 +55,11 @@

List of animals:

Animal Type + Breed Name Birth Date + Age + Image Actions @@ -80,6 +94,17 @@ +
+ + +
+
+ + +