ussd/internal/utils/userStore.go

35 lines
969 B
Go
Raw Normal View History

2024-09-09 16:16:08 +02:00
package utils
import (
"context"
2024-10-30 02:28:55 +01:00
"git.grassecon.net/urdt/ussd/common"
2024-09-09 16:16:08 +02:00
"git.defalsify.org/vise.git/db"
)
type DataStore interface {
2024-09-10 10:24:09 +02:00
db.Db
2024-10-30 02:28:55 +01:00
ReadEntry(ctx context.Context, sessionId string, typ common.DataTyp) ([]byte, error)
WriteEntry(ctx context.Context, sessionId string, typ common.DataTyp, value []byte) error
2024-09-09 16:16:08 +02:00
}
type UserDataStore struct {
2024-09-10 10:24:09 +02:00
db.Db
2024-09-09 16:16:08 +02:00
}
// ReadEntry retrieves an entry from the store based on the provided parameters.
2024-10-30 02:28:55 +01:00
func (store *UserDataStore) ReadEntry(ctx context.Context, sessionId string, typ common.DataTyp) ([]byte, error) {
2024-09-10 10:24:09 +02:00
store.SetPrefix(db.DATATYPE_USERDATA)
store.SetSession(sessionId)
2024-10-30 02:28:55 +01:00
k := common.PackKey(typ, []byte(sessionId))
2024-09-09 16:16:08 +02:00
return store.Get(ctx, k)
}
2024-10-30 02:28:55 +01:00
func (store *UserDataStore) WriteEntry(ctx context.Context, sessionId string, typ common.DataTyp, value []byte) error {
2024-09-10 10:24:09 +02:00
store.SetPrefix(db.DATATYPE_USERDATA)
store.SetSession(sessionId)
2024-10-30 02:28:55 +01:00
k := common.PackKey(typ, []byte(sessionId))
2024-09-10 10:24:09 +02:00
return store.Put(ctx, k, value)
2024-09-09 16:16:08 +02:00
}