app-cloudep-member-server/internal/logic/account/get_user_account_info_logic.go

59 lines
1.4 KiB
Go
Raw Permalink Normal View History

2024-08-22 14:27:13 +00:00
package accountlogic
import (
ers "code.30cm.net/digimon/library-go/errors"
2024-08-24 06:46:26 +00:00
"context"
"errors"
"github.com/zeromicro/go-zero/core/stores/sqlx"
2024-08-22 14:27:13 +00:00
"app-cloudep-member-server/gen_result/pb/member"
"app-cloudep-member-server/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserAccountInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetUserAccountInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserAccountInfoLogic {
return &GetUserAccountInfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
type getUserAccountReq struct {
LoginId string `json:"login_id" validate:"account"`
}
// GetUserAccountInfo 取得帳號密碼資料
func (l *GetUserAccountInfoLogic) GetUserAccountInfo(in *member.GetUIDByAccountReq) (*member.GetAccountInfoResp, error) {
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(getUserAccountReq{
LoginId: in.GetAccount(),
}); err != nil {
return nil, ers.InvalidFormat(err.Error())
}
account, err := l.svcCtx.AccountModel.FindOneByAccount(l.ctx, in.GetAccount())
if err != nil {
2024-08-24 06:46:26 +00:00
if errors.As(err, &sqlx.ErrNotFound) {
return nil, ers.ResourceNotFound(in.GetAccount())
}
2024-08-22 14:27:13 +00:00
return nil, ers.DBError(err.Error())
}
return &member.GetAccountInfoResp{
Data: &member.CreateLoginUserReq{
LoginId: account.Account,
Token: account.Token,
Platform: account.Platform,
},
}, nil
}