diff options
author | r <r@freesoftwareextremist.com> | 2020-01-28 17:51:00 +0000 |
---|---|---|
committer | r <r@freesoftwareextremist.com> | 2020-01-28 17:58:29 +0000 |
commit | 2af37d47783aac8c650ffd1578e2297b5784c73d (patch) | |
tree | 7b5c7a4b2fa530285bfaa16324e818d97dd00408 /repository/sessionRepository.go | |
parent | 57d2a4288b02fd1245ee85ae629649798578cf6c (diff) | |
download | bloat-2af37d47783aac8c650ffd1578e2297b5784c73d.tar.gz bloat-2af37d47783aac8c650ffd1578e2297b5784c73d.zip |
Refactor everything
Diffstat (limited to 'repository/sessionRepository.go')
-rw-r--r-- | repository/sessionRepository.go | 64 |
1 files changed, 0 insertions, 64 deletions
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 -} |