Skip to content

Commit

Permalink
1486 adding get transaction version service (#1488)
Browse files Browse the repository at this point in the history
* 1486 adding get transaction version service

* 1486 adding get transaction version service
  • Loading branch information
xoscar committed Nov 15, 2022
1 parent a1f7847 commit 3041a34
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
28 changes: 28 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,34 @@ paths:
"204":
description: OK

/transactions/{transactionId}/version/{version}:
get:
tags:
- api
parameters:
- in: path
name: transactionId
schema:
type: string
required: true
- in: path
name: version
schema:
type: integer
required: true
summary: "get a transaction specific version"
description: "get a transaction specific version"
operationId: getTransactionVersion
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: "./transactions.yaml#/components/schemas/Transaction"
500:
description: "problem with getting a test"

/transactions/{transactionId}/run:
post:
tags:
Expand Down
10 changes: 10 additions & 0 deletions server/http/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,16 @@ func (c *controller) GetTransaction(ctx context.Context, tID string) (openapi.Im
return openapi.Response(http.StatusOK, c.mappers.Out.Transaction(transaction)), nil
}

func (c *controller) GetTransactionVersion(ctx context.Context, tID string, version int32) (openapi.ImplResponse, error) {
transaction, err := c.testDB.GetTransactionVersion(ctx, id.ID(tID), int(version))

if err != nil {
return handleDBError(err), err
}

return openapi.Response(http.StatusOK, c.mappers.Out.Transaction(transaction)), nil
}

func (c *controller) GetTransactions(ctx context.Context, take, skip int32, query, sortBy, sortDirection string) (openapi.ImplResponse, error) {
if take == 0 {
take = 20
Expand Down
2 changes: 2 additions & 0 deletions server/openapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type ApiApiRouter interface {
GetTransaction(http.ResponseWriter, *http.Request)
GetTransactionRun(http.ResponseWriter, *http.Request)
GetTransactionRuns(http.ResponseWriter, *http.Request)
GetTransactionVersion(http.ResponseWriter, *http.Request)
GetTransactions(http.ResponseWriter, *http.Request)
ImportTestRun(http.ResponseWriter, *http.Request)
RerunTestRun(http.ResponseWriter, *http.Request)
Expand Down Expand Up @@ -89,6 +90,7 @@ type ApiApiServicer interface {
GetTransaction(context.Context, string) (ImplResponse, error)
GetTransactionRun(context.Context, string, int32) (ImplResponse, error)
GetTransactionRuns(context.Context, string) (ImplResponse, error)
GetTransactionVersion(context.Context, string, int32) (ImplResponse, error)
GetTransactions(context.Context, int32, int32, string, string, string) (ImplResponse, error)
ImportTestRun(context.Context, ExportedTestInformation) (ImplResponse, error)
RerunTestRun(context.Context, string, string) (ImplResponse, error)
Expand Down
28 changes: 28 additions & 0 deletions server/openapi/api_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ func (c *ApiApiController) Routes() Routes {
"/api/transactions/{transactionId}/run",
c.GetTransactionRuns,
},
{
"GetTransactionVersion",
strings.ToUpper("Get"),
"/api/transactions/{transactionId}/version/{version}",
c.GetTransactionVersion,
},
{
"GetTransactions",
strings.ToUpper("Get"),
Expand Down Expand Up @@ -840,6 +846,28 @@ func (c *ApiApiController) GetTransactionRuns(w http.ResponseWriter, r *http.Req

}

// GetTransactionVersion - get a transaction specific version
func (c *ApiApiController) GetTransactionVersion(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
transactionIdParam := params["transactionId"]

versionParam, err := parseInt32Parameter(params["version"], true)
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}

result, err := c.service.GetTransactionVersion(r.Context(), transactionIdParam, versionParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)

}

// GetTransactions - Get transactions
func (c *ApiApiController) GetTransactions(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
Expand Down
2 changes: 1 addition & 1 deletion server/openapi/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package openapi

//Implementation response defines an error code with the associated body
// Implementation response defines an error code with the associated body
type ImplResponse struct {
Code int
Body interface{}
Expand Down
6 changes: 6 additions & 0 deletions server/testdb/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ func (td *postgresDB) DeleteTransaction(ctx context.Context, transaction model.T
return err
}

_, err = tx.ExecContext(ctx, "DELETE FROM transaction_runs WHERE transaction_id = $1", transaction.ID)
if err != nil {
tx.Rollback()
return err
}

_, err = tx.ExecContext(ctx, "DELETE FROM transactions WHERE id = $1", transaction.ID)
if err != nil {
tx.Rollback()
Expand Down
2 changes: 1 addition & 1 deletion tracetesting/definitions/transaction_delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ spec:
- attr:tracetest.selected_spans.count = 1
- selector: span[name = "exec DELETE"]
assertions:
- attr:tracetest.selected_spans.count = 2
- attr:tracetest.selected_spans.count = 3

0 comments on commit 3041a34

Please sign in to comment.