Skip to content

Commit

Permalink
Rename models to schemas, dm_models to models to reflect latest fastA…
Browse files Browse the repository at this point in the history
  • Loading branch information
paul121 committed Feb 13, 2020
1 parent 5e1bb9d commit a0e760d
Show file tree
Hide file tree
Showing 41 changed files with 217 additions and 217 deletions.
2 changes: 1 addition & 1 deletion backend/app/app/api/api_v1/endpoints/farms/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from app.api.utils.db import get_db
from app.api.utils.farms import get_active_farms_url_or_list, get_farm_client, ClientError
from app.models.farm import Farm
from app.schemas.farm import Farm

router = APIRouter()

Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/api/api_v1/endpoints/farms/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from app.api.utils.db import get_db
from app.api.utils.farms import get_active_farms_url_or_list, get_farm_client, ClientError
from app.models.farm import Farm
from app.schemas.farm import Farm

router = APIRouter()

Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/api/api_v1/endpoints/farms/farms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from app.api.utils.db import get_db
from app.api.utils.farms import get_farm_client, ClientError, get_farms_url_or_list, get_farm_by_id
from app.api.utils.security import get_farm_access
from app.models.farm import Farm, FarmCreate, FarmUpdate
from app.schemas.farm import Farm, FarmCreate, FarmUpdate
from app.core.celery_app import celery_app

router = APIRouter()
Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/api/api_v1/endpoints/farms/farms_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from app import crud
from app.api.utils.db import get_db
from app.api.utils.farms import get_oauth_token
from app.models.farm import Farm, FarmCreate
from app.models.farm_token import FarmAuthorizationParams
from app.schemas.farm import Farm, FarmCreate
from app.schemas.farm_token import FarmAuthorizationParams

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/api/api_v1/endpoints/farms/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from app.api.utils.db import get_db
from app.api.utils.farms import get_farm_client, ClientError, get_farms_url_or_list
from app.api.utils.security import get_farm_access
from app.models.farm import Farm
from app.models.farm_info import FarmInfo
from app.schemas.farm import Farm
from app.schemas.farm_info import FarmInfo

router = APIRouter()

Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/api/api_v1/endpoints/farms/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from app.api.utils.db import get_db
from app.api.utils.farms import get_active_farms_url_or_list, get_farm_client, ClientError
from app.models.farm import Farm
from app.schemas.farm import Farm

router = APIRouter()

Expand Down
2 changes: 1 addition & 1 deletion backend/app/app/api/api_v1/endpoints/farms/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from app.api.utils.db import get_db
from app.api.utils.farms import get_active_farms_url_or_list, get_farm_client, ClientError
from app.models.farm import Farm
from app.schemas.farm import Farm

router = APIRouter()

