diff --git a/bolt/config.go b/bolt/config.go index eab21f1b..e3d7fb81 100644 --- a/bolt/config.go +++ b/bolt/config.go @@ -5,10 +5,12 @@ import ( fm "github.com/hacdias/filemanager" ) +// ConfigStore is a configuration store. type ConfigStore struct { DB *storm.DB } +// Get gets a configuration from the database to an interface. func (c ConfigStore) Get(name string, to interface{}) error { err := c.DB.Get("config", name, to) if err == storm.ErrNotFound { @@ -18,6 +20,7 @@ func (c ConfigStore) Get(name string, to interface{}) error { return err } +// Save saves a configuration from an interface to the database. func (c ConfigStore) Save(name string, from interface{}) error { return c.DB.Set("config", name, from) } diff --git a/bolt/share.go b/bolt/share.go index 189ed418..cbe6eed5 100644 --- a/bolt/share.go +++ b/bolt/share.go @@ -6,10 +6,12 @@ import ( fm "github.com/hacdias/filemanager" ) +// ShareStore is a shareable links store. type ShareStore struct { DB *storm.DB } +// Get gets a Share Link from an hash. func (s ShareStore) Get(hash string) (*fm.ShareLink, error) { var v *fm.ShareLink err := s.DB.One("Hash", hash, &v) @@ -20,6 +22,7 @@ func (s ShareStore) Get(hash string) (*fm.ShareLink, error) { return v, err } +// GetPermanent gets the permanent link from a path. func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) { var v *fm.ShareLink err := s.DB.Select(q.Eq("Path", path), q.Eq("Expires", false)).First(&v) @@ -30,6 +33,7 @@ func (s ShareStore) GetPermanent(path string) (*fm.ShareLink, error) { return v, err } +// GetByPath gets all the links for a specific path. func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) { var v []*fm.ShareLink err := s.DB.Find("Path", hash, &v) @@ -40,16 +44,19 @@ func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) { return v, err } +// Gets retrieves all the shareable links. func (s ShareStore) Gets() ([]*fm.ShareLink, error) { var v []*fm.ShareLink err := s.DB.All(&v) return v, err } +// Save stores a Share Link on the database. func (s ShareStore) Save(l *fm.ShareLink) error { return s.DB.Save(l) } +// Delete deletes a Share Link from the database. func (s ShareStore) Delete(hash string) error { return s.DB.DeleteStruct(&fm.ShareLink{Hash: hash}) } diff --git a/bolt/users.go b/bolt/users.go index 2c12f69a..55758614 100644 --- a/bolt/users.go +++ b/bolt/users.go @@ -7,10 +7,12 @@ import ( fm "github.com/hacdias/filemanager" ) +// UsersStore is a users store. type UsersStore struct { DB *storm.DB } +// Get gets a user with a certain id from the database. func (u UsersStore) Get(id int, builder fm.FSBuilder) (*fm.User, error) { var us *fm.User err := u.DB.One("ID", id, us) @@ -26,6 +28,7 @@ func (u UsersStore) Get(id int, builder fm.FSBuilder) (*fm.User, error) { return us, nil } +// Gets gets all the users from the database. func (u UsersStore) Gets(builder fm.FSBuilder) ([]*fm.User, error) { var us []*fm.User err := u.DB.All(us) @@ -40,6 +43,7 @@ func (u UsersStore) Gets(builder fm.FSBuilder) ([]*fm.User, error) { return us, err } +// Updates the whole user object or only certain fields. func (u UsersStore) Update(us *fm.User, fields ...string) error { if len(fields) == 0 { return u.Save(us) @@ -55,10 +59,12 @@ func (u UsersStore) Update(us *fm.User, fields ...string) error { return nil } +// Save saves a user to the database. func (u UsersStore) Save(us *fm.User) error { return u.DB.Save(us) } +// Delete deletes a user from the database. func (u UsersStore) Delete(id int) error { return u.DB.DeleteStruct(&fm.User{ID: id}) }