domain

package
v0.0.0-...-23502e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeedLikeEvent   string = "feed-like"
	FeedPostEvent   string = "feed-post"
	FeedFollowEvent string = "feed-follow"

	THRESHOLD int = 1000 // 读写扩散阈值
)
View Source
const (
	FileTypeUnknown = "unknown"
	FileTypeImage   = "image"
)
View Source
const (
	FileSourceKnown = "unknown"
	FileSourceLocal = "local"
)
View Source
const (
	PostTopNKey = "post_topN"

	PostStatusHide    string = "hide"
	PostStatusPublish string = "publish"
)
View Source
const (
	Follow   = true
	UnFollow = false
)
View Source
const (
	ESPostIndex    = "post_index"
	ESUserIndex    = "user_index"
	ESCommentIndex = "comment_index"
)
View Source
const (
	DefaultPage = 0
	DefaultSize = 10
)
View Source
const (
	XUserID       = "x-user-id"
	UserSessionID = "user-session-id"
)
View Source
const (
	BizPost = "post"
)

Variables

This section is empty.

Functions

func UserLogoutKey

func UserLogoutKey(ssid string) string

Types

type BasePageRequest

type BasePageRequest struct {
	Page int `json:"page" form:"page"`
	Size int `json:"size" form:"size"`
}

type Comment

type Comment struct {
	Model
	CommentID int64 `gorm:"primaryKey"`
	UserID    int64

	Biz   string `gorm:"index:idx_biz_biz_id" binding:"required" json:"biz"`
	BizID int64  `gorm:"index:idx_biz_biz_id" binding:"required" json:"biz_id"`

	RootID        sql.NullInt64 `json:"root_id" gorm:"index"`
	ParentID      sql.NullInt64 `json:"parent_id" gorm:"index"`
	ParentComment *Comment      `json:"parent_comment" gorm:"foreignKey:ParentID;AssociationForeignKey:CommentID;constraint:OnDelete:CASCADE"` // 简化删除操作
	Content       string        `json:"content" binding:"required"`
}

func (Comment) TableName

func (Comment) TableName() string

type CommentCreateRequest

type CommentCreateRequest struct {
	Biz      string `json:"biz" binding:"required"`
	BizID    int64  `json:"biz_id" binding:"required"`
	RootID   int64  `json:"root_id"`
	ParentID int64  `json:"parent_id"`
	Content  string `json:"content" binding:"required"`
}

type CommentListRequest

type CommentListRequest struct {
	Biz   string `json:"biz" form:"biz"`
	BizID int64  `json:"biz_id" form:"biz_id"`
	MinID int64  `json:"min_id" form:"min_id"`
	Limit int    `json:"limit" form:"limit"`
}

type CommentRepository

type CommentRepository interface {
	Create(c context.Context, comment Comment) error
	Delete(c context.Context, id int64) error                                                // 删除本节点和其对应的子节点
	FindTop(c context.Context, biz string, bizID, minID int64, limit int) ([]Comment, error) // 查找一级评论
}

type CommentUsecase

type CommentUsecase interface {
	Create(c context.Context, comment Comment) error
	Delete(c context.Context, id int64) error
	FindTop(c context.Context, biz string, bizID, minID int64, limit int) ([]Comment, error)
}

type CreateTagBizRequest

type CreateTagBizRequest struct {
	Biz    string  `json:"biz" form:"biz" binding:"required"`
	BizID  int64   `json:"biz_id" form:"biz_id" binding:"required"`
	TagIDs []int64 `json:"tag_ids" form:"tag_ids" binding:"required"`
}

type ESSearch

type ESSearch interface {
	Search()
}

type ESSync

type ESSync interface {
	InputAny(ctx context.Context, item interface{}) error

	InputUser(ctx context.Context, item User) error
	InputPost(ctx context.Context, item Post) error
}

type Feed

type Feed struct {
	Model
	UserID    int64
	Type      string
	Content   FeedContent
	CreatedAt time.Time
}

type FeedContent

type FeedContent map[string]string

type FeedHandler

type FeedHandler interface {
	CreateFeedEvent(c context.Context, t string, content FeedContent) error
	FindFeedEvent(c context.Context, userID, timestamp, limit int64) ([]Feed, error)
}

FeedHandler 具体业务的处理逻辑 按照 type 类型来分,因为 type 天然的标记业务

type FeedPull

type FeedPull struct {
	Model
	UserID    int64 `gorm:"index;not null"` // 发件人
	Type      string
	Content   string
	CreatedAt int64 `gorm:"index"`
}

FeedPull 拉模型 - 读扩散

func (FeedPull) TableName

func (FeedPull) TableName() string

type FeedPush

type FeedPush struct {
	Model
	UserID    int64  `gorm:"index;not null"` // 收件人
	Type      string // 标记事件类型 决定Content解读方式
	Content   string
	CreatedAt int64 `gorm:"index"`
}

FeedPush 推模型 - 写扩散 - 收件箱

func (FeedPush) TableName

func (FeedPush) TableName() string

type FeedRepository

type FeedRepository interface {
	CreatePush(c context.Context, feed ...Feed) error
	CreatePull(c context.Context, feed ...Feed) error
	// FindPull Get from other outbox
	FindPull(c context.Context, userIDs []int64, timestamp, limit int64) ([]Feed, error)
	// FindPush Get from inbox
	FindPush(c context.Context, userID, timestamp, limit int64) ([]Feed, error)

	FindPullWithType(c context.Context, event string, userIDs []int64, timestamp, limit int64) ([]Feed, error)
	FindPushWithType(c context.Context, event string, userID, timestamp, limit int64) ([]Feed, error)
}

type FeedUsecase

type FeedUsecase interface {
	CreateFeedEvent(c context.Context, feed Feed) error
	GetFeedEventList(c context.Context, userID, timestamp, limit int64) ([]Feed, error)
}

FeedUsecase 处理业务公共部分 并且负责找出 Handler 来处理业务的个性部分

type File

type File struct {
	Model
	FileID int64 `gorm:"primaryKey"`
	Name   string
	Path   string
	Type   string
	Source string
	Hash   string `gorm:"unique"`
}

func (File) TableName

func (File) TableName() string

type FileListRequest

type FileListRequest struct {
	BasePageRequest
	Type   string `json:"type" from:"type"`
	Source string `json:"source" from:"source"`
}

type FileRepository

type FileRepository interface {
	Upload(c context.Context, file File) error
	Uploads(c context.Context, files []File) error
	FileList(c context.Context, fileType, fileSource string, page, size int) ([]File, int, error)
	FindByHash(c context.Context, hash string) (File, error)
}

type FileUploadsResponse

type FileUploadsResponse struct {
	Data map[string]interface{} `json:"data"` // 文件上传状态
}

type FileUsecase

type FileUsecase interface {
	Upload(c context.Context, file *multipart.FileHeader) (File, error) // 文件上传
	Uploads(c context.Context, files []*multipart.FileHeader) (FileUploadsResponse, error)
	FileList(c context.Context, fileType, fileSource string, page, size int) ([]File, int, error)
}

type GetTagsByBizRequest

type GetTagsByBizRequest struct {
	Biz   string `json:"biz" form:"biz" binding:"required"`
	BizID int64  `json:"biz_id" form:"biz_id" binding:"required"`
}

type Interaction

type Interaction struct {
	Model
	// idx_biz select * from . where biz ==
	// idx_bizID_biz 联合索引 (bizID区分度高)
	BizID int64 `gorm:"uniqueIndex:idx_interaction_bizID_biz"`
	//Biz   string `gorm:"uniqueIndex:idx_interaction_bizID_biz"`
	Biz        string `gorm:"type:varchar(255);uniqueIndex:idx_bizID_biz"` // MYSQL 写法
	ReadCnt    int
	LikeCnt    int
	CollectCnt int // 3个cnt 相比较 type+cnt 在读性能友好, 每次只需要读一行
}

func (Interaction) TableName

func (Interaction) TableName() string

type InteractionRepository

type InteractionRepository interface {
	IncrReadCount(c context.Context, biz string, id int64) error
	BatchIncrReadCount(c context.Context, biz []string, id []int64) error
	Like(c context.Context, biz string, bizID, userID int64) error
	CancelLike(c context.Context, biz string, bizID, userID int64) error
	Stat(c context.Context, biz string, bizID, userID int64) (Interaction, UserInteractionStat, error)
	Collect(c context.Context, biz string, bizID, userID, collectionID int64) error
	CancelCollect(c context.Context, biz string, bizID, userID, collectionID int64) error
	GetByIDs(c context.Context, biz string, id []int64) (map[int64]Interaction, error)
}

type InteractionUseCase

type InteractionUseCase interface {
	IncrReadCount(c context.Context, biz string, id int64) error
	Like(c context.Context, biz string, bizID, userID int64) error
	CancelLike(c context.Context, biz string, bizID, userID int64) error
	Info(c context.Context, biz string, bizID, userID int64) (Interaction, UserInteractionStat, error)
	Collect(c context.Context, biz string, bizID, userID, collectionID int64) error
	CancelCollect(c context.Context, biz string, bizID, userID, collectionID int64) error
}

type JwtCustomClaims

type JwtCustomClaims struct {
	Name string `json:"name"`
	ID   int64  `json:"id"`
	SSID string `json:"ssid"`
	jwt.RegisteredClaims
}

type JwtCustomRefreshClaims

type JwtCustomRefreshClaims struct {
	ID   int64  `json:"id"`
	SSID string `json:"ssid"`
	jwt.RegisteredClaims
}

type LoginRequest

type LoginRequest struct {
	Email    string `form:"email" binding:"required,email"`
	Password string `form:"password" binding:"required"`
}

type LoginResponse

type LoginResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type LoginUsecase

type LoginUsecase interface {
	GetUserByEmail(c context.Context, email string) (User, error)
	CreateAccessToken(user User, ssid string, secret string, expiry int) (accessToken string, err error)
	CreateRefreshToken(user User, ssid string, secret string, expiry int) (refreshToken string, err error)
}

type Model

type Model struct {
	ID        uint `gorm:"primarykey" json:"-"`
	CreatedAt int64
	UpdatedAt int64
}

type Post

type Post struct {
	Model
	PostID int64 `json:"post_id,string" gorm:"primaryKey"`

	Title    string `json:"title" form:"title" binding:"required"`
	Abstract string `json:"abstract" form:"abstract" binding:"required"`
	Content  string `json:"content" form:"content" binding:"required"`
	AuthorID int64  `json:"author_id,string" form:"author_id"`
	Status   string `json:"status" form:"status" binding:"required"`
}

func (Post) TableName

func (Post) TableName() string

type PostListRequest

type PostListRequest struct {
	Page     int    `json:"page" form:"page"`
	Size     int    `json:"size" form:"size"`
	AuthorID int64  `json:"author_id" form:"author_id"`
	Status   string `json:"status" form:"status"`
}

type PostRepository

type PostRepository interface {
	Create(c context.Context, post Post) error
	GetByID(c context.Context, id int64) (Post, error)
	FindMany(c context.Context, filter interface{}) ([]Post, error) // Modify
	List(c context.Context, filter interface{}, page, size int) ([]Post, error)
	FindTopNPage(c context.Context, page, size int, begin time.Time) ([]Post, error)
	Count(c context.Context, filter interface{}) (int64, error)
}

type PostUsecase

type PostUsecase interface {
	Create(c context.Context, post Post) error
	List(c context.Context, filter interface{}, page, size int) ([]Post, int64, error)
	Info(c context.Context, postID int64) (Post, error)
	TopN(c context.Context) ([]Post, error)
}

type Profile

type Profile struct {
	UserName string    `json:"user_name"`
	NickName string    `json:"nick_name"`
	Email    string    `json:"email"`
	AboutMe  string    `json:"about_me"`
	Birthday time.Time `json:"birthday"`
}

type RankRepository

type RankRepository interface {
	ReplaceTopN(c context.Context, items []Post, expiration time.Duration) error
	GetTopN(c context.Context) ([]Post, error)
}

type RankUsecase

type RankUsecase interface {
	TopN(c context.Context) error
}

type RefreshTokenRequest

type RefreshTokenRequest struct {
	RefreshToken string `form:"refresh_token" binding:"required"`
}

type RefreshTokenResponse

type RefreshTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type RefreshTokenUsecase

type RefreshTokenUsecase interface {
	GetUserByID(c context.Context, id int64) (User, error)
	CreateAccessToken(user User, ssid string, secret string, expiry int) (accessToken string, err error)
	CreateRefreshToken(user User, ssid string, secret string, expiry int) (refreshToken string, err error)
	ExtractIDAndSSIDFromToken(requestToken string, secret string) (int64, string, error)
}

type Relation

type Relation struct {
	Model
	RelationID int64 `gorm:"primaryKey"`
	Followee   int64 `gorm:"not null;uniqueIndex:idx_followee_follower"` // Follower 关注了 Followee
	Follower   int64 `gorm:"not null;uniqueIndex:idx_followee_follower;index:idx_follower"`
	// 典型场景:某个人关注列表follower 某个人的粉丝列表followee 我都要
	Status bool // true 关注 false 取消关注
}

func (Relation) TableName

func (Relation) TableName() string

type RelationRepository

type RelationRepository interface {
	Follow(c context.Context, follower, followee int64) error
	CancelFollow(c context.Context, follower, followee int64) error
	GetFollower(c context.Context, follower int64, page, size int) ([]Relation, error) // 粉丝列表
	GetFollowee(c context.Context, follower int64, page, size int) ([]Relation, error) // 关注者列表
	Detail(c context.Context, follower, followee int64) (Relation, error)              // 关注状态
	FollowerCnt(c context.Context, userID int64) (int64, error)                        // 粉丝数
	FolloweeCnt(c context.Context, userID int64) (int64, error)                        // 关注数
}

type RelationStat

type RelationStat struct {
	UserID   int64 `gorm:"unique"`
	Follower int   // 粉丝数
	Followee int   // 关注数
}

type RelationUsecase

type RelationUsecase interface {
	Follow(c context.Context, follower, followee int64) error
	CancelFollow(c context.Context, follower, followee int64) error
	GetFollower(c context.Context, userID int64, page, size int) ([]User, int, error) // 粉丝列表
	GetFollowee(c context.Context, userID int64, page, size int) ([]User, int, error) // 关注者列表
	Detail(c context.Context, follower, followee int64) (Relation, error)             // 关注状态
	Stat(c context.Context, userID int64) (RelationStat, error)
}

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Error   string      `json:"error"`
}

func ErrorResp

func ErrorResp(msg string, err error) Response

func SuccessResp

func SuccessResp(data interface{}) Response

type SearchRepository

type SearchRepository interface {
	SearchUser(ctx context.Context, keywords ...string) ([]User, error)
	SearchPost(ctx context.Context, userID int64, keywords ...string) ([]Post, error)
}

type SearchResult

type SearchResult struct {
	Users []User
	Posts []Post
}

type SearchUsecase

type SearchUsecase interface {
	Search(ctx context.Context, userID int64, cmd string) error // 用户画像和表达式
}

type SignupRequest

type SignupRequest struct {
	UserName string `form:"user_name" binding:"required"`
	Email    string `form:"email" binding:"required,email"`
	Password string `form:"password" binding:"required"`
}

type SignupResponse

type SignupResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type SignupUsecase

type SignupUsecase interface {
	Create(c context.Context, user User) error
	GetUserByEmail(c context.Context, email string) (User, error)
}

type Tag

type Tag struct {
	Model
	TagID   int64 `gorm:"primaryKey"`
	UserID  int64 `gorm:"index"`
	TagName string
}

func (Tag) TableName

func (Tag) TableName() string

type TagBiz

type TagBiz struct {
	Model
	Biz    string `gorm:"index:idx_tagBiz_biz_bizId"`
	BizID  int64  `gorm:"index:idx_tagBiz_biz_bizId"`
	UserID int64  `gorm:"index"`
	TagID  int64  `gorm:"index"`
}

SELECT * FROM tag_biz WHERE biz = ? and biz_id = ?

func (TagBiz) TableName

func (TagBiz) TableName() string

type TagRepository

type TagRepository interface {
	CreateTag(c context.Context, tag Tag) error                                                  // 用户创建Tag
	CreateTagBiz(c context.Context, userID int64, biz string, bizID int64, tagIDs []int64) error // 用户为某个资源加Tag
	GetTagsByUserID(c context.Context, userID int64) ([]Tag, error)                              // 查询用户所有Tag
	GetTagsByBiz(c context.Context, userID int64, biz string, bizID int64) ([]Tag, error)        // 查询用户在某个资源上打的的Tag
}

type TagUsecase

type TagUsecase interface {
	CreateTag(c context.Context, tag Tag) error
	CreateTagBiz(c context.Context, userID int64, biz string, bizID int64, tagIDs []int64) error
	GetTagsByUserID(c context.Context, userID int64) ([]Tag, error)
	GetTagsByBiz(c context.Context, userID int64, biz string, bizID int64) ([]Tag, error)
}

type Task

type Task struct {
	Model
	TaskID int64  `json:"task_id"`
	Title  string `json:"title" form:"title"`
	UserID int64  `json:"user_id" form:"user_id"`
}

func (Task) TableName

func (Task) TableName() string

type TaskRepository

type TaskRepository interface {
	Create(c context.Context, task Task) error
	Delete(c context.Context, taskID int64) error
}

type TaskUsecase

type TaskUsecase interface {
	Create(c context.Context, task Task) error
	Delete(c context.Context, taskID int64) error
}

type User

type User struct {
	Model
	UserID   int64     `json:"user_id" gorm:"primaryKey"`
	UserName string    `json:"user_name" gorm:"unique"`
	NickName string    `json:"nick_name"`
	Email    string    `json:"email" gorm:"unique"`
	Password string    `json:"-" gorm:"size:256"`
	AboutMe  string    `json:"about_me"`
	Birthday time.Time `json:"birthday" gorm:"default:null"`
	Phone    string    `json:"phone"`
	Region   string    `json:"region" gorm:"default:null"`
}

func (User) TableName

func (User) TableName() string

type UserCollect

type UserCollect struct {
	Model
	UserID       int64  `gorm:"uniqueIndex:idx_userCollect_userID_bizID_biz"`
	BizID        int64  `gorm:"uniqueIndex:idx_userCollect_userID_bizID_biz"`
	Biz          string `gorm:"type:varchar(255);uniqueIndex:idx_userCollect_userID_bizID_biz"`
	CollectionID int64  `gorm:"index"`
	Status       bool
}

func (UserCollect) TableName

func (UserCollect) TableName() string

type UserInteractionStat

type UserInteractionStat struct {
	Liked     bool
	Collected bool
}

type UserLike

type UserLike struct {
	Model
	UserID int64  `gorm:"uniqueIndex:idx_userLike_userID_bizID_biz"`
	BizID  int64  `gorm:"uniqueIndex:idx_userLike_userID_bizID_biz"`
	Biz    string `gorm:"type:varchar(255);uniqueIndex:idx_userLike_userID_bizID_biz"`
	Status bool   // true 点赞 false 取消点赞

}

func (UserLike) TableName

func (UserLike) TableName() string

type UserRepository

type UserRepository interface {
	Create(c context.Context, user User) error
	GetByEmail(c context.Context, email string) (User, error)
	GetByID(c context.Context, id int64) (User, error)
	//UpsertAvatar(c context.Context, avatar string) error
	FindByUserIDs(c context.Context, userIDs []int64, page, size int) ([]User, error)
	InvalidToken(c context.Context, ssid string, exp time.Duration) error
	Update(c context.Context, id int64, user User) error
}

type UserUsecase

type UserUsecase interface {
	GetProfileByID(c context.Context, userID int64) (*Profile, error)
	UpdateProfile(c context.Context, userID int64, user User) error
	Logout(c context.Context, SSID string, tokenExpiry time.Duration) error
}

Directories

Path Synopsis
Package domain_mock is a generated GoMock package.
Package domain_mock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL