aboutsummaryrefslogtreecommitdiff
path: root/repo
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2020-01-28 17:51:00 +0000
committerr <r@freesoftwareextremist.com>2020-01-28 17:58:29 +0000
commit2af37d47783aac8c650ffd1578e2297b5784c73d (patch)
tree7b5c7a4b2fa530285bfaa16324e818d97dd00408 /repo
parent57d2a4288b02fd1245ee85ae629649798578cf6c (diff)
downloadbloat-2af37d47783aac8c650ffd1578e2297b5784c73d.tar.gz
bloat-2af37d47783aac8c650ffd1578e2297b5784c73d.zip
Refactor everything
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
+}