54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
conventity "spark-server/internal/module/conversation/entity"
|
|
"spark-server/internal/module/favorite/entity"
|
|
msgentity "spark-server/internal/module/message/entity"
|
|
)
|
|
|
|
// Repository persists favorites. Model implements it.
|
|
type Repository interface {
|
|
Get(ctx context.Context, id int64) (*entity.Favorite, error)
|
|
GetByUserMsg(ctx context.Context, userID, msgID int64) (*entity.Favorite, error)
|
|
Create(ctx context.Context, fav *entity.Favorite) error
|
|
ListByUser(ctx context.Context, userID int64, limit int) ([]*entity.Favorite, error)
|
|
Delete(ctx context.Context, userID, id int64) error
|
|
ListAllByUser(ctx context.Context, userID int64) ([]*entity.Favorite, error)
|
|
}
|
|
|
|
type Messages interface {
|
|
GetByID(ctx context.Context, id int64) (*msgentity.Message, error)
|
|
}
|
|
|
|
type Members interface {
|
|
GetMember(ctx context.Context, conversationID, userID int64) (*conventity.Member, error)
|
|
}
|
|
|
|
type Objects interface {
|
|
Copy(ctx context.Context, src, dst string) error
|
|
Delete(ctx context.Context, key string) error
|
|
}
|
|
|
|
type IDGen interface {
|
|
NextID() (int64, error)
|
|
}
|
|
|
|
// Service is the favorite use-case layer (HTTP and TCP share it).
|
|
type Service struct {
|
|
repo Repository
|
|
msgs Messages
|
|
members Members
|
|
objects Objects
|
|
ids IDGen
|
|
}
|
|
|
|
func NewService(repo Repository, msgs Messages, members Members, objects Objects, ids IDGen) *Service {
|
|
return &Service{repo: repo, msgs: msgs, members: members, objects: objects, ids: ids}
|
|
}
|
|
|
|
func (s *Service) ready() bool {
|
|
return s != nil && s.repo != nil && s.msgs != nil && s.members != nil && s.ids != nil
|
|
}
|