2024-08-27 10:19:49 +02:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import (
|
2024-09-05 02:42:12 +02:00
|
|
|
"context"
|
2024-08-27 10:19:49 +02:00
|
|
|
"encoding/json"
|
2024-09-05 02:42:12 +02:00
|
|
|
|
|
|
|
"git.defalsify.org/vise.git/db"
|
2024-08-27 10:19:49 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type AccountFileHandler struct {
|
2024-09-05 02:42:12 +02:00
|
|
|
store db.Db
|
2024-08-27 10:19:49 +02:00
|
|
|
}
|
|
|
|
|
2024-09-05 02:42:12 +02:00
|
|
|
func NewAccountFileHandler(store db.Db) *AccountFileHandler {
|
|
|
|
return &AccountFileHandler{
|
|
|
|
store: store,
|
2024-08-27 10:19:49 +02:00
|
|
|
}
|
2024-09-05 02:42:12 +02:00
|
|
|
}
|
2024-08-27 10:19:49 +02:00
|
|
|
|
2024-09-05 02:42:12 +02:00
|
|
|
func (afh *AccountFileHandler) ReadAccountData(ctx context.Context, sessionId string) (map[string]string, error) {
|
2024-08-27 10:19:49 +02:00
|
|
|
var accountData map[string]string
|
2024-09-05 02:42:12 +02:00
|
|
|
jsonData, err := ReadEntry(ctx, afh.store, sessionId, DATA_ACCOUNT)
|
2024-08-27 10:19:49 +02:00
|
|
|
err = json.Unmarshal(jsonData, &accountData)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return accountData, nil
|
|
|
|
}
|
|
|
|
|
2024-09-05 02:42:12 +02:00
|
|
|
func (afh *AccountFileHandler) WriteAccountData(ctx context.Context, sessionId string, accountData map[string]string) error {
|
|
|
|
b, err := json.Marshal(accountData)
|
2024-08-27 10:19:49 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-09-05 02:42:12 +02:00
|
|
|
return WriteEntry(ctx, afh.store, sessionId, DATA_ACCOUNT, b)
|
2024-08-27 10:19:49 +02:00
|
|
|
}
|