clean taux info
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
7c62edda39
commit
af0d98683c
5 changed files with 187 additions and 0 deletions
69
internal/store/account.go
Normal file
69
internal/store/account.go
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
ID int32 `json:"id"`
|
||||
Nom string `json:"nom"`
|
||||
Type string `json:"type"`
|
||||
DeviseReference string `json:"devise_reference"`
|
||||
Plafond *float64 `json:"plafond,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAccountParams struct {
|
||||
Nom string `json:"nom"`
|
||||
Type string `json:"type"`
|
||||
DeviseReference string `json:"devise_reference"`
|
||||
Plafond *float64 `json:"plafond,omitempty"`
|
||||
}
|
||||
|
||||
func (s *Store) ListAccounts(ctx context.Context) ([]Account, error) {
|
||||
rows, err := s.pool.Query(ctx,
|
||||
`SELECT id, nom, type, devise_reference, plafond FROM account ORDER BY nom`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pgx.CollectRows(rows, pgx.RowToStructByName[Account])
|
||||
}
|
||||
|
||||
func (s *Store) GetAccount(ctx context.Context, id int32) (Account, error) {
|
||||
rows, err := s.pool.Query(ctx,
|
||||
`SELECT id, nom, type, devise_reference, plafond FROM account WHERE id = $1`, id)
|
||||
if err != nil {
|
||||
return Account{}, err
|
||||
}
|
||||
return pgx.CollectOneRow(rows, pgx.RowToStructByName[Account])
|
||||
}
|
||||
|
||||
func (s *Store) CreateAccount(ctx context.Context, p CreateAccountParams) (Account, error) {
|
||||
rows, err := s.pool.Query(ctx,
|
||||
`INSERT INTO account (nom, type, devise_reference, plafond, taux)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, nom, type, devise_reference, plafond`,
|
||||
p.Nom, p.Type, p.DeviseReference, p.Plafond)
|
||||
if err != nil {
|
||||
return Account{}, err
|
||||
}
|
||||
return pgx.CollectOneRow(rows, pgx.RowToStructByName[Account])
|
||||
}
|
||||
|
||||
func (s *Store) UpdateAccount(ctx context.Context, id int32, p CreateAccountParams) (Account, error) {
|
||||
rows, err := s.pool.Query(ctx,
|
||||
`UPDATE account SET nom = $2, type = $3, devise_reference = $4, plafond = $5
|
||||
WHERE id = $1
|
||||
RETURNING id, nom, type, devise_reference, plafond`,
|
||||
id, p.Nom, p.Type, p.DeviseReference, p.Plafond)
|
||||
if err != nil {
|
||||
return Account{}, err
|
||||
}
|
||||
return pgx.CollectOneRow(rows, pgx.RowToStructByName[Account])
|
||||
}
|
||||
|
||||
func (s *Store) DeleteAccount(ctx context.Context, id int32) error {
|
||||
_, err := s.pool.Exec(ctx, `DELETE FROM account WHERE id = $1`, id)
|
||||
return err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue