diff --git a/dal/db_query/queries.sql b/dal/db_query/queries.sql index d093792..eb407c2 100644 --- a/dal/db_query/queries.sql +++ b/dal/db_query/queries.sql @@ -1553,4 +1553,7 @@ update YclientsTokens set Expiration=$1, Active = $2 where AccountID = $3 RETURN select * from YclientsTokens where AccountID = $1 and Expiration=false and Active = true; -- name: CreateYclientsAccount :one -insert into YclientsAccounts (AccountID,SalonID,Title,Country,ShortDecription) values ($1,$2,$3,$4,$5) RETURNING *; \ No newline at end of file +insert into YclientsAccounts (AccountID,SalonID,Title,Country,ShortDecription) values ($1,$2,$3,$4,$5) RETURNING *; + +-- name: GetAllYclientsUserToken :many +select * from YclientsTokens where Expiration=false and Active = true; \ No newline at end of file diff --git a/dal/sqlcgen/queries.sql.go b/dal/sqlcgen/queries.sql.go index 8771c23..f0ef518 100644 --- a/dal/sqlcgen/queries.sql.go +++ b/dal/sqlcgen/queries.sql.go @@ -2164,6 +2164,40 @@ func (q *Queries) GetAllTokens(ctx context.Context) ([]Token, error) { return items, nil } +const getAllYclientsUserToken = `-- name: GetAllYclientsUserToken :many +select accountid, salonid, accesstoken, active, expiration, createdat from YclientsTokens where Expiration=false and Active = true +` + +func (q *Queries) GetAllYclientsUserToken(ctx context.Context) ([]Yclientstoken, error) { + rows, err := q.db.QueryContext(ctx, getAllYclientsUserToken) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Yclientstoken + for rows.Next() { + var i Yclientstoken + if err := rows.Scan( + &i.Accountid, + &i.Salonid, + &i.Accesstoken, + &i.Active, + &i.Expiration, + &i.Createdat, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const getBitrixFieldByID = `-- name: GetBitrixFieldByID :one SELECT id, bitrixid, accountid, entityid, fieldname, editfromlabel, fieldtype, deleted, createdat FROM BitrixFields WHERE BitrixID = $1 AND Deleted = false ` diff --git a/repository/yclients/yclients.go b/repository/yclients/yclients.go index 90b8dfe..0e8869d 100644 --- a/repository/yclients/yclients.go +++ b/repository/yclients/yclients.go @@ -95,6 +95,24 @@ func (r *YclientsRepository) GetYclientsUserToken(ctx context.Context, accountID }, err } +func (r *YclientsRepository) GetAllYclientsUserToken(ctx context.Context) ([]model.YclientsToken, error) { + rows, err := r.queries.GetAllYclientsUserToken(ctx) + if err != nil { + return nil, err + } + var tokens []model.YclientsToken + for _, row := range rows { + tokens = append(tokens, model.YclientsToken{ + AccountID: row.Accountid, + SalonID: row.Salonid, + AccessToken: row.Accesstoken, + Active: row.Active, + Expiration: row.Expiration, + }) + } + return tokens, nil +} + // users func (r *YclientsRepository) GetCurrentAccount(ctx context.Context, accountID string) (*model.YclientsAccount, error) { row, err := r.queries.GetCurrentYclientsCompany(ctx, accountID)