spark-server/internal/module/user/logic/service.go
zhr ae9a71034d feat: implement Spark IM V3 modular monolith
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>
2026-09-17 19:52:11 +08:00

48 lines
1.7 KiB
Go

// Package logic is the user application use-case layer, split by function (profile, login, email code).
package logic
import (
"context"
"time"
"spark-server/internal/module/user/entity"
)
// Repository is user persistence. Model implements it; do not split this by table.
type Repository interface {
GetByID(ctx context.Context, id int64) (*entity.User, error)
GetByEmail(ctx context.Context, email string) (*entity.User, error)
GetBySparkID(ctx context.Context, sparkID string) (*entity.User, error)
GetByQRCode(ctx context.Context, qrcode string) (*entity.User, error)
CreateWithEmail(ctx context.Context, u *entity.User, email string) error
UpdateSparkID(ctx context.Context, userID int64, sparkID string) error
UpdateQRCode(ctx context.Context, userID int64, qrcode string) error
UpdateProfile(ctx context.Context, u *entity.User) error
TouchLogin(ctx context.Context, userID int64, at time.Time) error
UpsertDevice(ctx context.Context, d *entity.Device) error
GetDevice(ctx context.Context, userID int64, deviceID uint64) (*entity.Device, error)
InsertLoginLog(ctx context.Context, log *entity.LoginLog) error
}
// IDGen issues time-ordered Snowflake IDs (user PK).
type IDGen interface {
NextID() (int64, error)
}
// Objects stores the generated default avatar. Nil or Put error keeps an SVG data-URI fallback.
type Objects interface {
Put(ctx context.Context, key string, body []byte, contentType string) error
}
// Service is the user application use-case (HTTP and TCP share it).
type Service struct {
repo Repository
codes CodeStore
ids IDGen
objects Objects
}
func NewService(repo Repository, codes CodeStore, ids IDGen, objects Objects) *Service {
return &Service{repo: repo, codes: codes, ids: ids, objects: objects}
}