62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"spark-server/internal/module/friend/entity"
|
|
"spark-server/internal/pkg/errs"
|
|
)
|
|
|
|
func (s *Service) ListFriendIDs(ctx context.Context, userID int64) ([]int64, error) {
|
|
if !s.ready() || userID <= 0 {
|
|
return nil, errs.ErrUnauthorized
|
|
}
|
|
return s.repo.ListFriendIDs(ctx, userID)
|
|
}
|
|
|
|
func (s *Service) ListBlockedPeerIDs(ctx context.Context, userID int64) ([]int64, error) {
|
|
if !s.ready() || userID <= 0 {
|
|
return nil, errs.ErrUnauthorized
|
|
}
|
|
return s.repo.ListBlockedPeerIDs(ctx, userID)
|
|
}
|
|
|
|
func (s *Service) Relation(ctx context.Context, userID, peerID int64) (*entity.Relation, error) {
|
|
if !s.ready() || userID <= 0 || peerID <= 0 {
|
|
return nil, errs.ErrNotFound
|
|
}
|
|
return s.repo.GetRelation(ctx, userID, peerID)
|
|
}
|
|
|
|
func (s *Service) BlockedEither(ctx context.Context, a, b int64) (bool, error) {
|
|
if !s.ready() || a <= 0 || b <= 0 || a == b {
|
|
return false, nil
|
|
}
|
|
return s.repo.BlockedEither(ctx, a, b)
|
|
}
|
|
|
|
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
|
|
}
|