Skip to content

Commit

Permalink
Remove items management (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
StreetLamb authored May 3, 2024
1 parent 1e4bb8b commit de8fee4
Show file tree
Hide file tree
Showing 26 changed files with 14 additions and 990 deletions.
3 changes: 1 addition & 2 deletions backend/app/api/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from fastapi import APIRouter

from app.api.routes import items, login, members, skills, teams, users, utils
from app.api.routes import login, members, skills, teams, users, utils

api_router = APIRouter()
api_router.include_router(login.router, tags=["login"])
api_router.include_router(users.router, prefix="/users", tags=["users"])
api_router.include_router(utils.router, prefix="/utils", tags=["utils"])
api_router.include_router(items.router, prefix="/items", tags=["items"])
api_router.include_router(teams.router, prefix="/teams", tags=["teams"])
api_router.include_router(
members.router, prefix="/teams/{team_id}/members", tags=["members"]
Expand Down
102 changes: 0 additions & 102 deletions backend/app/api/routes/items.py

This file was deleted.

8 changes: 4 additions & 4 deletions backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from fastapi import APIRouter, Depends, HTTPException
from sqlmodel import col, delete, func, select
from sqlmodel import func, select

from app import crud
from app.api.deps import (
Expand All @@ -12,7 +12,6 @@
from app.core.config import settings
from app.core.security import get_password_hash, verify_password
from app.models import (
Item,
Message,
UpdatePassword,
User,
Expand Down Expand Up @@ -212,8 +211,9 @@ def delete_user(
status_code=403, detail="Super users are not allowed to delete themselves"
)

statement = delete(Item).where(col(Item.owner_id) == user_id)
session.exec(statement) # type: ignore
# TODO: Handle deletion of user's resources
# statement = delete(Item).where(col(Item.owner_id) == user_id)
# session.exec(statement) # type: ignore
session.delete(user)
session.commit()
return Message(message="User deleted successfully")
10 changes: 1 addition & 9 deletions backend/app/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from sqlmodel import Session, select

from app.core.security import get_password_hash, verify_password
from app.models import Item, ItemCreate, User, UserCreate, UserUpdate
from app.models import User, UserCreate, UserUpdate


def create_user(*, session: Session, user_create: UserCreate) -> User:
Expand Down Expand Up @@ -43,11 +43,3 @@ def authenticate(*, session: Session, email: str, password: str) -> User | None:
if not verify_password(password, db_user.hashed_password):
return None
return db_user


def create_item(*, session: Session, item_in: ItemCreate, owner_id: int) -> Item:
db_item = Item.model_validate(item_in, update={"owner_id": owner_id})
session.add(db_item)
session.commit()
session.refresh(db_item)
return db_item
38 changes: 0 additions & 38 deletions backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class UpdatePassword(SQLModel):
class User(UserBase, table=True):
id: int | None = Field(default=None, primary_key=True)
hashed_password: str
items: list["Item"] = Relationship(back_populates="owner")
teams: list["Team"] = Relationship(back_populates="owner")


Expand All @@ -84,43 +83,6 @@ class UsersOut(SQLModel):
count: int


# ==============ITEM=========================


# Shared properties
class ItemBase(SQLModel):
title: str
description: str | None = None


class ItemCreate(ItemBase):
title: str


# Properties to receive on item update
class ItemUpdate(ItemBase):
title: str | None = None # type: ignore


# Database model, database table inferred from class name
class Item(ItemBase, table=True):
id: int | None = Field(default=None, primary_key=True)
title: str
owner_id: int | None = Field(default=None, foreign_key="user.id", nullable=False)
owner: User | None = Relationship(back_populates="items")


# Properties to return via API, id is always required
class ItemOut(ItemBase):
id: int
owner_id: int


class ItemsOut(SQLModel):
data: list[ItemOut]
count: int


# ==============TEAM=========================


Expand Down
162 changes: 0 additions & 162 deletions backend/app/tests/api/routes/test_items.py

This file was deleted.

4 changes: 1 addition & 3 deletions backend/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from app.core.config import settings
from app.core.db import engine, init_db
from app.main import app
from app.models import Item, User
from app.models import User
from app.tests.utils.user import authentication_token_from_email
from app.tests.utils.utils import get_superuser_token_headers

Expand All @@ -17,8 +17,6 @@ def db() -> Generator[Session, None, None]:
with Session(engine) as session:
init_db(session)
yield session
statement = delete(Item)
session.execute(statement)
statement = delete(User)
session.execute(statement)
session.commit()
Expand Down
Loading

0 comments on commit de8fee4

Please sign in to comment.