2024-11-11 08:04:42 +00:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AccountRelation struct {
|
|
|
|
gorm.Model
|
|
|
|
FromId string
|
|
|
|
ToId string
|
|
|
|
Accepted bool
|
|
|
|
}
|
2024-11-15 15:14:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|