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

51 lines
1.2 KiB
Go

package accountlogic
import (
"context"
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 {
return nil, err
}
return &member.GetUidByAccountResp{
Uid: account.Uid,
Account: in.GetAccount(),
}, nil
}