diff options
Diffstat (limited to 'repository')
-rw-r--r-- | repository/appRepository.go | 42 | ||||
-rw-r--r-- | repository/sessionRepository.go | 64 |
2 files changed, 0 insertions, 106 deletions
diff --git a/repository/appRepository.go b/repository/appRepository.go deleted file mode 100644 index 9e57fb7..0000000 --- a/repository/appRepository.go +++ /dev/null @@ -1,42 +0,0 @@ -package repository - -import ( - "encoding/json" - - "bloat/kv" - "bloat/model" -) - -type appRepository struct { - db *kv.Database -} - -func NewAppRepository(db *kv.Database) *appRepository { - return &appRepository{ - db: db, - } -} - -func (repo *appRepository) 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 *appRepository) 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/repository/sessionRepository.go b/repository/sessionRepository.go deleted file mode 100644 index cb19f68..0000000 --- a/repository/sessionRepository.go +++ /dev/null @@ -1,64 +0,0 @@ -package repository - -import ( - "encoding/json" - - "bloat/kv" - "bloat/model" -) - -type sessionRepository struct { - db *kv.Database -} - -func NewSessionRepository(db *kv.Database) *sessionRepository { - return &sessionRepository{ - db: db, - } -} - -func (repo *sessionRepository) 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 *sessionRepository) Update(id string, accessToken string) (err error) { - data, err := repo.db.Get(id) - if err != nil { - return - } - - var s model.Session - err = json.Unmarshal(data, &s) - if err != nil { - return - } - - s.AccessToken = accessToken - - data, err = json.Marshal(s) - if err != nil { - return - } - - return repo.db.Set(id, data) -} - -func (repo *sessionRepository) 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 -} |