aboutsummaryrefslogtreecommitdiff
path: root/repo
diff options
context:
space:
mode:
Diffstat (limited to 'repo')
-rw-r--r--repo/appRepo.go42
-rw-r--r--repo/sessionRepo.go42
2 files changed, 84 insertions, 0 deletions
diff --git a/repo/appRepo.go b/repo/appRepo.go
new file mode 100644
index 0000000..6338c4a
--- /dev/null
+++ b/repo/appRepo.go
@@ -0,0 +1,42 @@
+package repo
+
+import (
+ "encoding/json"
+
+ "bloat/kv"
+ "bloat/model"
+)
+
+type appRepo struct {
+ db *kv.Database
+}
+
+func NewAppRepo(db *kv.Database) *appRepo {
+ return &appRepo{
+ db: db,
+ }
+}
+
+func (repo *appRepo) Add(a model.App) (err error) {
+ data, err := json.Marshal(a)
+ if err != nil {
+ return
+ }
+ err = repo.db.Set(a.InstanceDomain, data)
+ return
+}
+
+func (repo *appRepo) Get(instanceDomain string) (a model.App, err error) {
+ data, err := repo.db.Get(instanceDomain)
+ if err != nil {
+ err = model.ErrAppNotFound
+ return
+ }
+
+ err = json.Unmarshal(data, &a)
+ if err != nil {
+ return
+ }
+
+ return
+}
diff --git a/repo/sessionRepo.go b/repo/sessionRepo.go
new file mode 100644
index 0000000..ce923b1
--- /dev/null
+++ b/repo/sessionRepo.go
@@ -0,0 +1,42 @@
+package repo
+
+import (
+ "encoding/json"
+
+ "bloat/kv"
+ "bloat/model"
+)
+
+type sessionRepo struct {
+ db *kv.Database
+}
+
+func NewSessionRepo(db *kv.Database) *sessionRepo {
+ return &sessionRepo{
+ db: db,
+ }
+}
+
+func (repo *sessionRepo) Add(s model.Session) (err error) {
+ data, err := json.Marshal(s)
+ if err != nil {
+ return
+ }
+ err = repo.db.Set(s.ID, data)
+ return
+}
+
+func (repo *sessionRepo) Get(id string) (s model.Session, err error) {
+ data, err := repo.db.Get(id)
+ if err != nil {
+ err = model.ErrSessionNotFound
+ return
+ }
+
+ err = json.Unmarshal(data, &s)
+ if err != nil {
+ return
+ }
+
+ return
+}