domain

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodePurposeLogin
	CodePurposeBindTel
)
View Source
const (
	CodeStateSent
	CodeStateUsed
)
View Source
const DefaultNationCode = "0086"
View Source
const (
	UnionidDtWechat
)

Variables

View Source
var (
	// ErrInternalServerError will throw if any the Internal Server Error happen
	ErrInternalServerError = errors.New("internal Server Error")
	// ErrNotFound will throw if the requested item is not exists
	ErrNotFound = errors.New("your requested Item is not found")
	// ErrConflict will throw if the current action already exists
	ErrConflict = errors.New("your Item already exist")
	// ErrBadParamInput will throw if the given request-body or params is not valid
	ErrBadParamInput = errors.New("given Param is not valid")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID         int    `gorm:"column:id;primaryKey"`
	Openid     string `gorm:"column:openid"`
	PlatformId int    `gorm:"column:platform_id"`
	UserId     int    `gorm:"column:user_id"`
	CreatedAt  int64  `gorm:"column:created_at"`
	UpdatedAt  int64  `gorm:"column:updated_at"`
	DeletedAt  int64  `gorm:"column:deleted_at"`
}

func NewAccount

func NewAccount(openid string, platformId int) *Account

func (*Account) SetUserID

func (a *Account) SetUserID(id int)

func (*Account) TableName

func (*Account) TableName() string

type AccountBindTelCodeReq

type AccountBindTelCodeReq struct {
	Tel        string `json:"tel" binding:"required"`
	NationCode string `json:"nationCode"`
}

type AccountBindTelReq

type AccountBindTelReq struct {
	Tel        string `json:"tel" binding:"required"`
	Code       string `json:"code" binding:"required"`
	NationCode string `json:"nationCode"`
}

type AccountBindWechatReq

type AccountBindWechatReq struct {
	Code string `json:"string"`
}

type AccountCheckSwitchCodeReq

type AccountCheckSwitchCodeReq struct {
}

type AccountInfoResp

type AccountInfoResp struct {
	Tel         string `json:"tel"`
	WechatBound bool   `json:"wechatBound"`
}

type AccountSwitchTargetCodeReq

type AccountSwitchTargetCodeReq struct {
}

type AccountSwitchTelCodeReq

type AccountSwitchTelCodeReq struct {
}

type AccountSwitchTelReq

type AccountSwitchTelReq struct {
}

type AccountUnBindWechatReq

type AccountUnBindWechatReq struct {
}

type Article

type Article struct {
	ID        int64     `json:"id"`
	Title     string    `json:"title" validate:"required"`
	Content   string    `json:"content" validate:"required"`
	Author    Author    `json:"author"`
	UpdatedAt time.Time `json:"updated_at"`
	CreatedAt time.Time `json:"created_at"`
}

Article is representing the Article data struct

type ArticleRepository

type ArticleRepository interface {
	Fetch(ctx context.Context, cursor string, num int64) (res []Article, nextCursor string, err error)
	GetByID(ctx context.Context, id int64) (Article, error)
	GetByTitle(ctx context.Context, title string) (Article, error)
	Update(ctx context.Context, ar *Article) error
	Store(ctx context.Context, a *Article) error
	Delete(ctx context.Context, id int64) error
}

ArticleRepository represent the article's repository contract

type ArticleUsecase

type ArticleUsecase interface {
	Fetch(ctx context.Context, cursor string, num int64) ([]Article, string, error)
	GetByID(ctx context.Context, id int64) (Article, error)
	Update(ctx context.Context, ar *Article) error
	GetByTitle(ctx context.Context, title string) (Article, error)
	Store(context.Context, *Article) error
	Delete(ctx context.Context, id int64) error
}

ArticleUsecase represent the article's usecases

type AuthLoginReq

type AuthLoginReq struct {
	PlatformId int               `json:"platformId" binding:"required"`
	Data       map[string]string `json:"data" binding:"required"`
}

type AuthLoginResp

type AuthLoginResp struct {
	AccessToken string `json:"accessToken"`
	ExpiresAt   int64  `json:"expiresAt"`
}

type AuthSmsCodeReq

type AuthSmsCodeReq struct {
	NationCode string `json:"nationCode"`
	Tel        string `json:"tel" binding:"required"`
}

