fix: GetImpersonationToken external_id handling

This commit is contained in:
nihonium 2025-12-06 05:15:21 +03:00
parent afb1db17bd
commit 8bd515c33f
Signed by: nihonium
GPG key ID: 0251623741027CFC
7 changed files with 70 additions and 52 deletions

View file

@ -112,7 +112,7 @@ CREATE TABLE external_services (
CREATE TABLE external_ids (
user_id bigint NOT NULL REFERENCES users (id),
service_id bigint REFERENCES external_services (id),
service_id bigint NOT NULL REFERENCES external_services (id),
external_id text NOT NULL
);

View file

@ -188,7 +188,7 @@ func (ns NullUsertitleStatusT) Value() (driver.Value, error) {
type ExternalID struct {
UserID int64 `json:"user_id"`
ServiceID *int64 `json:"service_id"`
ServiceID int64 `json:"service_id"`
ExternalID string `json:"external_id"`
}

View file

@ -251,6 +251,35 @@ func (q *Queries) GetTitleTags(ctx context.Context, titleID int64) ([]json.RawMe
return items, nil
}
const getUserByExternalServiceId = `-- name: GetUserByExternalServiceId :one
SELECT u.id, u.avatar_id, u.passhash, u.mail, u.nickname, u.disp_name, u.user_desc, u.creation_date, u.last_login
FROM users u
LEFT JOIN external_ids ei ON eu.user_id = u.id
WHERE ei.external_id = $1 AND ei.service_id = $2
`
type GetUserByExternalServiceIdParams struct {
ExternalID string `json:"external_id"`
ServiceID int64 `json:"service_id"`
}
func (q *Queries) GetUserByExternalServiceId(ctx context.Context, arg GetUserByExternalServiceIdParams) (User, error) {
row := q.db.QueryRow(ctx, getUserByExternalServiceId, arg.ExternalID, arg.ServiceID)
var i User
err := row.Scan(
&i.ID,
&i.AvatarID,
&i.Passhash,
&i.Mail,
&i.Nickname,
&i.DispName,
&i.UserDesc,
&i.CreationDate,
&i.LastLogin,
)
return i, err
}
const getUserByID = `-- name: GetUserByID :one
SELECT
t.id as id,