Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"time"
|
|
|
|
"spark-server/internal/module/friend/entity"
|
|
"spark-server/internal/pkg/errs"
|
|
"spark-server/internal/pkg/i18n"
|
|
"spark-server/internal/pkg/reqctx"
|
|
)
|
|
|
|
func (s *Service) Block(ctx context.Context, userID, targetID int64) error {
|
|
if !s.ready() || userID <= 0 {
|
|
return errs.ErrUnauthorized
|
|
}
|
|
if targetID <= 0 {
|
|
return errs.ErrInvalidArgument
|
|
}
|
|
if entity.SameUser(userID, targetID) {
|
|
return errs.ErrInvalidArgument.WithMsg(i18n.T(reqctx.Lang(ctx), i18n.KeyFriendSelf, nil))
|
|
}
|
|
if _, err := s.activeUser(ctx, targetID); err != nil {
|
|
return err
|
|
}
|
|
return s.repo.CreateBlock(ctx, &entity.Block{UserID: userID, BlockedID: targetID, CreatedAt: time.Now()})
|
|
}
|
|
|
|
func (s *Service) Unblock(ctx context.Context, userID, targetID int64) error {
|
|
if !s.ready() || userID <= 0 {
|
|
return errs.ErrUnauthorized
|
|
}
|
|
if targetID <= 0 {
|
|
return errs.ErrInvalidArgument
|
|
}
|
|
return s.repo.DeleteBlock(ctx, userID, targetID)
|
|
}
|
|
|
|
func (s *Service) Delete(ctx context.Context, userID, friendID int64) error {
|
|
if !s.ready() || userID <= 0 {
|
|
return errs.ErrUnauthorized
|
|
}
|
|
if friendID <= 0 {
|
|
return errs.ErrInvalidArgument
|
|
}
|
|
if err := s.repo.DeleteFriend(ctx, userID, friendID); err != nil {
|
|
if errors.Is(err, errs.ErrNotFound) {
|
|
return errs.ErrNotFound.WithMsg(i18n.T(reqctx.Lang(ctx), i18n.KeyFriendNotFriend, nil))
|
|
}
|
|
return err
|
|
}
|
|
return nil
|
|
}
|