type Author

type Author struct {
	ID        int64  `json:"id"`
	Name      string `json:"name"`
	CreatedAt string `json:"created_at"`
	UpdatedAt string `json:"updated_at"`
}

Author representing the Author data struct

type AuthorRepository

type AuthorRepository interface {
	GetByID(ctx context.Context, id int64) (Author, error)
}

AuthorRepository represent the author's repository contract

type Code

type Code struct {
	ID         int    `gorm:"column:id;primaryKey"`
	Tel        string `gorm:"column:tel"`
	NationCode string `gorm:"column:nation_code"`
	Code       string `gorm:"column:code"`
	State      int    `gorm:"column:state"`
	Purpose    int    `gorm:"column:purpose"`
	CreatedAt  int64  `gorm:"column:created_at"`
	UpdateAt   int64  `gorm:"column:updated_at"`
	ExpiredAt  int64  `gorm:"column:expired_at"`
}

func NewSmsCode

func NewSmsCode(tel, nationCode string, purpose int) *Code

func (*Code) IsUsed

func (c *Code) IsUsed() bool

func (*Code) SetState

func (c *Code) SetState(state int)

func (*Code) TableName

func (*Code) TableName() string

type GithubAccessTokenResp

type GithubAccessTokenResp struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	Scope       string `json:"scope"`
}

type GithubErrResp

type GithubErrResp struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type GithubUserInfoResp

type GithubUserInfoResp struct {
	Openid     string `json:"openid"`
	Nickname   string `json:"nickname"`
	Sex        int    `json:"sex"`
	Province   string `json:"province"`
	City       string `json:"city"`
	Country    string `json:"country"`
	Headimgurl string `json:"headimgurl"`
	Privilege  string `json:"privilege"`
	Unionid    string `json:"unionid"`
}

type IAccessTokenRepository

type IAccessTokenRepository interface {
	GetAccessToken(ctx context.Context, token string) (int, error)
	SetAccessToken(ctx context.Context, token string, id int) error
	DelAccessToken(ctx context.Context, token string) error
}

type IAccountRepository

type IAccountRepository interface {
	GetOneByOpenid(ctx context.Context, openid string) (*Account, error)

	GetByUserID(ctx context.Context, userId int) ([]Account, error)
	DelByUserIdFromCache(ctx context.Context, userId int) error

	Save(ctx context.Context, account *Account, privateTet *PrivateTelInfo, privateInfo *PrivateInfo, profile *Profile, update func(account *Account)) error

	SaveSns(ctx context.Context, account *Account, profile *Profile, unionid *Unionid, update func(account *Account)) error

	DeleteFromCache(ctx context.Context, openid string) error
}

type IAccountUsecase

type IAccountUsecase interface {
	// Info 账户信息手机号、微信
	Info(ctx context.Context) (*AccountInfoResp, error)
	// BindTelCode 绑定手机号验证码
	BindTelCode(ctx context.Context, param *AccountBindTelCodeReq) error
	// BindTel 绑定手机号
	BindTel(ctx context.Context, param *AccountBindTelReq) error
	// BindWechat 绑定微信
	BindWechat(ctx context.Context, param *AccountBindWechatReq) error
}

type IAuthUsecase

type IAuthUsecase interface {
	// Login 登录
	Login(ctx context.Context, param *AuthLoginReq) (*AuthLoginResp, error)
	// SmsCode 发送短信验证码
	SmsCode(ctx context.Context, param *AuthSmsCodeReq) error
	// Logout 登出
	Logout(ctx context.Context) error
}

type ICodeRepository

type ICodeRepository interface {
	Save(ctx context.Context, code *Code) error
	GetByTelAndCode(ctx context.Context, tel, nationCode, code string, purpose int) (*Code, error)
	GetByTel(ctx context.Context, tel, nationCode string, purpose int) (*Code, error)
	Update(ctx context.Context, code *Code) error
}

type IGithubRepository

type IGithubRepository interface {
	GetAccessToken(code string) (*GithubAccessTokenResp, error)
	UserInfo(accessToken, openid string) (*GithubUserInfoResp, error)
}

type IPrivateInfoRepository

