mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
DELETE license API endpoint (#3697)
* DELETE license API endpoint Signed-off-by: Spike Curtis <spike@coder.com> * Fix new lint stuff Signed-off-by: Spike Curtis <spike@coder.com> Signed-off-by: Spike Curtis <spike@coder.com>
This commit is contained in:
@@ -2301,6 +2301,20 @@ func (q *fakeQuerier) GetLicenses(_ context.Context) ([]database.License, error)
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) DeleteLicense(_ context.Context, id int32) (int32, error) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
|
||||
for index, l := range q.licenses {
|
||||
if l.ID == id {
|
||||
q.licenses[index] = q.licenses[len(q.licenses)-1]
|
||||
q.licenses = q.licenses[:len(q.licenses)-1]
|
||||
return id, nil
|
||||
}
|
||||
}
|
||||
return 0, sql.ErrNoRows
|
||||
}
|
||||
|
||||
func (q *fakeQuerier) GetUserLinkByLinkedID(_ context.Context, id string) (database.UserLink, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
@@ -21,6 +21,7 @@ type querier interface {
|
||||
AcquireProvisionerJob(ctx context.Context, arg AcquireProvisionerJobParams) (ProvisionerJob, error)
|
||||
DeleteAPIKeyByID(ctx context.Context, id string) error
|
||||
DeleteGitSSHKey(ctx context.Context, userID uuid.UUID) error
|
||||
DeleteLicense(ctx context.Context, id int32) (int32, error)
|
||||
DeleteParameterValueByID(ctx context.Context, id uuid.UUID) error
|
||||
GetAPIKeyByID(ctx context.Context, id string) (APIKey, error)
|
||||
GetAPIKeysLastUsedAfter(ctx context.Context, lastUsed time.Time) ([]APIKey, error)
|
||||
|
||||
@@ -475,6 +475,19 @@ func (q *sqlQuerier) UpdateGitSSHKey(ctx context.Context, arg UpdateGitSSHKeyPar
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteLicense = `-- name: DeleteLicense :one
|
||||
DELETE
|
||||
FROM licenses
|
||||
WHERE id = $1
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) DeleteLicense(ctx context.Context, id int32) (int32, error) {
|
||||
row := q.db.QueryRowContext(ctx, deleteLicense, id)
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getLicenses = `-- name: GetLicenses :many
|
||||
SELECT id, uploaded_at, jwt, exp
|
||||
FROM licenses
|
||||
|
||||
@@ -8,8 +8,13 @@ INSERT INTO
|
||||
VALUES
|
||||
($1, $2, $3) RETURNING *;
|
||||
|
||||
|
||||
-- name: GetLicenses :many
|
||||
SELECT *
|
||||
FROM licenses
|
||||
ORDER BY (id);
|
||||
|
||||
-- name: DeleteLicense :one
|
||||
DELETE
|
||||
FROM licenses
|
||||
WHERE id = $1
|
||||
RETURNING id;
|
||||
|
||||
Reference in New Issue
Block a user