Skip to content

Commit 378b475

Browse files
authored
feat: add months endpoints to API v3 (#882)
1 parent 762a502 commit 378b475

File tree

15 files changed

+2245
-217
lines changed

15 files changed

+2245
-217
lines changed

api/docs.go

Lines changed: 390 additions & 1 deletion
Large diffs are not rendered by default.

api/swagger.json

Lines changed: 390 additions & 1 deletion
Large diffs are not rendered by default.

api/swagger.yaml

Lines changed: 288 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,64 @@ definitions:
572572
example: the specified resource ID is not a valid UUID
573573
type: string
574574
type: object
575+
controllers.CategoryEnvelopesV3:
576+
properties:
577+
allocation:
578+
description: Sum of allocations for the envelopes
579+
example: 90
580+
type: number
581+
archived:
582+
default: false
583+
description: Is the Category archived?
584+
example: true
585+
type: boolean
586+
balance:
587+
description: Sum of the balances of the envelopes
588+
example: -10.13
589+
type: number
590+
budgetId:
591+
description: ID of the budget the category belongs to
592+
example: 52d967d3-33f4-4b04-9ba7-772e5ab9d0ce
593+
type: string
594+
createdAt:
595+
description: Time the resource was created
596+
example: "2022-04-02T19:28:44.491514Z"
597+
type: string
598+
deletedAt:
599+
description: Time the resource was marked as deleted
600+
example: "2022-04-22T21:01:05.058161Z"
601+
type: string
602+
envelopes:
603+
description: Slice of all envelopes
604+
items:
605+
$ref: '#/definitions/controllers.EnvelopeMonthV3'
606+
type: array
607+
hidden:
608+
default: false
609+
description: Is the category hidden?
610+
example: true
611+
type: boolean
612+
id:
613+
description: UUID for the resource
614+
example: 65392deb-5e92-4268-b114-297faad6cdce
615+
type: string
616+
name:
617+
description: Name of the category
618+
example: Saving
619+
type: string
620+
note:
621+
description: Notes about the category
622+
example: All envelopes for long-term saving
623+
type: string
624+
spent:
625+
description: Sum spent for all envelopes
626+
example: 100.13
627+
type: number
628+
updatedAt:
629+
description: Last time the resource was updated
630+
example: "2022-04-17T20:14:01.048145Z"
631+
type: string
632+
type: object
575633
controllers.CategoryListResponse:
576634
properties:
577635
data:
@@ -774,6 +832,59 @@ definitions:
774832
- $ref: '#/definitions/models.EnvelopeMonth'
775833
description: Data for the month for the envelope
776834
type: object
835+
controllers.EnvelopeMonthV3:
836+
properties:
837+
allocation:
838+
description: The amount of money allocated
839+
example: 85.44
840+
type: number
841+
archived:
842+
default: false
843+
description: Is the Envelope archived?
844+
example: true
845+
type: boolean
846+
balance:
847+
description: The balance at the end of the monht
848+
example: 12.32
849+
type: number
850+
categoryId:
851+
description: ID of the category the envelope belongs to
852+
example: 878c831f-af99-4a71-b3ca-80deb7d793c1
853+
type: string
854+
createdAt:
855+
description: Time the resource was created
856+
example: "2022-04-02T19:28:44.491514Z"
857+
type: string
858+
deletedAt:
859+
description: Time the resource was marked as deleted
860+
example: "2022-04-22T21:01:05.058161Z"
861+
type: string
862+
hidden:
863+
default: false
864+
description: Is the envelope hidden?
865+
example: true
866+
type: boolean
867+
id:
868+
description: UUID for the resource
869+
example: 65392deb-5e92-4268-b114-297faad6cdce
870+
type: string
871+
name:
872+
description: Name of the envelope
873+
example: Groceries
874+
type: string
875+
note:
876+
description: Notes about the envelope
877+
example: For stuff bought at supermarkets and drugstores
878+
type: string
879+
spent:
880+
description: The amount spent over the whole month
881+
example: 73.12
882+
type: number
883+
updatedAt:
884+
description: Last time the resource was updated
885+
example: "2022-04-17T20:14:01.048145Z"
886+
type: string
887+
type: object
777888
controllers.EnvelopeResponse:
778889
properties:
779890
data:
@@ -823,7 +934,7 @@ definitions:
823934
properties:
824935
month:
825936
description: The MonthConfig for the envelope
826-
example: https://example.com/api/v3/transactions?envelope=45b6b5b9-f746-4ae9-b77b-7688b91f8166/YYYY-MM
937+
example: https://example.com/api/v3/envelopes/45b6b5b9-f746-4ae9-b77b-7688b91f8166/YYYY-MM
827938
type: string
828939
self:
829940
description: The envelope itself
@@ -1155,6 +1266,57 @@ definitions:
11551266
- $ref: '#/definitions/models.Month'
11561267
description: Data for the month
11571268
type: object
1269+
controllers.MonthResponseV3:
1270+
properties:
1271+
data:
1272+
allOf:
1273+
- $ref: '#/definitions/controllers.MonthV3'
1274+
description: Data for the month
1275+
error:
1276+
description: The error, if any occurred
1277+
type: string
1278+
type: object
1279+
controllers.MonthV3:
1280+
properties:
1281+
allocation:
1282+
description: The sum of all allocations for this month
1283+
example: 1200.5
1284+
type: number
1285+
available:
1286+
description: The amount available to budget
1287+
example: 217.34
1288+
type: number
1289+
balance:
1290+
description: The sum of all envelope balances
1291+
example: 5231.37
1292+
type: number
1293+
categories:
1294+
description: A list of envelope month calculations grouped by category
1295+
items:
1296+
$ref: '#/definitions/controllers.CategoryEnvelopesV3'
1297+
type: array
1298+
id:
1299+
description: The ID of the Budget
1300+
example: 1e777d24-3f5b-4c43-8000-04f65f895578
1301+
type: string
1302+
income:
1303+
description: The total income for the month (sum of all incoming transactions
1304+
without an Envelope)
1305+
example: 2317.34
1306+
type: number
1307+
month:
1308+
description: The month
1309+
example: "2006-05-01T00:00:00.000000Z"
1310+
type: string
1311+
name:
1312+
description: The name of the Budget
1313+
example: Zero budget
1314+
type: string
1315+
spent:
1316+
description: The amount of money spent in this month
1317+
example: 133.7
1318+
type: number
1319+
type: object
11581320
controllers.Pagination:
11591321
properties:
11601322
count:
@@ -2211,6 +2373,10 @@ definitions:
22112373
description: URL of Match Rule collection endpoint
22122374
example: https://example.com/api/v3/match-rules
22132375
type: string
2376+
months:
2377+
description: URL of Month endpoint
2378+
example: https://example.com/api/v3/months
2379+
type: string
22142380
transactions:
22152381
description: URL of Transaction collection endpoint
22162382
example: https://example.com/api/v3/transactions
@@ -2286,6 +2452,7 @@ paths:
22862452
- General
22872453
/v1:
22882454
delete:
2455+
deprecated: true
22892456
description: Permanently deletes all resources
22902457
responses:
22912458
"204":
@@ -2298,6 +2465,7 @@ paths:
22982465
tags:
22992466
- v1
23002467
get:
2468+
deprecated: true
23012469
description: Returns general information about the v1 API
23022470
responses:
23032471
"200":
@@ -2308,6 +2476,7 @@ paths:
23082476
tags:
23092477
- v1
23102478
options:
2479+
deprecated: true
23112480
description: Returns an empty response with the HTTP Header "allow" set to the
23122481
allowed HTTP verbs
23132482
responses:
@@ -3947,6 +4116,7 @@ paths:
39474116
- MonthConfigs
39484117
/v1/months:
39494118
delete:
4119+
deprecated: true
39504120
description: Deletes all allocation for the specified month
39514121
parameters:
39524122
- description: ID formatted as string
@@ -3978,6 +4148,7 @@ paths:
39784148
tags:
39794149
- Months
39804150
get:
4151+
deprecated: true
39814152
description: Returns data about a specific month.
39824153
parameters:
39834154
- description: ID formatted as string
@@ -4013,6 +4184,7 @@ paths:
40134184
tags:
40144185
- Months
40154186
options:
4187+
deprecated: true
40164188
description: Returns an empty response with the HTTP Header "allow" set to the
40174189
allowed HTTP verbs.
40184190
responses:
@@ -4022,6 +4194,7 @@ paths:
40224194
tags:
40234195
- Months
40244196
post:
4197+
deprecated: true
40254198
description: Sets allocations for a month for all envelopes that do not have
40264199
an allocation yet
40274200
parameters:
@@ -6196,6 +6369,120 @@ paths:
61966369
summary: Update matchRule
61976370
tags:
61986371
- MatchRules
6372+
/v3/months:
6373+
delete:
6374+
description: Deletes all allocation for the specified month
6375+
parameters:
6376+
- description: ID formatted as string
6377+
in: query
6378+
name: budget
6379+
required: true
6380+
type: string
6381+
- description: The month in YYYY-MM format
6382+
in: query
6383+
name: month
6384+
required: true
6385+
type: string
6386+
responses:
6387+
"204":
6388+
description: No Content
6389+
"400":
6390+
description: Bad Request
6391+
schema:
6392+
$ref: '#/definitions/httperrors.HTTPError'
6393+
"404":
6394+
description: Not Found
6395+
schema:
6396+
$ref: '#/definitions/httperrors.HTTPError'
6397+
"500":
6398+
description: Internal Server Error
6399+
schema:
6400+
$ref: '#/definitions/httperrors.HTTPError'
6401+
summary: Delete allocations for a month
6402+
tags:
6403+
- Months
6404+
get:
6405+
description: Returns data about a specific month.
6406+
parameters:
6407+
- description: ID formatted as string
6408+
in: query
6409+
name: budget
6410+
required: true
6411+
type: string
6412+
- description: The month in YYYY-MM format
6413+
in: query
6414+
name: month
6415+
required: true
6416+
type: string
6417+
produces:
6418+
- application/json
6419+
responses:
6420+
"200":
6421+
description: OK
6422+
schema:
6423+
$ref: '#/definitions/controllers.MonthResponseV3'
6424+
"400":
6425+
description: Bad Request
6426+
schema:
6427+
$ref: '#/definitions/controllers.MonthResponseV3'
6428+
"404":
6429+
description: Not Found
6430+
schema:
6431+
$ref: '#/definitions/controllers.MonthResponseV3'
6432+
"500":
6433+
description: Internal Server Error
6434+
schema:
6435+
$ref: '#/definitions/controllers.MonthResponseV3'
6436+
summary: Get data about a month
6437+
tags:
6438+
- Months
6439+
options:
6440+
description: Returns an empty response with the HTTP Header "allow" set to the
6441+
allowed HTTP verbs.
6442+
responses:
6443+
"204":
6444+
description: No Content
6445+
summary: Allowed HTTP verbs
6446+
tags:
6447+
- Months
6448+
post:
6449+
description: Sets allocations for a month for all envelopes that do not have
6450+
an allocation yet
6451+
parameters:
6452+
- description: ID formatted as string
6453+
in: query
6454+
name: budget
6455+
required: true
6456+
type: string
6457+
- description: The month in YYYY-MM format
6458+
in: query
6459+
name: month
6460+
required: true
6461+
type: string
6462+
- description: Budget
6463+
in: body
6464+
name: mode
6465+
required: true
6466+
schema:
6467+
$ref: '#/definitions/controllers.BudgetAllocationMode'
6468+
responses:
6469+
"204":
6470+
description: No Content
6471+
"400":
6472+
description: Bad Request
6473+
schema:
6474+
$ref: '#/definitions/httperrors.HTTPError'
6475+
"404":
6476+
description: Not Found
6477+
schema:
6478+
$ref: '#/definitions/httperrors.HTTPError'
6479+
"500":
6480+
description: Internal Server Error
6481+
schema:
6482+
$ref: '#/definitions/httperrors.HTTPError'
6483+
summary: Set allocations for a month
6484+
tags:
6485+
- Months
61996486
/v3/transactions:
62006487
get:
62016488
description: Returns a list of transactions

pkg/controllers/cleanup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// @Success 204
1717
// @Failure 500 {object} httperrors.HTTPError
1818
// @Router /v1 [delete]
19+
// @Deprecated true
1920
func (co Controller) DeleteAll(c *gin.Context) {
2021
err := co.DB.Unscoped().Where("true").Delete(&models.Transaction{}).Error
2122
if err != nil {

0 commit comments

Comments
 (0)