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)
|
GetTasks(ctx context.Context) ([]Task, error)
|
||||||
InsertPrices(ctx context.Context, rawPrices []Result) 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
|
OriginName string
|
||||||
Price int32
|
Price int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PersonalDTO struct {
|
||||||
|
Uuid string
|
||||||
|
Email string
|
||||||
|
Username string
|
||||||
|
Name string
|
||||||
|
Surname string
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,29 +3,32 @@ package authCheck
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"merch-api/internal/common"
|
||||||
verifyV1 "merch-api/pkg/verify/v1"
|
verifyV1 "merch-api/pkg/verify/v1"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type service struct {
|
type service struct {
|
||||||
client verifyV1.AuthServiceClient
|
client verifyV1.AuthServiceClient
|
||||||
timeout time.Duration
|
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{
|
return &service{
|
||||||
client: c,
|
client: c,
|
||||||
timeout: timeout,
|
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)
|
runCtx, cancel := context.WithTimeout(ctx, s.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
response, err := s.client.VerifyToken(runCtx, &verifyV1.VerifyTokenRequest{
|
response, err := s.client.VerifyToken(runCtx, &verifyV1.VerifyTokenRequest{
|
||||||
SessionToken: sessionUuid,
|
SessionToken: sessionUuid,
|
||||||
ServiceId: serviceId,
|
ServiceId: s.serviceId,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
@ -41,3 +44,28 @@ func (s *service) VerifySession(ctx context.Context, sessionUuid string, service
|
||||||
|
|
||||||
return response.UserUuid, nil
|
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