Skip to content

Commit 61392b7

Browse files
authored
feat: add GET method for /v3/transactions/{id} (#839)
1 parent 554fdd6 commit 61392b7

File tree

9 files changed

+451
-23
lines changed

9 files changed

+451
-23
lines changed

api/docs.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4021,6 +4021,92 @@ const docTemplate = `{
40214021
}
40224022
}
40234023
},
4024+
"/v3/transactions/{transactionId}": {
4025+
"get": {
4026+
"description": "Returns a specific transaction",
4027+
"produces": [
4028+
"application/json"
4029+
],
4030+
"tags": [
4031+
"Transactions"
4032+
],
4033+
"summary": "Get transaction",
4034+
"parameters": [
4035+
{
4036+
"type": "string",
4037+
"description": "ID formatted as string",
4038+
"name": "transactionId",
4039+
"in": "path",
4040+
"required": true
4041+
}
4042+
],
4043+
"responses": {
4044+
"200": {
4045+
"description": "OK",
4046+
"schema": {
4047+
"$ref": "#/definitions/controllers.TransactionResponseV3"
4048+
}
4049+
},
4050+
"400": {
4051+
"description": "Bad Request",
4052+
"schema": {
4053+
"$ref": "#/definitions/httperrors.HTTPError"
4054+
}
4055+
},
4056+
"404": {
4057+
"description": "Not Found",
4058+
"schema": {
4059+
"$ref": "#/definitions/httperrors.HTTPError"
4060+
}
4061+
},
4062+
"500": {
4063+
"description": "Internal Server Error",
4064+
"schema": {
4065+
"$ref": "#/definitions/httperrors.HTTPError"
4066+
}
4067+
}
4068+
}
4069+
},
4070+
"options": {
4071+
"description": "Returns an empty response with the HTTP Header \"allow\" set to the allowed HTTP verbs",
4072+
"tags": [
4073+
"Transactions"
4074+
],
4075+
"summary": "Allowed HTTP verbs",
4076+
"parameters": [
4077+
{
4078+
"type": "string",
4079+
"description": "ID formatted as string",
4080+
"name": "transactionId",
4081+
"in": "path",
4082+
"required": true
4083+
}
4084+
],
4085+
"responses": {
4086+
"204": {
4087+
"description": "No Content"
4088+
},
4089+
"400": {
4090+
"description": "Bad Request",
4091+
"schema": {
4092+
"$ref": "#/definitions/httperrors.HTTPError"
4093+
}
4094+
},
4095+
"404": {
4096+
"description": "Not Found",
4097+
"schema": {
4098+
"$ref": "#/definitions/httperrors.HTTPError"
4099+
}
4100+
},
4101+
"500": {
4102+
"description": "Internal Server Error",
4103+
"schema": {
4104+
"$ref": "#/definitions/httperrors.HTTPError"
4105+
}
4106+
}
4107+
}
4108+
}
4109+
},
40244110
"/version": {
40254111
"get": {
40264112
"description": "Returns the software version of the API",

api/swagger.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4010,6 +4010,92 @@
40104010
}
40114011
}
40124012
},
4013+
"/v3/transactions/{transactionId}": {
4014+
"get": {
4015+
"description": "Returns a specific transaction",
4016+
"produces": [
4017+
"application/json"
4018+
],
4019+
"tags": [
4020+
"Transactions"
4021+
],
4022+
"summary": "Get transaction",
4023+
"parameters": [
4024+
{
4025+
"type": "string",
4026+
"description": "ID formatted as string",
4027+
"name": "transactionId",
4028+
"in": "path",
4029+
"required": true
4030+
}
4031+
],
4032+
"responses": {
4033+
"200": {
4034+
"description": "OK",
4035+
"schema": {
4036+
"$ref": "#/definitions/controllers.TransactionResponseV3"
4037+
}
4038+
},
4039+
"400": {
4040+
"description": "Bad Request",
4041+
"schema": {
4042+
"$ref": "#/definitions/httperrors.HTTPError"
4043+
}
4044+
},
4045+
"404": {
4046+
"description": "Not Found",
4047+
"schema": {
4048+
"$ref": "#/definitions/httperrors.HTTPError"
4049+
}
4050+
},
4051+
"500": {
4052+
"description": "Internal Server Error",
4053+
"schema": {
4054+
"$ref": "#/definitions/httperrors.HTTPError"
4055+
}
4056+
}
4057+
}
4058+
},
4059+
"options": {
4060+
"description": "Returns an empty response with the HTTP Header \"allow\" set to the allowed HTTP verbs",
4061+
"tags": [
4062+
"Transactions"
4063+
],
4064+
"summary": "Allowed HTTP verbs",
4065+
"parameters": [
4066+
{
4067+
"type": "string",
4068+
"description": "ID formatted as string",
4069+
"name": "transactionId",
4070+
"in": "path",
4071+
"required": true
4072+
}
4073+
],
4074+
"responses": {
4075+
"204": {
4076+
"description": "No Content"
4077+
},
4078+
"400": {
4079+
"description": "Bad Request",
4080+
"schema": {
4081+
"$ref": "#/definitions/httperrors.HTTPError"
4082+
}
4083+
},
4084+
"404": {
4085+
"description": "Not Found",
4086+
"schema": {
4087+
"$ref": "#/definitions/httperrors.HTTPError"
4088+
}
4089+
},
4090+
"500": {
4091+
"description": "Internal Server Error",
4092+
"schema": {
4093+
"$ref": "#/definitions/httperrors.HTTPError"
4094+
}
4095+
}
4096+
}
4097+
}
4098+
},
40134099
"/version": {
40144100
"get": {
40154101
"description": "Returns the software version of the API",

api/swagger.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4278,6 +4278,64 @@ paths:
42784278
summary: Create transactions
42794279
tags:
42804280
- Transactions
4281+
/v3/transactions/{transactionId}:
4282+
get:
4283+
description: Returns a specific transaction
4284+
parameters:
4285+
- description: ID formatted as string
4286+
in: path
4287+
name: transactionId
4288+
required: true
4289+
type: string
4290+
produces:
4291+
- application/json
4292+
responses:
4293+
"200":
4294+
description: OK
4295+
schema:
4296+
$ref: '#/definitions/controllers.TransactionResponseV3'
4297+
"400":
4298+
description: Bad Request
4299+
schema:
4300+
$ref: '#/definitions/httperrors.HTTPError'
4301+
"404":
4302+
description: Not Found
4303+
schema:
4304+
$ref: '#/definitions/httperrors.HTTPError'
4305+
"500":
4306+
description: Internal Server Error
4307+
schema:
4308+
$ref: '#/definitions/httperrors.HTTPError'
4309+
summary: Get transaction
4310+
tags:
4311+
- Transactions
4312+
options:
4313+
description: Returns an empty response with the HTTP Header "allow" set to the
4314+
allowed HTTP verbs
4315+
parameters:
4316+
- description: ID formatted as string
4317+
in: path
4318+
name: transactionId
4319+
required: true
4320+
type: string
4321+
responses:
4322+
"204":
4323+
description: No Content
4324+
"400":
4325+
description: Bad Request
4326+
schema:
4327+
$ref: '#/definitions/httperrors.HTTPError'
4328+
"404":
4329+
description: Not Found
4330+
schema:
4331+
$ref: '#/definitions/httperrors.HTTPError'
4332+
"500":
4333+
description: Internal Server Error
4334+
schema:
4335+
$ref: '#/definitions/httperrors.HTTPError'
4336+
summary: Allowed HTTP verbs
4337+
tags:
4338+
- Transactions
42814339
/version:
42824340
get:
42834341
description: Returns the software version of the API
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package controllers_test
2+
3+
import (
4+
"github.com/envelope-zero/backend/v3/pkg/models"
5+
"github.com/google/uuid"
6+
)
7+
8+
func (suite *TestSuiteStandard) defaultTransactionCreate(c models.TransactionCreate) models.TransactionCreate {
9+
if c.BudgetID == uuid.Nil {
10+
c.BudgetID = suite.createTestBudget(models.BudgetCreate{Name: "Testing budget"}).Data.ID
11+
}
12+
13+
if c.SourceAccountID == uuid.Nil {
14+
c.SourceAccountID = suite.createTestAccount(models.AccountCreate{Name: "Source Account"}).Data.ID
15+
}
16+
17+
if c.DestinationAccountID == uuid.Nil {
18+
c.DestinationAccountID = suite.createTestAccount(models.AccountCreate{Name: "Destination Account"}).Data.ID
19+
}
20+
21+
if c.EnvelopeID == &uuid.Nil {
22+
*c.EnvelopeID = suite.createTestEnvelope(models.EnvelopeCreate{Name: "Transaction Test Envelope"}).Data.ID
23+
}
24+
25+
return c
26+
}

pkg/controllers/transaction.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,23 @@ func (f TransactionQueryFilterV1) ToCreateHandleErrors(c *gin.Context) (models.T
154154

155155
// ToCreate parses the query string and returns a TransactionCreate struct for
156156
// the database request. On error, it returns httperrors.ErrorStatus struct with.
157-
func (f TransactionQueryFilterV3) ToCreate(c *gin.Context) (models.TransactionCreate, httperrors.Error) {
158-
budgetID, err := httputil.UUIDFromString(c, f.BudgetID)
157+
func (f TransactionQueryFilterV3) ToCreate() (models.TransactionCreate, httperrors.Error) {
158+
budgetID, err := httputil.UUIDFromString(f.BudgetID)
159159
if !err.Nil() {
160160
return models.TransactionCreate{}, err
161161
}
162162

163-
sourceAccountID, err := httputil.UUIDFromString(c, f.SourceAccountID)
163+
sourceAccountID, err := httputil.UUIDFromString(f.SourceAccountID)
164164
if !err.Nil() {
165165
return models.TransactionCreate{}, err
166166
}
167167

168-
destinationAccountID, err := httputil.UUIDFromString(c, f.DestinationAccountID)
168+
destinationAccountID, err := httputil.UUIDFromString(f.DestinationAccountID)
169169
if !err.Nil() {
170170
return models.TransactionCreate{}, err
171171
}
172172

173-
envelopeID, err := httputil.UUIDFromString(c, f.EnvelopeID)
173+
envelopeID, err := httputil.UUIDFromString(f.EnvelopeID)
174174
if !err.Nil() {
175175
return models.TransactionCreate{}, err
176176
}

pkg/controllers/transaction_v1_test.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,7 @@ import (
1616
)
1717

1818
func (suite *TestSuiteStandard) createTestTransaction(c models.TransactionCreate, expectedStatus ...int) controllers.TransactionResponse {
19-
if c.BudgetID == uuid.Nil {
20-
c.BudgetID = suite.createTestBudget(models.BudgetCreate{Name: "Testing budget"}).Data.ID
21-
}
22-
23-
if c.SourceAccountID == uuid.Nil {
24-
c.SourceAccountID = suite.createTestAccount(models.AccountCreate{Name: "Source Account"}).Data.ID
25-
}
26-
27-
if c.DestinationAccountID == uuid.Nil {
28-
c.DestinationAccountID = suite.createTestAccount(models.AccountCreate{Name: "Destination Account"}).Data.ID
29-
}
30-
31-
if c.EnvelopeID == &uuid.Nil {
32-
*c.EnvelopeID = suite.createTestEnvelope(models.EnvelopeCreate{Name: "Transaction Test Envelope"}).Data.ID
33-
}
19+
c = suite.defaultTransactionCreate(c)
3420

3521
// Default to 201 Created as expected status
3622
if len(expectedStatus) == 0 {

0 commit comments

Comments
 (0)