get personal interface + provider + dto
This commit is contained in:
parent
e6da13e657
commit
c7c67a641e
3 changed files with 47 additions and 7 deletions
|
|
@ -8,3 +8,7 @@ type MerchProvider interface {
|
|||
GetTasks(ctx context.Context) ([]Task, error)
|
||||
InsertPrices(ctx context.Context, rawPrices []Result) error
|
||||
}
|
||||
|
||||
type AuthDataProvider interface {
|
||||
GetPersonalData(ctx context.Context, userUuid string) (*PersonalDTO, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,3 +10,11 @@ type Result struct {
|
|||
OriginName string
|
||||
Price int32
|
||||
}
|
||||
|
||||
type PersonalDTO struct {
|
||||
Uuid string
|
||||
Email string
|
||||
Username string
|
||||
Name string
|
||||
Surname string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package authCheck
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"merch-api/internal/common"
|
||||
verifyV1 "merch-api/pkg/verify/v1"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -10,22 +11,24 @@ import (
|
|||
type service struct {
|
||||
client verifyV1.AuthServiceClient
|
||||
timeout time.Duration
|
||||
serviceId int32
|
||||
}
|
||||
|
||||
func newService(c verifyV1.AuthServiceClient, timeout time.Duration) *service {
|
||||
func newService(c verifyV1.AuthServiceClient, timeout time.Duration, sid int32) *service {
|
||||
return &service{
|
||||
client: c,
|
||||
timeout: timeout,
|
||||
serviceId: sid,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *service) VerifySession(ctx context.Context, sessionUuid string, serviceId int32) (string, error) {
|
||||
func (s *service) VerifySession(ctx context.Context, sessionUuid string) (string, error) {
|
||||
runCtx, cancel := context.WithTimeout(ctx, s.timeout)
|
||||
defer cancel()
|
||||
|
||||
response, err := s.client.VerifyToken(runCtx, &verifyV1.VerifyTokenRequest{
|
||||
SessionToken: sessionUuid,
|
||||
ServiceId: serviceId,
|
||||
ServiceId: s.serviceId,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
@ -41,3 +44,28 @@ func (s *service) VerifySession(ctx context.Context, sessionUuid string, service
|
|||
|
||||
return response.UserUuid, nil
|
||||
}
|
||||
|
||||
func (s *service) GetPersonalData(ctx context.Context, userUuid string) (*common.PersonalDTO, error) {
|
||||
runCtx, cancel := context.WithTimeout(ctx, s.timeout)
|
||||
defer cancel()
|
||||
|
||||
response, err := s.client.GetPersonalInfo(runCtx, &verifyV1.PersonalRequest{
|
||||
UserUuid: userUuid,
|
||||
ServiceId: s.serviceId,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if response == nil {
|
||||
return nil, errors.New("no data")
|
||||
}
|
||||
|
||||
return &common.PersonalDTO{
|
||||
Uuid: userUuid,
|
||||
Email: response.Email,
|
||||
Username: response.Username,
|
||||
Name: response.Name,
|
||||
Surname: response.Surname,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue