ussd/internal/utils/account_utils.go

45 lines
903 B
Go
Raw Normal View History

package utils
import (
2024-09-05 16:07:20 +02:00
"context"
"encoding/json"
2024-09-05 16:07:20 +02:00
"git.defalsify.org/vise.git/db"
)
type AccountFileHandler struct {
2024-09-05 16:07:20 +02:00
store db.Db
}
2024-09-05 16:07:20 +02:00
func NewAccountFileHandler(store db.Db) *AccountFileHandler {
return &AccountFileHandler{
store: store,
}
2024-09-05 16:07:20 +02:00
}
func (afh *AccountFileHandler) ReadAccountData(ctx context.Context, sessionId string) (map[string]string, error) {
var accountData map[string]string
2024-09-05 16:07:20 +02:00
jsonData, err := ReadEntry(ctx, afh.store, sessionId, DATA_ACCOUNT)
2024-09-06 11:42:24 +02:00
if err != nil {
return nil,err
}
err = json.Unmarshal(jsonData, &accountData)
if err != nil {
return nil, err
}
return accountData, nil
}
2024-09-05 16:07:20 +02:00
func (afh *AccountFileHandler) WriteAccountData(ctx context.Context, sessionId string, accountData map[string]string) error {
_, err := json.Marshal(accountData)
if err != nil {
return err
}
2024-09-05 16:07:20 +02:00
return nil
}
func (afh *AccountFileHandler) EnsureFileExists() error {
2024-09-05 16:07:20 +02:00
return nil
}