Early stages of the storage classes/decouplers for receipts and such
Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
This commit is contained in:
parent
aed333d04c
commit
031942c9d9
8
backend/internal/storage/images.go
Normal file
8
backend/internal/storage/images.go
Normal file
@ -0,0 +1,8 @@
|
||||
package storage
|
||||
|
||||
type Image struct {
|
||||
ID int64 `json:"id"`
|
||||
ReceiptID string `json:"receipt_id"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
1
backend/internal/storage/local_user.go
Normal file
1
backend/internal/storage/local_user.go
Normal file
@ -0,0 +1 @@
|
||||
package storage
|
||||
20
backend/internal/storage/receipts.go
Normal file
20
backend/internal/storage/receipts.go
Normal file
@ -0,0 +1,20 @@
|
||||
package storage
|
||||
|
||||
import "time"
|
||||
|
||||
type Receipt struct {
|
||||
ID int64 `json:"id"`
|
||||
Owner string `json:"username"`
|
||||
OwnerID int64 `json:"user_id"`
|
||||
ImageIDs []int64 `json:"image_ids"`
|
||||
Data ReceiptData `json:"receipt_data"`
|
||||
}
|
||||
|
||||
type ReceiptData struct {
|
||||
Date time.Time `json:"date"`
|
||||
Subtotal float64 `json:"subtotal"`
|
||||
Total float64 `json:"total"`
|
||||
Tax float64 `json:"tax"`
|
||||
Items map[string]float64 `json:"items"`
|
||||
// Currency string `json:"currency"`
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
package storage
|
||||
|
||||
import "time"
|
||||
|
||||
type SessionStore interface {
|
||||
AddSession(sessKey string) error
|
||||
RemoveSession(sessKey string) error
|
||||
SetLifespan(sessKey string, lf time.Time) error
|
||||
}
|
||||
38
backend/internal/storage/storage.go
Normal file
38
backend/internal/storage/storage.go
Normal file
@ -0,0 +1,38 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type Storage struct {
|
||||
Receipts interface {
|
||||
GetByID(context.Context, int64) (*Receipt, error)
|
||||
}
|
||||
Users interface {
|
||||
AddUser(user string, password string) error
|
||||
RemoveUser(user string, password string) error
|
||||
UpdateUserPass(user string, oldPassword string, newPass string) error
|
||||
}
|
||||
Images interface {
|
||||
GetByID(context.Context, int64) (*Image, error)
|
||||
}
|
||||
}
|
||||
|
||||
func NewSQLStorage(db *sql.DB) Storage {
|
||||
return Storage{}
|
||||
}
|
||||
|
||||
func withTx(db *sql.DB, ctx context.Context, fn func(*sql.Tx) error) error {
|
||||
tx, err := db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := fn(tx); err != nil {
|
||||
_ = tx.Rollback()
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
package storage
|
||||
|
||||
type UserStore interface {
|
||||
AddUser(user string, password string) error
|
||||
RemoveUser(user string, password string) error
|
||||
UpdateUserPass(user string, password string) error
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user