feat: implement repository

This commit is contained in:
clz 2023-06-10 15:21:30 +08:00
parent 751bab15d1
commit 91f212ba62

View File

@ -6,51 +6,63 @@ import (
) )
type sqliteRepository struct { type sqliteRepository struct {
db *gorm.DB *gorm.DB
} }
func NewBillRepository(db *gorm.DB) BillRepository { func NewBillRepository(db *gorm.DB) BillRepository {
return &sqliteRepository{ return &sqliteRepository{
db: db, db,
} }
} }
func (db *sqliteRepository) GetBills(ctx context.Context) (*[]Bill, error) { func (db *sqliteRepository) GetBills(ctx context.Context) ([]Bill, error) {
//TODO implement me var bills []Bill
panic("implement me") if err := db.Find(&bills).Error; err != nil {
return nil, err
}
return bills, nil
} }
func (db *sqliteRepository) GetBillByDay(ctx context.Context, year int, month int, day int) (*[]Bill, error) { func (db *sqliteRepository) GetBillByDay(ctx context.Context, year int, month int, day int) ([]Bill, error) {
//TODO implement me var bills []Bill
panic("implement me") if err := db.Where("year =? AND month =? AND day =?", year, month, day).Find(&bills).Error; err != nil {
return nil, err
}
return bills, nil
} }
func (db *sqliteRepository) GetBillByMonth(ctx context.Context, year int, month int) (*[]Bill, error) { func (db *sqliteRepository) GetBillByMonth(ctx context.Context, year int, month int) ([]Bill, error) {
//TODO implement me var bills []Bill
panic("implement me") if err := db.Where("year =? AND month =?", year, month).Find(&bills).Error; err != nil {
return nil, err
}
return bills, nil
} }
func (db *sqliteRepository) GetBillByYear(ctx context.Context, year int) (*[]Bill, error) { func (db *sqliteRepository) GetBillByYear(ctx context.Context, year int) ([]Bill, error) {
//TODO implement me var bills []Bill
panic("implement me") if err := db.Where("year =?", year).Find(&bills).Error; err != nil {
return nil, err
}
return bills, nil
} }
func (db *sqliteRepository) GetBillByID(ctx context.Context, id int) (*Bill, error) { func (db *sqliteRepository) GetBillByID(ctx context.Context, id int) (*Bill, error) {
//TODO implement me var bill Bill
panic("implement me") if err := db.Where("id =?", id).Find(&bill).Error; err != nil {
return nil, err
}
return &bill, nil
} }
func (db *sqliteRepository) CreateBill(ctx context.Context, bill *Bill) error { func (db *sqliteRepository) CreateBill(ctx context.Context, bill *Bill) error {
//TODO implement me return db.Create(bill).Error
panic("implement me")
} }
func (db *sqliteRepository) UpdateBill(ctx context.Context, bill *Bill) error { func (db *sqliteRepository) UpdateBill(ctx context.Context, bill *Bill) error {
//TODO implement me return db.Save(bill).Error
panic("implement me")
} }
func (db *sqliteRepository) DeleteBill(ctx context.Context, id int) error { func (db *sqliteRepository) DeleteBill(ctx context.Context, id int) error {
//TODO implement me return db.Where("id =?", id).Delete(&Bill{}).Error
panic("implement me")
} }