feat: pay bills
This commit is contained in:
parent
d747454f4a
commit
8c681282ef
15 changed files with 607 additions and 65 deletions
27
internal/repository/category.go
Normal file
27
internal/repository/category.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package repository
|
||||
|
||||
import (
|
||||
"git.juancwu.dev/juancwu/budgit/internal/model"
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type CategoryRepository interface {
|
||||
All() ([]*model.Category, error)
|
||||
}
|
||||
|
||||
type categoryRepository struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
|
||||
func NewCategoryRepository(db *sqlx.DB) CategoryRepository {
|
||||
return &categoryRepository{db: db}
|
||||
}
|
||||
|
||||
func (r *categoryRepository) All() ([]*model.Category, error) {
|
||||
var categories []*model.Category
|
||||
query := `SELECT * FROM categories ORDER BY name ASC;`
|
||||
if err := r.db.Select(&categories, query); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return categories, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue