GetClient()

This commit is contained in:
2022-11-19 12:50:41 +01:00
parent f555f0f1cf
commit 6e01c41c22
5 changed files with 152 additions and 3 deletions

View File

@@ -221,3 +221,22 @@ func (db *Database) ListClients(ctx TxContext, userid int64) ([]models.Client, e
return data, nil
}
func (db *Database) GetClient(ctx TxContext, userid int64, clientid int64) (models.Client, error) {
tx, err := ctx.GetOrCreateTransaction(db)
if err != nil {
return models.Client{}, err
}
rows, err := tx.QueryContext(ctx, "SELECT * FROM clients WHERE user_id = ? AND client_id = ? LIMIT 1", userid, clientid)
if err != nil {
return models.Client{}, err
}
client, err := models.DecodeClient(rows)
if err != nil {
return models.Client{}, err
}
return client, nil
}