Add Comments
parent
921cc2f930
commit
c6e6b08305
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
|
|
|
@ -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})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue