service

package
v0.0.0-...-bf4de7e Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterAMQP

func RegisterAMQP(i IAMQP)

func RegisterBizCtx

func RegisterBizCtx(i IBizCtx)

func RegisterCache

func RegisterCache(i ICache)

func RegisterHitokoto

func RegisterHitokoto(i IHitokoto)

func RegisterJob

func RegisterJob(i IJob)

func RegisterMiddleware

func RegisterMiddleware(i IMiddleware)

func RegisterNotification

func RegisterNotification(i INotification)

func RegisterPoll

func RegisterPoll(i IPoll)

func RegisterPollMarks

func RegisterPollMarks(i IPollMarks)

func RegisterSearch

func RegisterSearch(i ISearch)

func RegisterUser

func RegisterUser(i IUser)

Types

type IAMQP

type IAMQP interface {
	GetConnectionController() (amqp.ConnectionController, error)
}

func AMQP

func AMQP() IAMQP

type IBizCtx

type IBizCtx interface {
	// Init initializes and injects custom business context object into request context.
	Init(r *ghttp.Request, customCtx *model.Context)
	// Get retrieves and returns the user object from context.
	// It returns nil if nothing found in given context.
	Get(ctx context.Context) *model.Context
	// SetUser injects business user object into context.
	SetUser(ctx context.Context, ctxUser *model.ContextUser)
	GetUser(ctx context.Context) *model.ContextUser
}

func BizCtx

func BizCtx() IBizCtx

type ICache

type ICache interface {
	RemovePrefix(ctx context.Context, prefix string) error
	RemovePrefixes(ctx context.Context, prefixes []string) error
	ClearCacheAfterHitokotoUpdated(ctx context.Context, uuids []string)
	ClearCacheAfterPollUpdated(ctx context.Context, userID, pollID uint, sentenceUUID string)
	ClearPollListCache(ctx context.Context)
	ClearPollUserCache(ctx context.Context, userID uint)
}

func Cache

func Cache() ICache

type IHitokoto

type IHitokoto interface {
	// ConvertPendingToSchemaV1 将 Pending 数据转换为 Schema V1
	ConvertPendingToSchemaV1(ctx context.Context, pending *entity.Pending) (*model.HitokotoV1WithPoll, error)
	// ConvertSentenceToSchemaV1 将 Sentence 数据转换为 Schema V1
	ConvertSentenceToSchemaV1(ctx context.Context, sentence *entity.Sentence) (*model.HitokotoV1WithPoll, error)
	// ConvertRefuseToSchemaV1 将 Refuse 数据转换为 Schema V1
	ConvertRefuseToSchemaV1(ctx context.Context, refuse *entity.Refuse) (*model.HitokotoV1WithPoll, error)
	ConvertStatusToPollStatus(status consts.HitokotoStatus) consts.PollStatus
	GetHitokotoV1SchemaByUUID(ctx context.Context, uuid string) (*model.HitokotoV1WithPoll, error)
	// GetList 获取句子列表
	//
	//nolint:gocyclo
	GetList(ctx context.Context, in *model.GetHitokotoV1SchemaListInput) (*model.GetHitokotoV1SchemaListOutput, error)
	// Move 移动句子
	//
	//nolint:gocyclo
	Move(ctx context.Context, sentence *model.HitokotoV1WithPoll, target consts.HitokotoStatus) error
	// Delete 使用 UUIDs 删除句子
	Delete(ctx context.Context, uuids []string) error
	UpdateByUUID(ctx context.Context, sentence *model.HitokotoV1WithPoll, do g.Map) error
	GetPendingByUUID(ctx context.Context, uuid string) (hitokoto *entity.Pending, err error)
	TopPendingPollNotOpen(ctx context.Context) (hitokoto *entity.Pending, err error)
	CountPendingPollNotOpen(ctx context.Context) (count int, err error)
	GetRefuseByUUID(ctx context.Context, uuid string) (hitokoto *entity.Refuse, err error)
	GetSentenceByUUID(ctx context.Context, uuid string) (hitokoto *entity.Sentence, err error)
}

func Hitokoto

func Hitokoto() IHitokoto

type IJob

type IJob interface {
	Register(ctx context.Context) error
}

func Job

func Job() IJob

type IMiddleware

type IMiddleware interface {
	// AuthorizationV1 用于 v1 接口校验用户是否登录
	// 尝试顺序 Authorization: Bearer Token -> param -> form -> body -> query -> Router
	AuthorizationV1(r *ghttp.Request)
	// Ctx 用于注入业务上下文,实现单次请求中的业务数据共享
	Ctx(r *ghttp.Request)
	// GuardV1 是 v1 用于检查用户权限的中间件
	GuardV1(role consts.UserRole) func(r *ghttp.Request)
	CORS(r *ghttp.Request)
	// HandlerResponse 重写了默认的 JSON 响应格式,提供统一的响应格式
	HandlerResponse(r *ghttp.Request)
}

func Middleware

func Middleware() IMiddleware

type INotification

type INotification interface {
	PollCreatedNotification(ctx context.Context, poll *model.PollElement) error
	// DailyReportNotification 发送每日报告通知
	// 直接交给 Event 生产消息
	DailyReportNotification(ctx context.Context, rawData []model.DailyReportNotificationMessage) error
	PollFinishedNotification(ctx context.Context, poll *model.PollElement, pollLogs []entity.PollLog) error
	// SentenceReviewedNotification 发送句子审核通知
	SentenceReviewedNotification(ctx context.Context, poll *model.PollElement, reviewerUID uint, reviewerName string) error
	GetUserIDsShouldDoNotification(ctx context.Context, userIDs []uint, settingField string) ([]uint, error)
	GetUsersShouldDoNotification(ctx context.Context, settingField string) ([]entity.Users, error)
	IsUserShouldDoNotification(ctx context.Context, settingField string, userID uint) (bool, error)
}

func Notification

func Notification() INotification

type IPoll

type IPoll interface {
	GetPointsByRole(role consts.UserRole) consts.UserPollPoints
	ConvertPollLogToPollRecord(ctx context.Context, in *entity.PollLog, isAdmin bool) (out *model.PollRecord, err error)
	MustConvertPollLogToPollRecord(ctx context.Context, in *entity.PollLog, isAdmin bool) (out *model.PollRecord)
	GetPollByID(ctx context.Context, pid int) (poll *entity.Poll, err error)
	// GetPollBySentenceUUID 根据 Sentence UUID 获取最新发起的投票
	GetPollBySentenceUUID(ctx context.Context, sentenceUUID string) (poll *entity.Poll, err error)
	GetPollsBySentenceUUIDs(ctx context.Context, sentenceUUIDs []string) (polls []entity.Poll, err error)
	CountOpenedPoll(ctx context.Context) (int, error)
	CreatePollByPending(ctx context.Context, pending *entity.Pending) (*entity.Poll, error)
	//nolint:gocyclo
	GetPollList(ctx context.Context, in *model.GetPollListInput) (*model.GetPollListOutput, error)
	// Poll 投票
	Poll(ctx context.Context, in *model.PollInput) error
	CancelPollByID(ctx context.Context, in *model.CancelPollInput) error
	CountUserUnreviewedPoll(ctx context.Context, uid uint) (int, error)
	GetPollDetailByID(ctx context.Context, pollID uint, withPolledData bool) (*model.PollListElement, error)
	GetPollLogsBySentenceUUID(ctx context.Context, uuid string) ([]entity.PollLog, error)
	GetPollLogsByPollID(ctx context.Context, pid int) ([]entity.PollLog, error)
	// GetPollMarksByPollID 获取指定投票的标签列表(不带用户信息)
	GetPollMarksByPollID(ctx context.Context, pid uint) ([]int, error)
	GetPollMarksByPollIDAndUserID(ctx context.Context, pid, userID int) ([]int, error)
	GetRulingThreshold(isExpandedPoll bool, totalTickets int) int
	// DoRuling 处理投票
	//
	//nolint:gocyclo
	DoRuling(ctx context.Context, poll *entity.Poll, target consts.PollStatus) error
}

func Poll

func Poll() IPoll

type IPollMarks

type IPollMarks interface {
	List(ctx context.Context) ([]entity.PollMark, error)
	GetByID(ctx context.Context, id int) (*entity.PollMark, error)
	Update(ctx context.Context, mark *entity.PollMark) error
	Add(ctx context.Context, mark *do.PollMark) error
}

func PollMarks

func PollMarks() IPollMarks

type ISearch

type ISearch interface {
	AddSentenceToSearch(ctx context.Context, schema *entity.Pending) error
}
func Search() ISearch

type IUser

type IUser interface {
	GetRoleByUser(ctx context.Context, user *entity.Users) (role consts.UserRole, err error)
	MustGetRoleByUser(ctx context.Context, user *entity.Users) (role consts.UserRole)
	GetUserStatusByUser(ctx context.Context, user *entity.Users) (status consts.UserStatus, err error)
	MustGetUserStatusByUser(ctx context.Context, user *entity.Users) (status consts.UserStatus)
	GetUserPollPointsByUserRole(role consts.UserRole) (points consts.UserPollPoints)
	GetUserRoleCodeByUserRole(role consts.UserRole) (code consts.UserRoleCode)
	GetUserPollLogs(ctx context.Context, in model.GetUserPollLogsInput) (*model.GetUserPollLogsOutput, error)
	GetUserPollLogsWithSentence(ctx context.Context, in model.GetUserPollLogsInput) (*model.GetUserPollLogsWithSentenceOutput, error)
	// GetUserPollLogsCount 获取用户投票记录数量
	GetUserPollLogsCount(ctx context.Context, userID uint) (int, error)
	GetUserPollLogsWithPollResult(ctx context.Context, in model.GetUserPollLogsInput) (*model.GetUserPollLogsWithPollResultOutput, error)
	GetUserPolledDataWithPollID(ctx context.Context, userID, pid uint) (*model.PolledData, error)
	// GetReviewersAndAdmins 获取所有需要发送通知的用户
	// 目前只是一次性获取管理员和审核员
	GetReviewersAndAdmins(ctx context.Context) (users []entity.Users, err error)
	// VerifyAPIV1Token 用于 v1 接口校验用户是否登录
	// TODO: v2 中会使用新的用户系统,并且将会使用带有 ACL、签名的授权机制。目前的 token 机制会被废弃。
	VerifyAPIV1Token(ctx context.Context, token string) (flag bool, err error)
	GetUserByToken(ctx context.Context, token string) (user *entity.Users, err error)
	GetUserByID(ctx context.Context, id uint) (user *entity.Users, err error)
	SetUserRoleReviewer(ctx context.Context, userID uint) error
	GetPollUserByUserID(ctx context.Context, uid uint) (user *entity.PollUsers, err error)
	CreatePollUser(ctx context.Context, uid uint) (err error)
	IncreaseUserPollScore(ctx context.Context, in *model.UserPollScoreInput) error
	DecreaseUserPollScore(ctx context.Context, in *model.UserPollScoreInput) error
	CountUserScoreRecords(ctx context.Context, userID uint) (int, error)
	GetUserScoreRecords(ctx context.Context, in *model.GetUserScoreRecordsInput) (*model.GetUserScoreRecordsOutput, error)
}

func User

func User() IUser

Jump to

Keyboard shortcuts

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