diff --git a/storage/follows.go b/storage/follows.go index f1b6caa..f15517d 100644 --- a/storage/follows.go +++ b/storage/follows.go @@ -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) diff --git a/storage/person.go b/storage/person.go index 19832ca..975e664 100644 --- a/storage/person.go +++ b/storage/person.go @@ -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 +} diff --git a/storage/storage.go b/storage/storage.go index a7cff87..fc6480c 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -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 }