20 lines
836 B
Python
20 lines
836 B
Python
|
from sqlalchemy.orm import Session
|
||
|
from sqlalchemy import text
|
||
|
from db import models, schemas
|
||
|
from datetime import datetime
|
||
|
|
||
|
def create_card_expense(db: Session, card_expense: schemas.CardExpenseCreate):
|
||
|
db_card_expense = models.CardExpense(jang=card_expense.jang, yeo=card_expense.yeo, kim=card_expense.kim, choi=card_expense.choi, amount=card_expense.amount, purpose=card_expense.purpose, created_at=datetime.now())
|
||
|
db.add(db_card_expense)
|
||
|
db.commit()
|
||
|
db.refresh(db_card_expense)
|
||
|
return db_card_expense
|
||
|
|
||
|
|
||
|
def get_card_expenses_by_date(db: Session, year: int, month: int):
|
||
|
query = text("""
|
||
|
SELECT * FROM card_expenses
|
||
|
WHERE EXTRACT(YEAR FROM created_at) = :year
|
||
|
AND EXTRACT(MONTH FROM created_at) = :month
|
||
|
""")
|
||
|
return db.execute(query, {'year': year, 'month': month}).fetchall()
|