-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from Andrenord282/main
feat: database migration,template displays cards from the database
- Loading branch information
Showing
13 changed files
with
118 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
.idea | ||
|
||
/animals_photo/ | ||
/node_modules/ | ||
/frontend/node_modules/ | ||
/frontend/testing/ | ||
/animal_photos/ |
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
46 changes: 46 additions & 0 deletions
46
backend/database/versions/3e3431180c42_add_additional_fields_to_models.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,46 @@ | ||
"""add additional fields to models | ||
Revision ID: 3e3431180c42 | ||
Revises: 619cced1d961 | ||
Create Date: 2024-03-15 22:33:02.438735 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '3e3431180c42' | ||
down_revision: Union[str, None] = '619cced1d961' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('animal', sa.Column('type', sa.String(), nullable=False)) | ||
op.add_column('animal', sa.Column('sex', sa.String(), nullable=False)) | ||
op.add_column('animal', sa.Column('age', sa.String(), nullable=False)) | ||
op.add_column('animal', sa.Column('size', sa.String(), nullable=False)) | ||
op.create_unique_constraint(op.f('uq__animal__id'), 'animal', ['id']) | ||
op.drop_index('ix__photo__animal_id', table_name='animal_photo') | ||
op.drop_index('ix__photo__id', table_name='animal_photo') | ||
op.create_index(op.f('ix__animal_photo__animal_id'), 'animal_photo', ['animal_id'], unique=False) | ||
op.create_index(op.f('ix__animal_photo__id'), 'animal_photo', ['id'], unique=True) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f('ix__animal_photo__id'), table_name='animal_photo') | ||
op.drop_index(op.f('ix__animal_photo__animal_id'), table_name='animal_photo') | ||
op.create_index('ix__photo__id', 'animal_photo', ['id'], unique=False) | ||
op.create_index('ix__photo__animal_id', 'animal_photo', ['animal_id'], unique=False) | ||
op.drop_constraint(op.f('uq__animal__id'), 'animal', type_='unique') | ||
op.drop_column('animal', 'size') | ||
op.drop_column('animal', 'age') | ||
op.drop_column('animal', 'sex') | ||
op.drop_column('animal', 'type') | ||
# ### end Alembic commands ### |
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
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
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
from fastapi.responses import HTMLResponse | ||
from backend.dao.animal_dao import AnimalDao | ||
from backend.models.animal import Animal | ||
from backend.services.base_template_service import BaseTemplateService | ||
from backend.schemas.animal_schemas import AnimalIndexSchema | ||
|
||
|
||
class AnimalTemplateService(BaseTemplateService): | ||
def __init__(self, request): | ||
super().__init__(request) | ||
def __init__(self, request, session): | ||
super().__init__(request, session) | ||
|
||
@staticmethod | ||
def _complete_template_path(template_name: str): | ||
return f"pages/index/{template_name}" | ||
|
||
def get_index_template(self) -> HTMLResponse: | ||
async def get_index_template(self) -> HTMLResponse: | ||
animals:list[Animal] = await AnimalDao(self.session).find_all() | ||
cards = [AnimalIndexSchema.from_orm(animal) for animal in animals] | ||
return self.templates.TemplateResponse( | ||
name=self._complete_template_path("index.html"), | ||
context={"request": self.request} | ||
context={"request": self.request, "cards": cards} | ||
) |
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from fastapi import Request | ||
from fastapi.templating import Jinja2Templates | ||
from sqlalchemy.ext.asyncio import AsyncSession as Session | ||
|
||
|
||
class BaseTemplateService: | ||
templates = Jinja2Templates(directory="./backend/templates") | ||
|
||
def __init__(self, request: Request): | ||
def __init__(self, request: Request, session: Session | None): | ||
self.request = request | ||
self.session = session |
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
93 changes: 1 addition & 92 deletions
93
backend/templates/pages/index/sections/animals_section.html
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
4 changes: 2 additions & 2 deletions
4
backend/templates/pages/index/sections/statistic_section.html
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