add not found error
add checks for if something actually exists in db
This commit is contained in:
parent
77b275130b
commit
5593efee37
3 changed files with 20 additions and 0 deletions
|
@ -18,6 +18,11 @@ type Follow struct {
|
|||
}
|
||||
|
||||
func (s *Storage) GetFollowersFor(url string) ([]Follow, error) {
|
||||
var pHit int64
|
||||
s.Db.Where("url = ?", url).Count(&pHit)
|
||||
if pHit <= 0 {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
var followed *Person = &Person{}
|
||||
s.Db.Table("people").First(&followed, "url = ?", url)
|
||||
var f []Follow = make([]Follow, 0)
|
||||
|
|
|
@ -57,3 +57,15 @@ func (pdb *Person) IntoAPPerson() (*astreams.Person, error) {
|
|||
actor.PreferredUsername = pdb.Name
|
||||
return nil, errors.New("unimplemented")
|
||||
}
|
||||
|
||||
// Gets a person from the db by name
|
||||
func (s *Storage) GetPersonByName(name string) (*Person, error) {
|
||||
var nrFound int64
|
||||
s.Db.Table("people").Where("name = ?", name).Count(&nrFound)
|
||||
if nrFound <= 0 {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
var p Person
|
||||
s.Db.Table("people").Where("name = ?", name).First(&p)
|
||||
return &p, nil
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gitlab.com/mstarongitlab/linstrom/config"
|
||||
|
@ -18,6 +19,8 @@ import (
|
|||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var ErrNotFound = errors.New("entry not found")
|
||||
|
||||
type Storage struct {
|
||||
Db *gorm.DB
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue