33 lines
594 B
Go
33 lines
594 B
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"spark-server/internal/pkg/errs"
|
|
)
|
|
|
|
func (s *Service) AreFriends(ctx context.Context, a, b int64) (bool, error) {
|
|
if !s.ready() || a <= 0 || b <= 0 || a == b {
|
|
return false, nil
|
|
}
|
|
ab, err := s.repo.GetRelation(ctx, a, b)
|
|
if err != nil {
|
|
if errors.Is(err, errs.ErrNotFound) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
if !ab.Active() {
|
|
return false, nil
|
|
}
|
|
ba, err := s.repo.GetRelation(ctx, b, a)
|
|
if err != nil {
|
|
if errors.Is(err, errs.ErrNotFound) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
return ba.Active(), nil
|
|
}
|