Expand Down
8 changes: 4 additions & 4 deletions backend/app/app/api/api_v1/endpoints/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from app.core import config
from app.core.jwt import create_access_token
from app.core.security import get_password_hash
from app.db_models.user import User as DBUser
from app.models.msg import Msg
from app.models.token import Token
from app.models.user import User
from app.models.user import User as DBUser
from app.schemas.msg import Msg
from app.schemas.token import Token
from app.schemas.user import User
from app.utils import (
generate_password_reset_token,
send_reset_password_email,
Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/api/api_v1/endpoints/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from app.api.utils.db import get_db
from app.api.utils.security import get_current_active_superuser, get_current_active_user
from app.core import config
from app.db_models.user import User as DBUser
from app.models.user import User, UserCreate, UserInDB, UserUpdate
from app.models.user import User as DBUser
from app.schemas.user import User, UserCreate, UserInDB, UserUpdate
from app.utils import send_new_account_email

router = APIRouter()
Expand Down
8 changes: 4 additions & 4 deletions backend/app/app/api/api_v1/endpoints/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from app.api.utils.db import get_db
from app.api.utils.security import get_current_active_superuser
from app.core.celery_app import celery_app
from app.models.msg import Msg
from app.models.user import UserInDB
from app.models.farm import Farm
from app.models.farm_token import FarmTokenCreate, FarmAuthorizationParams
from app.schemas.msg import Msg
from app.schemas.user import UserInDB
from app.schemas.farm import Farm
from app.schemas.farm_token import FarmTokenCreate, FarmAuthorizationParams
from app.api.utils.farms import get_farm_by_id, get_oauth_token
from app.api.utils.security import get_farm_access
from app.utils import send_test_email, generate_farm_authorization_link, generate_farm_registration_link
Expand Down
6 changes: 3 additions & 3 deletions backend/app/app/api/utils/farms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

from app import crud
from app.api.utils.db import get_db
from app.models.farm_token import FarmTokenBase, FarmTokenCreate
from app.schemas.farm_token import FarmTokenBase, FarmTokenCreate
from app.crud.farm_token import create_farm_token, update_farm_token
from app.models.farm import Farm, FarmUpdate
from app.models.token import FarmAccess
from app.schemas.farm import Farm, FarmUpdate
from app.schemas.token import FarmAccess
from app.api.utils.security import get_farm_access


Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/api/utils/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from app.api.utils.db import get_db
from app.core import config
from app.core.jwt import ALGORITHM
from app.db_models.user import User
from app.models.token import TokenData, FarmAccess
from app.models.user import User
from app.schemas.token import TokenData, FarmAccess


logger = logging.getLogger(__name__)
Expand Down
8 changes: 4 additions & 4 deletions backend/app/app/crud/farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from sqlalchemy.orm import Session

from app.core import config
from app.db_models.farm import Farm
from app.models.farm import FarmCreate, FarmUpdate
from app.db_models.farm_token import FarmToken
from app.models.farm_info import FarmInfo
from app.models.farm import Farm
from app.schemas.farm import FarmCreate, FarmUpdate
from app.models.farm_token import FarmToken
from app.schemas.farm_info import FarmInfo


logger = logging.getLogger(__name__)
Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/crud/farm_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from fastapi.encoders import jsonable_encoder
from sqlalchemy.orm import Session

from app.db_models.farm_token import FarmToken
from app.models.farm_token import FarmTokenCreate, FarmTokenUpdate
from app.models.farm_token import FarmToken
from app.schemas.farm_token import FarmTokenCreate, FarmTokenUpdate

def get_farm_token(db: Session, farm_id: int):
return db.query(FarmToken).filter(FarmToken.farm_id == farm_id).first()
Expand Down
4 changes: 2 additions & 2 deletions backend/app/app/crud/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from sqlalchemy.orm import Session

from app.core.security import get_password_hash, verify_password
from app.db_models.user import User
from app.models.user import UserCreate, UserUpdate
from app.models.user import User
from app.schemas.user import UserCreate, UserUpdate


def get(db_session: Session, *, user_id: int) -> Optional[User]:
Expand Down
8 changes: 4 additions & 4 deletions backend/app/app/db/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Import all the models, so that Base has them before being
# Import all the schemas, so that Base has them before being
# imported by Alembic
from app.db.base_class import Base # noqa
from app.db_models.user import User # noqa
from app.db_models.farm import Farm
from app.db_models.farm_token import FarmToken
from app.models.user import User # noqa
from app.models.farm import Farm
from app.models.farm_token import FarmToken
4 changes: 2 additions & 2 deletions backend/app/app/db/init_db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from app import crud
from app.core import config
from app.models.user import UserCreate
from app.schemas.user import UserCreate

# make sure all SQL Alchemy models are imported before initializing DB
# make sure all SQL Alchemy schemas are imported before initializing DB
# otherwise, SQL Alchemy might fail to initialize properly relationships
# for more details: https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/28
from app.db import base
Expand Down
33 changes: 0 additions & 33 deletions backend/app/app/db_models/farm.py

This file was deleted.

17 changes: 0 additions & 17 deletions backend/app/app/db_models/farm_token.py

This file was deleted.

13 changes: 0 additions & 13 deletions backend/app/app/db_models/user.py

This file was deleted.

Empty file modified backend/app/app/models/__init__.py
100644 → 100755
Empty file.
77 changes: 33 additions & 44 deletions backend/app/app/models/farm.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
from typing import Optional
from datetime import datetime

from app.models.api_model import APIModel
from app.models.farm_token import FarmTokenBase, FarmToken
from app.models.farm_info import FarmInfo

# Shared properties
class FarmBase(APIModel):
farm_name: Optional[str] = None
url: Optional[str] = None
username: Optional[str] = None
notes: Optional[str] = None
tags: Optional[str] = None
info: Optional[FarmInfo] = None
active: Optional[bool] = None

class FarmBaseInDB(FarmBase):
id: int = None

# Properties to receive via API on creation
class FarmCreate(FarmBase):
farm_name: str
url: str
username: Optional[str]
password: Optional[str]
token: Optional[FarmTokenBase]

# Properties to receive via API on update
class FarmUpdate(FarmBase):
password: Optional[str] = None

# Additional properties to return via API
class Farm(FarmBaseInDB):
time_created: Optional[datetime] = None
time_updated: Optional[datetime] = None
last_accessed: Optional[datetime] = None
token: Optional[FarmToken] = None
is_authorized: Optional[bool] = None
auth_error: Optional[str] = None

# Additional properites stored in DB
class FarmInDB(FarmBaseInDB):
pass
from sqlalchemy import Boolean, Column, Integer, String, DateTime
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.postgresql import JSONB

from app.db.base_class import Base
from app.models.farm_token import FarmToken


class Farm(Base):
__tablename__ = 'farm'

id = Column(Integer, primary_key=True, index=True)
time_created = Column(DateTime(timezone=True), server_default=func.now())
time_updated = Column(DateTime(timezone=True), onupdate=func.now())
last_accessed = Column(DateTime(timezone=True))
farm_name = Column(String, index=True)
url = Column(String, index=True, unique=True)
username = Column(String, index=True)
password = Column(String, index=True)
notes = Column(String, nullable=True)
tags = Column(String, nullable=True)

# active attribute allows admins to disable farmOS profiles
active = Column(Boolean, default=False)

# Store farm info in a JSONB column
info = Column(JSONB, nullable=True)

is_authorized = Column(Boolean, default=False)
token = relationship("FarmToken", uselist=False, back_populates="farm")
auth_error = Column(String, nullable=True)

38 changes: 12 additions & 26 deletions backend/app/app/models/farm_token.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,17 @@
from typing import Optional
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship

from app.models.api_model import APIModel
from app.db.base_class import Base

# Farm Token Models
class FarmTokenBase(APIModel):
access_token: Optional[str] = None
expires_in: Optional[str] = None
refresh_token: Optional[str] = None
expires_at: Optional[str] = None

class FarmToken(Base):
__tablename__ = 'farmtoken'

class FarmTokenCreate(FarmTokenBase):
farm_id: int
pass
id = Column(Integer, primary_key=True)
access_token = Column(String)
expires_in = Column(String)
refresh_token = Column(String)
expires_at = Column(String)


class FarmToken(FarmTokenBase):
id: int


class FarmTokenUpdate(FarmToken):
pass

class FarmAuthorizationParams(APIModel):
grant_type: str
code: str
state: str
client_id: str
client_secret: Optional[str]
redirect_uri: Optional[str]
farm_id = Column(Integer, ForeignKey("farm.id"), unique=True)
farm = relationship("Farm", uselist=False, back_populates="token")
5 changes: 0 additions & 5 deletions backend/app/app/models/msg.py

This file was deleted.

Loading

0 comments on commit a0e760d

Please sign in to comment.