type IPrivateInfoRepository interface {
	GetOneByUserID(ctx context.Context, userID int) (*PrivateInfo, error)
	DetByUserIDFromCache(ctx context.Context, userID int) error
}

type IPrivateTelInfoRepository

type IPrivateTelInfoRepository interface {
	GetOneByHash(ctx context.Context, hash string) (*PrivateTelInfo, error)
	DelByHashFromCache(ctx context.Context, hash string) error
}

type IProfileRepository

type IProfileRepository interface {
	UpdateByID(ctx context.Context, id int, data map[string]interface{}) error
	GetOneByID(ctx context.Context, id int) (*Profile, error)
}

type IProviceUsecase

type IProviceUsecase interface {
	// SetHead 设置头像
	SetHead(ctx context.Context, fh *multipart.FileHeader) (*UserSetHeadResp, error)
	// SetNickname 设置昵称
	SetNickname(ctx context.Context, nickname string) error
	// SetSex 设置性别
	SetSex(ctx context.Context, sex int) error
	// SetCity 设置城市
	SetCity(ctx context.Context, req *UserSetCityReq) error
	// Profile 获取用户基本信息
	Profile(ctx context.Context) (*UserProfileResp, error)
	// SetSignature 设置签名
	SetSignature(ctx context.Context, signature string) error
	// SetHeight 设置身高
	SetHeight(ctx context.Context, height int) error
	// SetWeight 设置体重
	SetWeight(ctx context.Context, weight int) error
	// SetBirthday 设置生日
	SetBirthday(ctx context.Context, birthday string) error
}

type IUnionidRepository

type IUnionidRepository interface {
	GetOneByUnionIdAndType(ctx context.Context, unionid string, dt int) (*Unionid, error)
	DelByUnionIdAndTypeFromCache(ctx context.Context, unionid string, dt int) error
}

type IWechatRepository

type IWechatRepository interface {
	GetAccessToken(code string) (*WechatAccessTokenResp, error)
	UserInfo(accessToken, openid string) (*WechatUserInfoResp, error)
}

type PrivateInfo

type PrivateInfo struct {
	UserId       int    `gorm:"column:user_id;primaryKey"`
	Name         string `gorm:"column:name"`
	Tel          string `gorm:"column:tel"`
	TelHash      string `gorm:"column:tel_hash"`
	IdCode       string `gorm:"column:id_code"`
	RealInfo     string `gorm:"column:real_info"`
	IdCodeHash   string `gorm:"column:id_code_hash"`
	IdType       string `gorm:"column:id_type"`
	IdHold       string `gorm:"column:id_hold"`
	IdFront      string `gorm:"column:id_front"`
	IdBack       string `gorm:"column:id_back"`
	IdVerifiedAt int64  `gorm:"column:id_verified_at"`
	IdExpiredAt  int64  `gorm:"column:id_expired_at"`
	CreatedAt    int64  `gorm:"column:created_at`
}

func NewPrivateInfo

func NewPrivateInfo(name, tel, telHash string) *PrivateInfo

func (*PrivateInfo) HasTel

func (pt *PrivateInfo) HasTel() bool

func (*PrivateInfo) SetUserID

func (pt *PrivateInfo) SetUserID(Id int)

func (*PrivateInfo) TableName

func (*PrivateInfo) TableName() string

type PrivateTelInfo

type PrivateTelInfo struct {
	ID        int    `gorm:"column:id;primaryKey"`
	TelHash   string `gorm:"column:tel_hash"`
	UserId    int    `gorm:"column:user_id"`
	CreatedAt int64  `gorm:"column:created_at"`
	DeletedAt int64  `gorm:"column:deleted_at"`
}

func NewPrivateTelInfo

func NewPrivateTelInfo(hash string) *PrivateTelInfo

func (*PrivateTelInfo) SetUserID

func (pti *PrivateTelInfo) SetUserID(Id int)

func (*PrivateTelInfo) TableName

func (*PrivateTelInfo) TableName() string

type Profile

