package accountlogic import ( "app-cloudep-member-server/internal/domain" "context" "errors" "github.com/zeromicro/go-zero/core/stores/sqlx" ers "code.30cm.net/digimon/library-go/errors" "app-cloudep-member-server/gen_result/pb/member" "app-cloudep-member-server/internal/svc" "github.com/zeromicro/go-zero/core/logx" ) type GetUidByAccountLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewGetUidByAccountLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUidByAccountLogic { return &GetUidByAccountLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } type getUidByAccountReq struct { Account string `json:"account" validate:"account"` } // GetUidByAccount 用帳號換取 UID func (l *GetUidByAccountLogic) GetUidByAccount(in *member.GetUIDByAccountReq) (*member.GetUidByAccountResp, error) { // 驗證資料 if err := l.svcCtx.Validate.ValidateAll(&getUidByAccountReq{ Account: in.GetAccount(), }); err != nil { return nil, ers.InvalidFormat(err.Error()) } account, err := l.svcCtx.AccountToUidModel.FindOneByAccount(l.ctx, in.GetAccount()) if err != nil { if errors.As(err, &sqlx.ErrNotFound) { return nil, ers.ResourceNotFound(in.GetAccount()) } logx.WithCallerSkip(1).WithFields( logx.Field("app", domain.AppName), logx.Field("func", "VerifyGoogleToken"), logx.Field("req", in), ).Error(err.Error()) return nil, ers.DBError(err.Error()) } return &member.GetUidByAccountResp{ Uid: account.Uid, Account: in.GetAccount(), }, nil }