Skip to content

Commit

Permalink
Merge pull request #13 from volmedo/minor-fixes
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
volmedo authored Jun 22, 2019
2 parents 357652a + 3bd74ce commit 491b4a0
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 112 deletions.
2 changes: 0 additions & 2 deletions e2e_test/features/create_payment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Feature: Create payment
When I create a new payment described in JSON as:
"""
{
"type": "Payment",
"id": "4ee3a8d8-ca7b-4290-a52c-dd5b6165ec43",
"version": 0,
"organisation_id": "743d5b63-8e6f-432e-a8fa-c5d8d2ee5fcb",
"attributes": {
"amount": "100.21",
Expand Down
4 changes: 2 additions & 2 deletions pAPI-swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ paths:
description: List of payment details
schema:
$ref: "#/definitions/PaymentDetailsListResponse"
400:
description: Bad Request
404:
description: The query returned no payments
schema:
$ref: "#/definitions/ApiError"
429:
Expand Down
22 changes: 11 additions & 11 deletions pkg/client/payments/list_payments_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions pkg/restapi/operations/payments/list_payments_responses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions pkg/service/db_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,13 @@ func (dbpr *DBPaymentRepository) Add(payment *models.Payment) (*models.Payment,
$41, $42
)`

version := int64(0)
attrs := payment.Attributes
amounts := senderChargesToAmounts(attrs.ChargesInformation.SenderCharges)
_, err := dbpr.db.Exec(insertStmt,
payment.ID, // id,
payment.OrganisationID, // organisation,
*payment.Version, // version,
version, // version,
attrs.Amount, // amount,
attrs.BeneficiaryParty.AccountName, // beneficiary_party.name,
attrs.BeneficiaryParty.AccountNumber, // beneficiary_party.number,
Expand Down Expand Up @@ -310,9 +311,10 @@ func (dbpr *DBPaymentRepository) Add(payment *models.Payment) (*models.Payment,
return nil, fmt.Errorf("db: error executing insert: %v", err)
}

// Ignore the original type attribute and fix it to TYPE_PAYMENT
added := copyPayment(payment)
// Add type and version attributes
added.Type = TYPE_PAYMENT
added.Version = &version
return added, nil
}

Expand Down Expand Up @@ -489,16 +491,6 @@ func (dbpr *DBPaymentRepository) List(offset, limit int64) ([]*models.Payment, e
return nil, newErrBadOffsetLimit(fmt.Sprintf("db: list offset %d negative", offset))
}

numRecords := 0
row := dbpr.db.QueryRow(`SELECT COUNT(*) FROM payments`)
err := row.Scan(&numRecords)
if err != nil {
return nil, fmt.Errorf("db: error counting records: %v", err)
}
if offset >= int64(numRecords) {
return nil, newErrBadOffsetLimit(fmt.Sprintf("db: list offset is %d but only %d records exist", offset, numRecords))
}

listStmt := `
SELECT
id,
Expand Down Expand Up @@ -629,6 +621,10 @@ func (dbpr *DBPaymentRepository) List(offset, limit int64) ([]*models.Payment, e
return nil, fmt.Errorf("db: error scanning rows: %v", err)
}

if len(payments) == 0 {
return nil, newErrNoResults(fmt.Sprintf("db: no results with offset %d and limit %d", offset, limit))
}

return payments, nil
}

Expand Down Expand Up @@ -693,7 +689,7 @@ func (dbpr *DBPaymentRepository) Update(paymentID strfmt.UUID, payment *models.P
attrs := payment.Attributes
amounts := senderChargesToAmounts(attrs.ChargesInformation.SenderCharges)
_, err = dbpr.db.Exec(updateStmt,
payment.ID, // id,
paymentID, // id,
payment.OrganisationID, // organisation,
version, // version,
attrs.Amount, // amount,
Expand Down Expand Up @@ -740,8 +736,8 @@ func (dbpr *DBPaymentRepository) Update(paymentID strfmt.UUID, payment *models.P
return nil, fmt.Errorf("db: error executing update: %v", err)
}

// Ignore the original type attribute and fix it to TYPE_PAYMENT
updated := copyPayment(payment)
// Add type and version attributes
updated.Type = TYPE_PAYMENT
updated.Version = &version
return updated, nil
Expand Down
Loading

0 comments on commit 491b4a0

Please sign in to comment.