type Profile struct {
	UserId         int    `gorm:"column:user_id;primaryKey"`
	Uri            string `gorm:"column:uri"`
	Headimgurl     string `gorm:"column:headimgurl"`
	Signature      string `gorm:"column:signature"`
	Nickname       string `gorm:"column:nickname"`
	Sex            int    `gorm:"column:sex"`
	Region         string `gorm:"column:region"`
	Country        string `gorm:"column:country"`
	Province       string `gorm:"column:province"`
	City           string `gorm:"column:city"`
	Height         int    `gorm:"height"`
	Weight         int    `gorm:"weight"`
	Lang           string `gorm:"column:lang"`
	Preferences    string `gorm:"column:preferences"`
	Birthday       string `gorm:"column:birthday"`
	ForbiddenAt    int64  `gorm:"column:forbidden_at"`
	ForbiddenEndAt int64  `gorm:"column:forbidden_end_at"`
	CreatedAt      int64  `gorm:"column:created_at"`
	UpdatedAt      int64  `gorm:"column:updated_at"`
	DeletedAt      int64  `gorm:"column:deleted_at"`
}

func InitProfile

func InitProfile() *Profile

func NewProfile

func NewProfile(snsInfo *WechatUserInfoResp) *Profile

func NewProfileWithGithub

func NewProfileWithGithub(snsInfo *GithubUserInfoResp) *Profile

func (*Profile) SetUserID

func (p *Profile) SetUserID(id int)

func (*Profile) TableName

func (p *Profile) TableName() string

type Unionid

type Unionid struct {
	ID        int    `gorm:"column:id;primaryKey"`
	UserId    int    `gorm:"column:user_id"`
	Unionid   string `gorm:"column:unionid"`
	DataType  int    `gorm:"column:data_type"`
	CreatedAt int64  `gorm:"column:created_at"`
	UpdatedAt int64  `gorm:"column:updated_at"`
}

func NewUnionid

func NewUnionid(unionid string, dt int) *Unionid

func (*Unionid) SetUserID

func (u *Unionid) SetUserID(id int)

func (*Unionid) TableName

func (*Unionid) TableName() string

type UserProfileResp

type UserProfileResp struct {
	Uri        string `json:"uri"`
	Nickname   string `json:"nickname"`
	Signature  string `json:"signature"`
	Sex        int    `json:"sex"`
	Province   string `json:"province"`
	City       string `json:"city"`
	Country    string `json:"country"`
	Region     string `json:"region"`
	Headimgurl string `json:"headimgurl"`
	Height     int    `json:"height"`
	Weight     int    `json:"weight"`
	Birthday   string `json:"birthday"`
}

func TransProfileDto

func TransProfileDto(profile *Profile) *UserProfileResp

type UserSetBirthdayReq

type UserSetBirthdayReq struct {
	Birthday string `json:"birthday" binding:"required"`
}

type UserSetCityReq

type UserSetCityReq struct {
	Region   string `json:"region"`
	Country  string `json:"country"`
	Province string `json:"province"`
	City     string `json:"city"`
}

type UserSetHeadResp

type UserSetHeadResp struct {
	Headimgurl string `json:"headimgurl"`
}

type UserSetHeightReq

type UserSetHeightReq struct {
	Height int `json:"height" binding:"required"`
}

type UserSetNicknameReq

type UserSetNicknameReq struct {
	Nickname string `json:"nickname" binding:"required"`
}

type UserSetSexReq

type UserSetSexReq struct {
	Sex int `json:"sex" binding:"required"`
}

type UserSetSignatureReq

type UserSetSignatureReq struct {
	Signature string `json:"signature" binding:"required,max=140"`
}

type UserSetWeightReq

type UserSetWeightReq struct {
	Weight int `json:"weight" binding:"required"`
}

type WechatAccessTokenResp

type WechatAccessTokenResp struct {
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	Openid       string `json:"openid"`
	Unionid      string `json:"unionid"`
}

type WechatErrResp

type WechatErrResp struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type WechatUserInfoResp

type WechatUserInfoResp struct {
	Openid     string `json:"openid"`
	Nickname   string `json:"nickname"`
	Sex        int    `json:"sex"`
	Province   string `json:"province"`
	City       string `json:"city"`
	Country    string `json:"country"`
	Headimgurl string `json:"headimgurl"`
	Privilege  string `json:"privilege"`
	Unionid    string `json:"unionid"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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