Add storage func for getting a relation between two accounts
This commit is contained in:
parent
5546d31e5d
commit
1f0dbda780
1 changed files with 13 additions and 0 deletions
|
@ -10,3 +10,16 @@ type AccountRelation struct {
|
|||
ToId string
|
||||
Accepted bool
|
||||
}
|
||||
|
||||
func (s *Storage) GetRelationBetween(fromId, toId string) (*AccountRelation, error) {
|
||||
rel := AccountRelation{}
|
||||
err := s.db.Where(AccountRelation{FromId: fromId, ToId: toId}).First(&rel).Error
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
return nil, ErrEntryNotFound
|
||||
case nil:
|
||||
return &rel, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue