Skip to content

Commit 9421a2b

Browse files
authored
fix: recent envelopes for Accounts in v1, links for Accounts in v2 (#801)
This refactors the Account code by assembling the API response in the controller instead of the models. This enabled fixing the links for Accounts in API v2. Additionally, the implementation for recent Envelopes already used in API v2 is now also used in API v1. This resolves a bug in API v1, where the recent Envelopes did factor in all transactions for the account, not only recent transactions.
1 parent 634648d commit 9421a2b

File tree

16 files changed

+789
-1289
lines changed

16 files changed

+789
-1289
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ package.json
1414

1515
# VSCode logs
1616
.vscode/*.log
17+
18+
# Debugging binaries
19+
__debug_bin*

api/docs.go

Lines changed: 108 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,14 +3616,120 @@ const docTemplate = `{
36163616
}
36173617
},
36183618
"definitions": {
3619+
"controllers.Account": {
3620+
"type": "object",
3621+
"properties": {
3622+
"balance": {
3623+
"description": "Balance of the account, including all transactions referencing it",
3624+
"type": "number",
3625+
"example": 2735.17
3626+
},
3627+
"budgetId": {
3628+
"description": "ID of the budget this account belongs to",
3629+
"type": "string",
3630+
"example": "550dc009-cea6-4c12-b2a5-03446eb7b7cf"
3631+
},
3632+
"createdAt": {
3633+
"description": "Time the resource was created",
3634+
"type": "string",
3635+
"example": "2022-04-02T19:28:44.491514Z"
3636+
},
3637+
"deletedAt": {
3638+
"description": "Time the resource was marked as deleted",
3639+
"type": "string",
3640+
"example": "2022-04-22T21:01:05.058161Z"
3641+
},
3642+
"external": {
3643+
"description": "Does the account belong to the budget owner or not?",
3644+
"type": "boolean",
3645+
"default": false,
3646+
"example": false
3647+
},
3648+
"hidden": {
3649+
"description": "Is the account archived?",
3650+
"type": "boolean",
3651+
"default": false,
3652+
"example": true
3653+
},
3654+
"id": {
3655+
"description": "UUID for the resource",
3656+
"type": "string",
3657+
"example": "65392deb-5e92-4268-b114-297faad6cdce"
3658+
},
3659+
"importHash": {
3660+
"description": "The SHA256 hash of a unique combination of values to use in duplicate detection",
3661+
"type": "string",
3662+
"example": "867e3a26dc0baf73f4bff506f31a97f6c32088917e9e5cf1a5ed6f3f84a6fa70"
3663+
},
3664+
"initialBalance": {
3665+
"description": "Balance of the account before any transactions were recorded",
3666+
"type": "number",
3667+
"default": 0,
3668+
"example": 173.12
3669+
},
3670+
"initialBalanceDate": {
3671+
"description": "Date of the initial balance",
3672+
"type": "string",
3673+
"example": "2017-05-12T00:00:00Z"
3674+
},
3675+
"links": {
3676+
"type": "object",
3677+
"properties": {
3678+
"self": {
3679+
"description": "The account itself",
3680+
"type": "string",
3681+
"example": "https://example.com/api/v1/accounts/af892e10-7e0a-4fb8-b1bc-4b6d88401ed2"
3682+
},
3683+
"transactions": {
3684+
"description": "Transactions referencing the account",
3685+
"type": "string",
3686+
"example": "https://example.com/api/v1/transactions?account=af892e10-7e0a-4fb8-b1bc-4b6d88401ed2"
3687+
}
3688+
}
3689+
},
3690+
"name": {
3691+
"description": "Name of the account",
3692+
"type": "string",
3693+
"example": "Cash"
3694+
},
3695+
"note": {
3696+
"description": "A longer description for the account",
3697+
"type": "string",
3698+
"example": "Money in my wallet"
3699+
},
3700+
"onBudget": {
3701+
"description": "Does the account factor into the available budget? Always false when external: true",
3702+
"type": "boolean",
3703+
"default": false,
3704+
"example": true
3705+
},
3706+
"recentEnvelopes": {
3707+
"description": "Envelopes recently used with this account",
3708+
"type": "array",
3709+
"items": {
3710+
"$ref": "#/definitions/models.Envelope"
3711+
}
3712+
},
3713+
"reconciledBalance": {
3714+
"description": "Balance of the account, including all reconciled transactions referencing it",
3715+
"type": "number",
3716+
"example": 2539.57
3717+
},
3718+
"updatedAt": {
3719+
"description": "Last time the resource was updated",
3720+
"type": "string",
3721+
"example": "2022-04-17T20:14:01.048145Z"
3722+
}
3723+
}
3724+
},
36193725
"controllers.AccountListResponse": {
36203726
"type": "object",
36213727
"properties": {
36223728
"data": {
36233729
"description": "List of accounts",
36243730
"type": "array",
36253731
"items": {
3626-
"$ref": "#/definitions/models.Account"
3732+
"$ref": "#/definitions/controllers.Account"
36273733
}
36283734
}
36293735
}
@@ -3635,7 +3741,7 @@ const docTemplate = `{
36353741
"description": "Data for the account",
36363742
"allOf": [
36373743
{
3638-
"$ref": "#/definitions/models.Account"
3744+
"$ref": "#/definitions/controllers.Account"
36393745
}
36403746
]
36413747
}
@@ -3972,112 +4078,6 @@ const docTemplate = `{
39724078
}
39734079
}
39744080
},
3975-
"models.Account": {
3976-
"type": "object",
3977-
"properties": {
3978-
"balance": {
3979-
"description": "Balance of the account, including all transactions referencing it",
3980-
"type": "number",
3981-
"example": 2735.17
3982-
},
3983-
"budgetId": {
3984-
"description": "ID of the budget this account belongs to",
3985-
"type": "string",
3986-
"example": "550dc009-cea6-4c12-b2a5-03446eb7b7cf"
3987-
},
3988-
"createdAt": {
3989-
"description": "Time the resource was created",
3990-
"type": "string",
3991-
"example": "2022-04-02T19:28:44.491514Z"
3992-
},
3993-
"deletedAt": {
3994-
"description": "Time the resource was marked as deleted",
3995-
"type": "string",
3996-
"example": "2022-04-22T21:01:05.058161Z"
3997-
},
3998-
"external": {
3999-
"description": "Does the account belong to the budget owner or not?",
4000-
"type": "boolean",
4001-
"default": false,
4002-
"example": false
4003-
},
4004-
"hidden": {
4005-
"description": "Is the account archived?",
4006-
"type": "boolean",
4007-
"default": false,
4008-
"example": true
4009-
},
4010-
"id": {
4011-
"description": "UUID for the resource",
4012-
"type": "string",
4013-
"example": "65392deb-5e92-4268-b114-297faad6cdce"
4014-
},
4015-
"importHash": {
4016-
"description": "The SHA256 hash of a unique combination of values to use in duplicate detection",
4017-
"type": "string",
4018-
"example": "867e3a26dc0baf73f4bff506f31a97f6c32088917e9e5cf1a5ed6f3f84a6fa70"
4019-
},
4020-
"initialBalance": {
4021-
"description": "Balance of the account before any transactions were recorded",
4022-
"type": "number",
4023-
"default": 0,
4024-
"example": 173.12
4025-
},
4026-
"initialBalanceDate": {
4027-
"description": "Date of the initial balance",
4028-
"type": "string",
4029-
"example": "2017-05-12T00:00:00Z"
4030-
},
4031-
"links": {
4032-
"type": "object",
4033-
"properties": {
4034-
"self": {
4035-
"description": "The account itself",
4036-
"type": "string",
4037-
"example": "https://example.com/api/v1/accounts/af892e10-7e0a-4fb8-b1bc-4b6d88401ed2"
4038-
},
4039-
"transactions": {
4040-
"description": "Transactions referencing the account",
4041-
"type": "string",
4042-
"example": "https://example.com/api/v1/transactions?account=af892e10-7e0a-4fb8-b1bc-4b6d88401ed2"
4043-
}
4044-
}
4045-
},
4046-
"name": {
4047-
"description": "Name of the account",
4048-
"type": "string",
4049-
"example": "Cash"
4050-
},
4051-
"note": {
4052-
"description": "A longer description for the account",
4053-
"type": "string",
4054-
"example": "Money in my wallet"
4055-
},
4056-
"onBudget": {
4057-
"description": "Does the account factor into the available budget? Always false when external: true",
4058-
"type": "boolean",
4059-
"default": false,
4060-
"example": true
4061-
},
4062-
"recentEnvelopes": {
4063-
"description": "Envelopes recently used with this account",
4064-
"type": "array",
4065-
"items": {
4066-
"$ref": "#/definitions/models.Envelope"
4067-
}
4068-
},
4069-
"reconciledBalance": {
4070-
"description": "Balance of the account, including all reconciled transactions referencing it",
4071-
"type": "number",
4072-
"example": 2539.57
4073-
},
4074-
"updatedAt": {
4075-
"description": "Last time the resource was updated",
4076-
"type": "string",
4077-
"example": "2022-04-17T20:14:01.048145Z"
4078-
}
4079-
}
4080-
},
40814081
"models.AccountCreate": {
40824082
"type": "object",
40834083
"properties": {

0 commit comments

Comments
 (0)