2024-08-22 14:27:13 +00:00
|
|
|
package accountlogic
|
|
|
|
|
|
|
|
import (
|
2024-08-24 06:46:26 +00:00
|
|
|
"app-cloudep-member-server/internal/domain"
|
2024-08-22 14:27:13 +00:00
|
|
|
"context"
|
2024-08-24 06:46:26 +00:00
|
|
|
"errors"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
2024-08-22 14:27:13 +00:00
|
|
|
|
|
|
|
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 {
|
2024-08-24 06:46:26 +00:00
|
|
|
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())
|
2024-08-22 14:27:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &member.GetUidByAccountResp{
|
|
|
|
Uid: account.Uid,
|
|
|
|
Account: in.GetAccount(),
|
|
|
|
}, nil
|
|
|
|
}
|