MSP-634 add func get_auth_data to token repository
This commit is contained in:
1 parent
bb0d2b460a
commit
e5d73d91de
2 files changed
+35
No files matched your search
@@ -10,3 +10,12 @@ type Token struct {
|
||||
ExpireTime int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type AuthData struct {
|
||||
SystemId int
|
||||
DomainId int
|
||||
ServiceId int
|
||||
AppId int
|
||||
ExpireTime int
|
||||
CreatedAt time.Time
|
||||
}
|
||||
@@ -2,11 +2,13 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/integration-system/isp-kit/db"
|
||||
"github.com/integration-system/isp-kit/db/query"
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
@@ -92,3 +94,27 @@ func (r Token) DeleteToken(ctx context.Context, tokens []string) (int, error) {
|
||||
|
||||
return int(rowsAffected), nil
|
||||
}
|
||||
|
||||
func (r Token) AuthDataByToken(ctx context.Context, token string) (*entity.AuthData, error) {
|
||||
q := `
|
||||
SELECT system_id, domain_id, service_id, app_id, token.expire_time, token.created_at
|
||||
FROM token
|
||||
LEFT JOIN application
|
||||
ON token.app_id = application.id
|
||||
LEFT JOIN service
|
||||
ON application.service_id = service.id
|
||||
LEFT JOIN domain
|
||||
ON service.domain_id = domain.id
|
||||
WHERE token = $1
|
||||
`
|
||||
result := entity.AuthData{}
|
||||
err := r.db.SelectRow(ctx, &result, q, token)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, domain.ErrTokenNotFound
|
||||
}
|
||||
return nil, errors.WithMessage(err, "select row db")
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
Reference in new issue
Block a user