service

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: MIT Imports: 17 Imported by: 0

README

service

  • 业务逻辑层,处于 handler 层和 repository 层之间
  • service 只能通过 repository 层获取数据
  • 面向接口编程
  • 依赖接口,不要依赖实现
  • 如果有事务处理,在这一层进行处理
  • 如果是调用的第三方服务,请不要加 cache, 避免缓存不一致(对方更新数据,这边无法知晓)
  • 由于 service 会被 httprpc 调用,默认会提供 http 调用的,比如:GetUserInfo(), 如果 rpc 需要调用,可以对 GetUserInfo() 进行一层封装, 比如:GetUser()

Reference

Documentation

Index

Constants

View Source
const (
	// FollowStatusNormal 关注状态-正常
	FollowStatusNormal int = 1 // 正常
	// FollowStatusDelete 关注状态-删除
	FollowStatusDelete = 0 // 删除
)
View Source
const (
	// DefaultLimit 默认分页数
	DefaultLimit = 50

	// MaxID 最大id
	MaxID = 0xffffffffffff

	// DefaultAvatar 默认头像 key
	DefaultAvatar = "default_avatar.png"
)

Variables

This section is empty.

Functions

func TransferUser added in v1.3.1

func TransferUser(input *TransferUserInput) *model.UserInfo

TransferUser 组装数据并输出 对外暴露的user结构,都应该经过此结构进行转换

Types

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service struct

var (
	UserSvc  *Service
	VCodeSvc *Service
)

func New

func New(c *conf.Config) (s *Service)

New init service

func (*Service) BatchGetUsers added in v1.3.1

func (s *Service) BatchGetUsers(ctx context.Context, userID uint64, userIDs []uint64) ([]*model.UserInfo, error)

BatchGetUsers 批量获取用户信息 1. 处理关注和被关注状态 2. 获取关注和粉丝数据

func (*Service) CheckLoginVCode added in v1.3.1

func (s *Service) CheckLoginVCode(phone int64, vCode int) bool

CheckLoginVCode 验证校验码是否正确

func (*Service) Close

func (s *Service) Close()

Close service

func (*Service) EmailLogin added in v1.3.1

func (s *Service) EmailLogin(ctx context.Context, email, password string) (tokenStr string, err error)

EmailLogin 邮箱登录

func (*Service) Follow added in v1.3.1

func (s *Service) Follow(ctx context.Context, userID uint64, followedUID uint64) error

Follow 关注目标用户

func (*Service) GenLoginVCode added in v1.3.1

func (s *Service) GenLoginVCode(phone string) (int, error)

GenLoginVCode 生成校验码

func (*Service) GetFollowerUserList added in v1.3.1

func (s *Service) GetFollowerUserList(ctx context.Context, userID uint64, lastID uint64, limit int) ([]*model.UserFansModel, error)

GetFollowerUserList 获取粉丝用户列表

func (*Service) GetFollowingUserList added in v1.3.1

func (s *Service) GetFollowingUserList(ctx context.Context, userID uint64, lastID uint64, limit int) ([]*model.UserFollowModel, error)

GetFollowingUserList 获取正在关注的用户列表

func (*Service) GetLoginVCode added in v1.3.1

func (s *Service) GetLoginVCode(phone int64) (int, error)

GetLoginVCode 获得校验码

func (*Service) GetUserByEmail added in v1.3.1

func (s *Service) GetUserByEmail(ctx context.Context, email string) (*model.UserBaseModel, error)

func (*Service) GetUserByID added in v1.3.1

func (s *Service) GetUserByID(ctx context.Context, id uint64) (*model.UserBaseModel, error)

GetUserByID 获取单条用户信息

func (*Service) GetUserByPhone added in v1.3.1

func (s *Service) GetUserByPhone(ctx context.Context, phone int64) (*model.UserBaseModel, error)

func (*Service) GetUserInfoByID added in v1.3.1

func (s *Service) GetUserInfoByID(ctx context.Context, id uint64) (*model.UserInfo, error)

GetUserInfoByID 获取组装好的用户数据

func (*Service) IsFollowing added in v1.3.1

func (s *Service) IsFollowing(ctx context.Context, userID uint64, followedUID uint64) bool

IsFollowing 是否正在关注某用户

func (*Service) LoginByPhone added in v1.3.1

func (s *Service) LoginByPhone(ctx context.Context, req *v1.PhoneLoginRequest) (reply *v1.PhoneLoginReply, err error)

LoginByPhone phone login, grpc wrapper

func (*Service) PhoneLogin added in v1.3.1

func (s *Service) PhoneLogin(ctx context.Context, phone int64, verifyCode int) (tokenStr string, err error)

PhoneLogin 邮箱登录

func (*Service) Ping

func (s *Service) Ping() error

Ping service

func (*Service) Register added in v1.3.1

func (s *Service) Register(ctx context.Context, username, email, password string) error

Register 注册用户

func (*Service) SendSMS added in v1.3.1

func (s *Service) SendSMS(phoneNumber string, verifyCode int) error

Send 发送短信

func (*Service) Unfollow added in v1.3.1

func (s *Service) Unfollow(ctx context.Context, userID uint64, followedUID uint64) error

Unfollow 取消用户关注

func (*Service) UpdateUser added in v1.3.1

func (s *Service) UpdateUser(ctx context.Context, id uint64, userMap map[string]interface{}) error

UpdateUser update user info

type TransferUserInput added in v1.3.1

type TransferUserInput struct {
	CurUser  *model.UserBaseModel
	User     *model.UserBaseModel
	UserStat *model.UserStatModel
	IsFollow int `json:"is_follow"`
	IsFans   int `json:"is_fans"`
}

TransferUserInput 转换输入字段

Jump to

Keyboard shortcuts

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