ark-member/internal/logic/get_uid_by_account_logic.go

56 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-07-21 15:57:56 +00:00
package logic
import (
"context"
2024-08-02 02:10:25 +00:00
"member/gen_result/pb/member"
2024-07-25 14:01:22 +00:00
"member/internal/domain"
ers "member/internal/lib/error"
2024-07-21 15:57:56 +00:00
"member/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),
}
}
2024-07-25 14:01:22 +00:00
type getUidByAccountReq struct {
Account string `json:"account" validate:"account"`
}
2024-07-21 15:57:56 +00:00
// GetUidByAccount 用帳號換取 UID
func (l *GetUidByAccountLogic) GetUidByAccount(in *member.GetUIDByAccountReq) (*member.GetUidByAccountResp, error) {
2024-08-02 02:10:25 +00:00
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&getUidByAccountReq{
2024-07-25 14:01:22 +00:00
Account: in.GetAccount(),
2024-08-02 02:10:25 +00:00
}); err != nil {
2024-07-25 14:01:22 +00:00
return nil, ers.InvalidFormat(err.Error())
}
account, err := l.svcCtx.AccountToUidModel.FindOneByAccount(l.ctx, in.GetAccount())
if err != nil {
return nil, err
}
2024-07-21 15:57:56 +00:00
2024-07-25 14:01:22 +00:00
return &member.GetUidByAccountResp{
Status: &member.BaseResp{
Code: domain.CodeOk.ToString(),
Message: "success",
Error: "",
},
Data: &member.UID{
Uid: account.Uid,
},
}, nil
2024-07-21 15:57:56 +00:00
}