-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
246 additions
and
26 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
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,12 @@ | ||
from sqlalchemy.orm import sessionmaker, Session | ||
from app.models import Base | ||
|
||
# Create a SessionLocal class | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=Base.metadata.bind) | ||
|
||
def get_db() -> Session: | ||
db = SessionLocal() | ||
try: | ||
yield db | ||
finally: | ||
db.close() |
40 changes: 40 additions & 0 deletions
40
backend/app/migrations/versions/59bb2488a76b_insert_roles.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,40 @@ | ||
"""insert roles | ||
Revision ID: 59bb2488a76b | ||
Revises: 4ba3479cb8df | ||
Create Date: 2024-10-16 16:55:42.324525 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '59bb2488a76b' | ||
down_revision: Union[str, None] = '4ba3479cb8df' | ||
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.bulk_insert( | ||
sa.table('roles', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('name', sa.String(length=80), nullable=False), | ||
), | ||
[ | ||
{'id': 1, 'name': 'participant'}, | ||
{'id': 2, 'name': 'volunteer'}, | ||
{'id': 3, 'name': 'admin'}, | ||
] | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
30 changes: 30 additions & 0 deletions
30
backend/app/migrations/versions/79de0b981dd8_add_auth_id_to_user_model.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,30 @@ | ||
"""Add auth_id to User model | ||
Revision ID: 79de0b981dd8 | ||
Revises: 59bb2488a76b | ||
Create Date: 2024-10-16 17:06:45.820859 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = '79de0b981dd8' | ||
down_revision: Union[str, None] = '59bb2488a76b' | ||
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('users', sa.Column('auth_id', sa.String(), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column('users', 'auth_id') | ||
# ### end Alembic commands ### |
40 changes: 40 additions & 0 deletions
40
backend/app/migrations/versions/c9bc2b4d1036_update_users_id_to_uuid_with_default.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,40 @@ | ||
"""Update users id to UUID with default | ||
Revision ID: c9bc2b4d1036 | ||
Revises: 79de0b981dd8 | ||
Create Date: 2024-10-16 17:13:53.820521 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'c9bc2b4d1036' | ||
down_revision: Union[str, None] = '79de0b981dd8' | ||
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.alter_column('users', 'id', | ||
existing_type=sa.VARCHAR(), | ||
type_=sa.UUID(), | ||
postgresql_using="id::uuid", | ||
server_default=sa.text("gen_random_uuid()"), | ||
existing_nullable=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.alter_column('users', 'id', | ||
existing_type=sa.UUID(), | ||
type_=sa.VARCHAR(), | ||
postgresql_using="id::text", | ||
server_default=None, | ||
existing_nullable=False) | ||
# ### 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from app.schemas.user import UserCreate, User | ||
from app.services.implementations.user_service import UserService | ||
from app.utilities.db_utils import get_db | ||
from sqlalchemy.orm import Session | ||
|
||
router = APIRouter( | ||
prefix="/users", | ||
tags=["users"], | ||
) | ||
|
||
# to do: send email verification via auth_service | ||
# to do: | ||
# send email verification via auth_service | ||
# allow signup methods other than email (like sign up w Google)?? | ||
|
||
@router.post("/", response_model=User) | ||
async def create_user(user: UserCreate, user_service: UserService = Depends()): | ||
async def create_user(user: UserCreate, db: Session = Depends(get_db)): | ||
user_service = UserService(db) | ||
try: | ||
created_user = await user_service.create_user(user) | ||
return created_user | ||
except HTTPException as http_ex: | ||
raise http_ex | ||
except Exception as e: | ||
raise HTTPException(status_code=500, detail=str(e)) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from sqlalchemy.orm import sessionmaker, Session | ||
from app.models import Base, init_app | ||
|
||
# Ensure the database is initialized | ||
init_app() | ||
|
||
# Create a SessionLocal class | ||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=Base.metadata.bind) | ||
|
||
def get_db() -> Session: | ||
db = SessionLocal() | ||
try: | ||
yield db | ||
finally: | ||
db.close() |
Oops, something went wrong.