-
-
Notifications
You must be signed in to change notification settings - Fork 0
Copilot Claude No Tuning #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vodkar
wants to merge
3
commits into
master
Choose a base branch
from
copilot-claude-no-tuning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
backend/app/alembic/versions/f3b2a1c9d8e7_add_wallet_and_transaction_tables.py
This file contains hidden or 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,92 @@ | ||
""" | ||
Add wallet and transaction tables. | ||
Revision ID: f3b2a1c9d8e7 | ||
Revises: d98dd8ec85a3 | ||
Create Date: 2025-09-15 12:30:00.000000 | ||
""" | ||
|
||
import sqlalchemy as sa | ||
import sqlmodel.sql.sqltypes | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "f3b2a1c9d8e7" | ||
down_revision = "d98dd8ec85a3" | ||
branch_labels: str | None = None | ||
depends_on: str | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
"""Upgrade database schema.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
|
||
# Create wallet table | ||
op.create_table( | ||
"wallet", | ||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("user_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("balance", sa.DECIMAL(precision=10, scale=2), nullable=False), | ||
sa.Column( | ||
"currency", sqlmodel.sql.sqltypes.AutoString(length=3), nullable=False | ||
), | ||
sa.Column("created_at", sa.DateTime(), nullable=False), | ||
sa.Column("updated_at", sa.DateTime(), nullable=False), | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration script includes Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
sa.ForeignKeyConstraint( | ||
["user_id"], | ||
["user.id"], | ||
ondelete="CASCADE", | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index(op.f("ix_wallet_user_id"), "wallet", ["user_id"], unique=False) | ||
op.create_index( | ||
"ix_wallet_user_currency", "wallet", ["user_id", "currency"], unique=True | ||
) | ||
|
||
# Create transaction table | ||
op.create_table( | ||
"transaction", | ||
sa.Column("id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("wallet_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("amount", sa.DECIMAL(precision=10, scale=2), nullable=False), | ||
sa.Column( | ||
"type", sa.Enum("credit", "debit", name="transactiontype"), nullable=False | ||
), | ||
sa.Column("timestamp", sa.DateTime(), nullable=False), | ||
sa.Column( | ||
"currency", sqlmodel.sql.sqltypes.AutoString(length=3), nullable=False | ||
), | ||
sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
sa.ForeignKeyConstraint( | ||
["wallet_id"], | ||
["wallet.id"], | ||
ondelete="CASCADE", | ||
), | ||
sa.PrimaryKeyConstraint("id"), | ||
) | ||
op.create_index( | ||
op.f("ix_transaction_wallet_id"), "transaction", ["wallet_id"], unique=False | ||
) | ||
op.create_index( | ||
op.f("ix_transaction_timestamp"), "transaction", ["timestamp"], unique=False | ||
) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
"""Downgrade database schema.""" | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f("ix_transaction_timestamp"), table_name="transaction") | ||
op.drop_index(op.f("ix_transaction_wallet_id"), table_name="transaction") | ||
op.drop_table("transaction") | ||
op.drop_index("ix_wallet_user_currency", table_name="wallet") | ||
op.drop_index(op.f("ix_wallet_user_id"), table_name="wallet") | ||
op.drop_table("wallet") | ||
|
||
# Drop the enum type | ||
op.execute("DROP TYPE IF EXISTS transactiontype") | ||
# ### end Alembic commands ### |
This file contains hidden or 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 hidden or 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,70 @@ | ||
"""Transaction management API endpoints.""" | ||
|
||
import uuid | ||
|
||
from app.api.deps import CurrentUser, SessionDep | ||
from app.constants import BAD_REQUEST_CODE, CREATED_CODE, NOT_FOUND_CODE | ||
from app.crud import create_transaction, get_wallet_by_id, get_wallet_transactions | ||
from app.models import TransactionCreate, TransactionPublic, TransactionsPublic | ||
from fastapi import APIRouter, HTTPException | ||
|
||
router = APIRouter(prefix="/transactions", tags=["transactions"]) | ||
|
||
|
||
@router.post("/", status_code=CREATED_CODE) | ||
def create_wallet_transaction( | ||
*, | ||
session: SessionDep, | ||
current_user: CurrentUser, | ||
transaction_in: TransactionCreate, | ||
) -> TransactionPublic: | ||
"""Create a new transaction for a wallet.""" | ||
# Verify that the wallet belongs to the current user | ||
wallet = get_wallet_by_id(session=session, wallet_id=transaction_in.wallet_id) | ||
if not wallet: | ||
raise HTTPException(status_code=NOT_FOUND_CODE, detail="Wallet not found") | ||
|
||
if not current_user.is_superuser and (wallet.user_id != current_user.id): | ||
raise HTTPException( | ||
status_code=BAD_REQUEST_CODE, | ||
detail="Not enough permissions", | ||
) | ||
|
||
try: | ||
db_transaction = create_transaction( | ||
session=session, transaction_in=transaction_in | ||
) | ||
return TransactionPublic.model_validate(db_transaction) | ||
except ValueError as e: | ||
raise HTTPException( | ||
status_code=BAD_REQUEST_CODE, | ||
detail=str(e), | ||
) from e | ||
|
||
|
||
@router.get("/wallet/{wallet_id}") | ||
def read_wallet_transactions( | ||
session: SessionDep, | ||
current_user: CurrentUser, | ||
wallet_id: uuid.UUID, | ||
) -> TransactionsPublic: | ||
"""Get all transactions for a specific wallet.""" | ||
# Verify that the wallet belongs to the current user | ||
wallet = get_wallet_by_id(session=session, wallet_id=wallet_id) | ||
if not wallet: | ||
raise HTTPException(status_code=NOT_FOUND_CODE, detail="Wallet not found") | ||
|
||
if not current_user.is_superuser and (wallet.user_id != current_user.id): | ||
raise HTTPException( | ||
status_code=BAD_REQUEST_CODE, | ||
detail="Not enough permissions", | ||
) | ||
|
||
transaction_list = get_wallet_transactions(session=session, wallet_id=wallet_id) | ||
transaction_data = [ | ||
TransactionPublic.model_validate(transaction) | ||
for transaction in transaction_list | ||
] | ||
return TransactionsPublic( | ||
transaction_data=transaction_data, count=len(transaction_data) | ||
) |
This file contains hidden or 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,65 @@ | ||
"""Wallet management API endpoints.""" | ||
|
||
import uuid | ||
|
||
from app.api.deps import CurrentUser, SessionDep | ||
from app.constants import BAD_REQUEST_CODE, CREATED_CODE, NOT_FOUND_CODE | ||
from app.crud import create_wallet, get_user_wallets, get_wallet_by_id | ||
from app.models import Message, WalletCreate, WalletPublic, WalletsPublic | ||
from fastapi import APIRouter, HTTPException | ||
|
||
router = APIRouter(prefix="/wallets", tags=["wallets"]) | ||
|
||
|
||
@router.post("/", status_code=CREATED_CODE) | ||
def create_user_wallet( | ||
*, | ||
session: SessionDep, | ||
current_user: CurrentUser, | ||
wallet_in: WalletCreate, | ||
) -> WalletPublic: | ||
"""Create a new wallet for the current user.""" | ||
try: | ||
db_wallet = create_wallet( | ||
session=session, | ||
wallet_in=wallet_in, | ||
user_id=current_user.id, | ||
) | ||
return WalletPublic.model_validate(db_wallet) | ||
except ValueError as e: | ||
raise HTTPException( | ||
status_code=BAD_REQUEST_CODE, | ||
detail=str(e), | ||
) from e | ||
|
||
|
||
@router.get("/") | ||
def read_user_wallets( | ||
session: SessionDep, | ||
current_user: CurrentUser, | ||
) -> WalletsPublic: | ||
"""Retrieve all wallets for the current user.""" | ||
wallet_list = get_user_wallets(session=session, user_id=current_user.id) | ||
wallet_data = [WalletPublic.model_validate(wallet) for wallet in wallet_list] | ||
return WalletsPublic(wallet_data=wallet_data, count=len(wallet_data)) | ||
|
||
|
||
@router.get("/{wallet_id}") | ||
def read_wallet( | ||
session: SessionDep, | ||
current_user: CurrentUser, | ||
wallet_id: uuid.UUID, | ||
) -> WalletPublic: | ||
"""Get wallet details by ID.""" | ||
db_wallet = get_wallet_by_id(session=session, wallet_id=wallet_id) | ||
if not db_wallet: | ||
raise HTTPException(status_code=NOT_FOUND_CODE, detail="Wallet not found") | ||
|
||
# Check if wallet belongs to current user or user is superuser | ||
if not current_user.is_superuser and (db_wallet.user_id != current_user.id): | ||
raise HTTPException( | ||
status_code=BAD_REQUEST_CODE, | ||
detail="Not enough permissions", | ||
) | ||
|
||
return WalletPublic.model_validate(db_wallet) |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration script includes
created_at
andupdated_at
columns that are not defined in the SQLModel classes. This mismatch between the migration and model definitions will cause issues.Copilot uses AI. Check for mistakes.