Rename Id to ID for annotation models (#62886)

* Rename Id to ID for annotation models

* Add xorm tags

* Rename Id to ID for API key models

* Add xorm tags
This commit is contained in:
idafurjes
2023-02-03 17:23:09 +01:00
committed by GitHub
parent a0602a2a78
commit 982939111b
34 changed files with 367 additions and 367 deletions
+9 -9
View File
@@ -26,10 +26,10 @@ func (ss *sqlxStore) GetAPIKeys(ctx context.Context, query *apikey.GetApiKeysQue
if query.IncludeExpired {
where = append(where, "org_id=?")
args = append(args, query.OrgId)
args = append(args, query.OrgID)
} else {
where = append(where, "org_id=? and ( expires IS NULL or expires >= ?)")
args = append(args, query.OrgId, timeNow().Unix())
args = append(args, query.OrgID, timeNow().Unix())
}
where = append(where, "service_account_id IS NULL")
@@ -64,7 +64,7 @@ func (ss *sqlxStore) GetAllAPIKeys(ctx context.Context, orgID int64) ([]*apikey.
}
func (ss *sqlxStore) DeleteApiKey(ctx context.Context, cmd *apikey.DeleteCommand) error {
res, err := ss.sess.Exec(ctx, "DELETE FROM api_key WHERE id=? and org_id=? and service_account_id IS NULL", cmd.Id, cmd.OrgId)
res, err := ss.sess.Exec(ctx, "DELETE FROM api_key WHERE id=? and org_id=? and service_account_id IS NULL", cmd.ID, cmd.OrgID)
if err != nil {
return err
}
@@ -85,14 +85,14 @@ func (ss *sqlxStore) AddAPIKey(ctx context.Context, cmd *apikey.AddCommand) erro
return apikey.ErrInvalidExpiration
}
err := ss.GetApiKeyByName(ctx, &apikey.GetByNameQuery{OrgId: cmd.OrgId, KeyName: cmd.Name})
err := ss.GetApiKeyByName(ctx, &apikey.GetByNameQuery{OrgID: cmd.OrgID, KeyName: cmd.Name})
// If key with the same orgId and name already exist return err
if !errors.Is(err, apikey.ErrInvalid) {
return apikey.ErrDuplicate
}
isRevoked := false
t := apikey.APIKey{
OrgId: cmd.OrgId,
OrgID: cmd.OrgID,
Name: cmd.Name,
Role: cmd.Role,
Key: cmd.Key,
@@ -103,15 +103,15 @@ func (ss *sqlxStore) AddAPIKey(ctx context.Context, cmd *apikey.AddCommand) erro
IsRevoked: &isRevoked,
}
t.Id, err = ss.sess.ExecWithReturningId(ctx,
`INSERT INTO api_key (org_id, name, role, "key", created, updated, expires, service_account_id, is_revoked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, t.OrgId, t.Name, t.Role, t.Key, t.Created, t.Updated, t.Expires, t.ServiceAccountId, t.IsRevoked)
t.ID, err = ss.sess.ExecWithReturningId(ctx,
`INSERT INTO api_key (org_id, name, role, "key", created, updated, expires, service_account_id, is_revoked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, t.OrgID, t.Name, t.Role, t.Key, t.Created, t.Updated, t.Expires, t.ServiceAccountId, t.IsRevoked)
cmd.Result = &t
return err
}
func (ss *sqlxStore) GetApiKeyById(ctx context.Context, query *apikey.GetByIDQuery) error {
var key apikey.APIKey
err := ss.sess.Get(ctx, &key, "SELECT * FROM api_key WHERE id=?", query.ApiKeyId)
err := ss.sess.Get(ctx, &key, "SELECT * FROM api_key WHERE id=?", query.ApiKeyID)
if err != nil && errors.Is(err, sql.ErrNoRows) {
return apikey.ErrInvalid
}
@@ -121,7 +121,7 @@ func (ss *sqlxStore) GetApiKeyById(ctx context.Context, query *apikey.GetByIDQue
func (ss *sqlxStore) GetApiKeyByName(ctx context.Context, query *apikey.GetByNameQuery) error {
var key apikey.APIKey
err := ss.sess.Get(ctx, &key, "SELECT * FROM api_key WHERE org_id=? AND name=?", query.OrgId, query.KeyName)
err := ss.sess.Get(ctx, &key, "SELECT * FROM api_key WHERE org_id=? AND name=?", query.OrgID, query.KeyName)
if err != nil && errors.Is(err, sql.ErrNoRows) {
return apikey.ErrInvalid
}