-
Notifications
You must be signed in to change notification settings - Fork 0
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 #10 from slepp22/user-api
Get User implemented
- Loading branch information
Showing
6 changed files
with
72 additions
and
12 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 |
---|---|---|
|
@@ -95,7 +95,15 @@ docker tag sleppp/inventory-backend gcr.io/inventory-database-420916/inventory-b | |
```bash | ||
docker push gcr.io/inventory-database-420916/inventory-backend:latest | ||
``` | ||
## SQL Scripts for Test Data | ||
```sql | ||
INSERT INTO users (firstname, lastname, email, password, role) | ||
VALUES ('Firstname1', 'Lastname1', '[email protected]', 'password1', 'student'); | ||
|
||
INSERT INTO users (firstname, lastname, email, password, role) | ||
VALUES ('Firstname2', 'Lastname2', '[email protected]', 'password2', 'admin'); | ||
|
||
``` | ||
If you encounter any errors during the deployment process, make sure you are authenticated with Google Cloud CLI | ||
(gcloud auth login) and have the necessary permissions to push images to Google Container Registry. For troubleshooting | ||
tips or common errors, refer to the Google Cloud Run documentation. | ||
|
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,38 @@ | ||
"""updated user model | ||
Revision ID: dd5d09078881 | ||
Revises: 8e8c4627a4df | ||
Create Date: 2024-04-27 13:50:02.573313 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'dd5d09078881' | ||
down_revision: Union[str, None] = '8e8c4627a4df' | ||
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('firstname', sa.String(), nullable=True)) | ||
op.add_column('users', sa.Column('lastname', sa.String(), nullable=True)) | ||
op.add_column('users', sa.Column('password', sa.String(), nullable=True)) | ||
op.add_column('users', sa.Column('role', sa.String(), nullable=True)) | ||
op.drop_column('users', 'name') | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column('users', sa.Column('name', sa.VARCHAR(), autoincrement=False, nullable=True)) | ||
op.drop_column('users', 'role') | ||
op.drop_column('users', 'password') | ||
op.drop_column('users', 'lastname') | ||
op.drop_column('users', 'firstname') | ||
# ### 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
from sqlalchemy import Column, Integer, String | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from fastapi import APIRouter, Depends, HTTPException | ||
from sqlalchemy.orm import Session | ||
from db.config import SessionLocal | ||
from app.models import user as user_model | ||
|
||
Base = declarative_base() | ||
router = APIRouter() | ||
|
||
class User(Base): | ||
__tablename__ = 'users' | ||
def get_db(): | ||
db = SessionLocal() | ||
try: | ||
yield db | ||
finally: | ||
db.close() | ||
|
||
id = Column(Integer, primary_key=True) | ||
name = Column(String) | ||
email = Column(String, unique=True) | ||
@router.get("/users/{user_id}") | ||
def get_user_by_id(user_id: int, db: Session = Depends(get_db)): | ||
user = db.query(user_model.User).filter(user_model.User.id == user_id).first() | ||
if user is None: | ||
raise HTTPException(status_code=404, detail="User not found") | ||
return user |
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