From 1f0dbda780186f657c0d76eff226ffc9301d1dc1 Mon Sep 17 00:00:00 2001 From: mStar Date: Fri, 15 Nov 2024 16:14:11 +0100 Subject: [PATCH] Add storage func for getting a relation between two accounts --- storage/accountRelations.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/storage/accountRelations.go b/storage/accountRelations.go index 644f44f..1a55eb9 100644 --- a/storage/accountRelations.go +++ b/storage/accountRelations.go @@ -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 + } +}