Add create, update, delete, read one methods

This commit is contained in:
kolaente 2020-09-06 19:11:12 +02:00
parent 1bdba90350
commit ca857b1f5a
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 31 additions and 0 deletions

View File

@ -50,3 +50,34 @@ type SavedFilter struct {
func (s *SavedFilter) TableName() string {
return "saved_filters"
}
func (s *SavedFilter) Create(auth web.Auth) error {
s.OwnerID = auth.GetID()
_, err := x.Insert(s)
return err
}
func getSavedFilterSimpleByID(id int64) (s *SavedFilter, err error) {
_, err = x.Where("id = ?", id).Get(s)
return
}
func (s *SavedFilter) ReadOne() error {
// s already contains almost the full saved filter from the rights check, we only need to add the user
u, err := user.GetUserByID(s.OwnerID)
s.Owner = u
return err
}
func (s *SavedFilter) ReadAll(auth web.Auth, search string, page int, perPage int) (result interface{}, resultCount int, numberOfTotalItems int64, err error) {
}
func (s *SavedFilter) Update() error {
_, err := x.Where("id = ?", s.ID).Update(s)
return err
}
func (s *SavedFilter) Delete() error {
_, err := x.Where("id = ?", s.ID).Delete(s)
return err
}