package accountlogic import ( ers "code.30cm.net/digimon/library-go/errors" "context" "errors" "github.com/zeromicro/go-zero/core/stores/sqlx" "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 { if errors.As(err, &sqlx.ErrNotFound) { return nil, ers.ResourceNotFound(in.GetAccount()) } return nil, ers.DBError(err.Error()) } return &member.GetAccountInfoResp{ Data: &member.CreateLoginUserReq{ LoginId: account.Account, Token: account.Token, Platform: account.Platform, }, }, nil }