Skip to content

Commit 86ec4cb

Browse files
authored
feat: add /v3/budgets endpoints (#858)
1 parent fb87739 commit 86ec4cb

20 files changed

+1984
-63
lines changed

api/docs.go

Lines changed: 415 additions & 3 deletions
Large diffs are not rendered by default.

api/swagger.json

Lines changed: 415 additions & 3 deletions
Large diffs are not rendered by default.

api/swagger.yaml

Lines changed: 289 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,18 @@ definitions:
249249
description: Mode to allocate budget with
250250
example: ALLOCATE_LAST_MONTH_SPEND
251251
type: object
252+
controllers.BudgetCreateResponseV3:
253+
properties:
254+
data:
255+
description: List of created Budgets
256+
items:
257+
$ref: '#/definitions/controllers.BudgetResponseV3'
258+
type: array
259+
error:
260+
description: The error, if any occurred
261+
example: the specified resource ID is not a valid UUID
262+
type: string
263+
type: object
252264
controllers.BudgetListResponse:
253265
properties:
254266
data:
@@ -257,6 +269,22 @@ definitions:
257269
$ref: '#/definitions/controllers.Budget'
258270
type: array
259271
type: object
272+
controllers.BudgetListResponseV3:
273+
properties:
274+
data:
275+
description: List of budgets
276+
items:
277+
$ref: '#/definitions/controllers.BudgetV3'
278+
type: array
279+
error:
280+
description: The error, if any occurred
281+
example: the specified resource ID is not a valid UUID
282+
type: string
283+
pagination:
284+
allOf:
285+
- $ref: '#/definitions/controllers.Pagination'
286+
description: Pagination information
287+
type: object
260288
controllers.BudgetMonthResponse:
261289
properties:
262290
data:
@@ -275,13 +303,72 @@ definitions:
275303
properties:
276304
data:
277305
allOf:
278-
- $ref: '#/definitions/controllers.Budget'
306+
- $ref: '#/definitions/controllers.BudgetV3'
279307
description: Data for the budget
280308
error:
281309
description: The error, if any occurred
282310
example: the specified resource ID is not a valid UUID
283311
type: string
284312
type: object
313+
controllers.BudgetV3:
314+
properties:
315+
createdAt:
316+
description: Time the resource was created
317+
example: "2022-04-02T19:28:44.491514Z"
318+
type: string
319+
currency:
320+
description: The currency for the budget
321+
example:
322+
type: string
323+
deletedAt:
324+
description: Time the resource was marked as deleted
325+
example: "2022-04-22T21:01:05.058161Z"
326+
type: string
327+
id:
328+
description: UUID for the resource
329+
example: 65392deb-5e92-4268-b114-297faad6cdce
330+
type: string
331+
links:
332+
properties:
333+
accounts:
334+
description: Accounts for this budget
335+
example: https://example.com/api/v3/accounts?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf
336+
type: string
337+
categories:
338+
description: Categories for this budget
339+
example: https://example.com/api/v3/categories?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf
340+
type: string
341+
envelopes:
342+
description: Envelopes for this budget
343+
example: https://example.com/api/v3/envelopes?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf
344+
type: string
345+
month:
346+
description: This uses 'YYYY-MM' for clients to replace with the actual
347+
year and month.
348+
example: https://example.com/api/v3/months?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf&month=YYYY-MM
349+
type: string
350+
self:
351+
description: The budget itself
352+
example: https://example.com/api/v3/budgets/550dc009-cea6-4c12-b2a5-03446eb7b7cf
353+
type: string
354+
transactions:
355+
description: Transactions for this budget
356+
example: https://example.com/api/v3/transactions?budget=550dc009-cea6-4c12-b2a5-03446eb7b7cf
357+
type: string
358+
type: object
359+
name:
360+
description: Name of the budget
361+
example: Morre's Budget
362+
type: string
363+
note:
364+
description: A longer description of the budget
365+
example: My personal expenses
366+
type: string
367+
updatedAt:
368+
description: Last time the resource was updated
369+
example: "2022-04-17T20:14:01.048145Z"
370+
type: string
371+
type: object
285372
controllers.Category:
286373
properties:
287374
budgetId:
@@ -796,7 +883,7 @@ definitions:
796883
controllers.TransactionCreateResponseV3:
797884
properties:
798885
data:
799-
description: List of created transactions
886+
description: List of created Transactions
800887
items:
801888
$ref: '#/definitions/controllers.TransactionResponseV3'
802889
type: array
@@ -841,7 +928,7 @@ definitions:
841928
data:
842929
allOf:
843930
- $ref: '#/definitions/controllers.TransactionV3'
844-
description: The transaction data, if creation was successful
931+
description: The Transaction data, if creation was successful
845932
error:
846933
description: The error, if any occurred for this transaction
847934
example: the specified resource ID is not a valid UUID
@@ -1644,6 +1731,10 @@ definitions:
16441731
type: object
16451732
router.V3Links:
16461733
properties:
1734+
budgets:
1735+
description: URL of Budget collection endpoint
1736+
example: https://example.com/api/v3/budgets
1737+
type: string
16471738
import:
16481739
description: URL of import list endpoint
16491740
example: https://example.com/api/v3/import
@@ -4296,6 +4387,201 @@ paths:
42964387
summary: Allowed HTTP verbs
42974388
tags:
42984389
- v3
4390+
/v3/budgets:
4391+
get:
4392+
description: Returns a list of budgets
4393+
parameters:
4394+
- description: Filter by name
4395+
in: query
4396+
name: name
4397+
type: string
4398+
- description: Filter by note
4399+
in: query
4400+
name: note
4401+
type: string
4402+
- description: Filter by currency
4403+
in: query
4404+
name: currency
4405+
type: string
4406+
- description: Search for this text in name and note
4407+
in: query
4408+
name: search
4409+
type: string
4410+
produces:
4411+
- application/json
4412+
responses:
4413+
"200":
4414+
description: OK
4415+
schema:
4416+
$ref: '#/definitions/controllers.BudgetListResponseV3'
4417+
"500":
4418+
description: Internal Server Error
4419+
schema:
4420+
$ref: '#/definitions/controllers.BudgetListResponseV3'
4421+
summary: List budgets
4422+
tags:
4423+
- Budgets
4424+
options:
4425+
description: Returns an empty response with the HTTP Header "allow" set to the
4426+
allowed HTTP verbs
4427+
responses:
4428+
"204":
4429+
description: No Content
4430+
summary: Allowed HTTP verbs
4431+
tags:
4432+
- Budgets
4433+
post:
4434+
consumes:
4435+
- application/json
4436+
description: Creates a new budget
4437+
parameters:
4438+
- description: Budget
4439+
in: body
4440+
name: budget
4441+
required: true
4442+
schema:
4443+
$ref: '#/definitions/models.BudgetCreate'
4444+
produces:
4445+
- application/json
4446+
responses:
4447+
"201":
4448+
description: Created
4449+
schema:
4450+
$ref: '#/definitions/controllers.BudgetCreateResponseV3'
4451+
"400":
4452+
description: Bad Request
4453+
schema:
4454+
$ref: '#/definitions/controllers.BudgetCreateResponseV3'
4455+
"500":
4456+
description: Internal Server Error
4457+
schema:
4458+
$ref: '#/definitions/controllers.BudgetCreateResponseV3'
4459+
summary: Create budget
4460+
tags:
4461+
- Budgets
4462+
/v3/budgets/{id}:
4463+
delete:
4464+
description: Deletes a budget
4465+
parameters:
4466+
- description: ID formatted as string
4467+
in: path
4468+
name: id
4469+
required: true
4470+
type: string
4471+
responses:
4472+
"204":
4473+
description: No Content
4474+
"400":
4475+
description: Bad Request
4476+
schema:
4477+
$ref: '#/definitions/httperrors.HTTPError'
4478+
"404":
4479+
description: Not Found
4480+
schema:
4481+
$ref: '#/definitions/httperrors.HTTPError'
4482+
"500":
4483+
description: Internal Server Error
4484+
schema:
4485+
$ref: '#/definitions/httperrors.HTTPError'
4486+
summary: Delete budget
4487+
tags:
4488+
- Budgets
4489+
get:
4490+
description: Returns a specific budget
4491+
parameters:
4492+
- description: ID formatted as string
4493+
in: path
4494+
name: id
4495+
required: true
4496+
type: string
4497+
produces:
4498+
- application/json
4499+
responses:
4500+
"200":
4501+
description: OK
4502+
schema:
4503+
$ref: '#/definitions/controllers.BudgetResponseV3'
4504+
"400":
4505+
description: Bad Request
4506+
schema:
4507+
$ref: '#/definitions/controllers.BudgetResponseV3'
4508+
"404":
4509+
description: Not Found
4510+
schema:
4511+
$ref: '#/definitions/controllers.BudgetResponseV3'
4512+
"500":
4513+
description: Internal Server Error
4514+
schema:
4515+
$ref: '#/definitions/controllers.BudgetResponseV3'
4516+
summary: Get budget
4517+
tags:
4518+
- Budgets
4519+
options:
4520+
description: Returns an empty response with the HTTP Header "allow" set to the
4521+
allowed HTTP verbs
4522+
parameters:
4523+
- description: ID formatted as string
4524+
in: path
4525+
name: id
4526+
required: true
4527+
type: string
4528+
responses:
4529+
"204":
4530+
description: No Content
4531+
"400":
4532+
description: Bad Request
4533+
schema:
4534+
$ref: '#/definitions/httperrors.HTTPError'
4535+
"404":
4536+
description: Not Found
4537+
schema:
4538+
$ref: '#/definitions/httperrors.HTTPError'
4539+
"500":
4540+
description: Internal Server Error
4541+
schema:
4542+
$ref: '#/definitions/httperrors.HTTPError'
4543+
summary: Allowed HTTP verbs
4544+
tags:
4545+
- Budgets
4546+
patch:
4547+
consumes:
4548+
- application/json
4549+
description: Update an existing budget. Only values to be updated need to be
4550+
specified.
4551+
parameters:
4552+
- description: ID formatted as string
4553+
in: path
4554+
name: id
4555+
required: true
4556+
type: string
4557+
- description: Budget
4558+
in: body
4559+
name: budget
4560+
required: true
4561+
schema:
4562+
$ref: '#/definitions/models.BudgetCreate'
4563+
produces:
4564+
- application/json
4565+
responses:
4566+
"200":
4567+
description: OK
4568+
schema:
4569+
$ref: '#/definitions/controllers.BudgetResponseV3'
4570+
"400":
4571+
description: Bad Request
4572+
schema:
4573+
$ref: '#/definitions/controllers.BudgetResponseV3'
4574+
"404":
4575+
description: Not Found
4576+
schema:
4577+
$ref: '#/definitions/controllers.BudgetResponseV3'
4578+
"500":
4579+
description: Internal Server Error
4580+
schema:
4581+
$ref: '#/definitions/controllers.BudgetResponseV3'
4582+
summary: Update budget
4583+
tags:
4584+
- Budgets
42994585
/v3/import:
43004586
get:
43014587
description: Returns general information about the v3 API

pkg/controllers/budget.go renamed to pkg/controllers/budget_v1.go

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import (
1414
"github.com/shopspring/decimal"
1515
)
1616

17+
type BudgetQueryFilter struct {
18+
Name string `form:"name" filterField:"false"` // By name
19+
Note string `form:"note" filterField:"false"` // By note
20+
Currency string `form:"currency"` // By currency
21+
Search string `form:"search" filterField:"false"` // By string in name or note
22+
}
23+
1724
// Budget is the API v1 representation of a Budget.
1825
type Budget struct {
1926
models.Budget
@@ -74,34 +81,10 @@ type BudgetResponse struct {
7481
Data Budget `json:"data"` // Data for the budget
7582
}
7683

77-
type BudgetResponseV3 struct {
78-
Data *Budget `json:"data"` // Data for the budget
79-
Error *string `json:"error" example:"the specified resource ID is not a valid UUID"` // The error, if any occurred
80-
}
81-
8284
type BudgetMonthResponse struct {
8385
Data models.BudgetMonth `json:"data"` // Data for the budget's month
8486
}
8587

86-
type BudgetQueryFilter struct {
87-
Name string `form:"name" filterField:"false"` // By name
88-
Note string `form:"note" filterField:"false"` // By note
89-
Currency string `form:"currency"` // By currency
90-
Search string `form:"search" filterField:"false"` // By string in name or note
91-
}
92-
93-
// swagger:enum AllocationMode
94-
type AllocationMode string
95-
96-
const (
97-
AllocateLastMonthBudget AllocationMode = "ALLOCATE_LAST_MONTH_BUDGET"
98-
AllocateLastMonthSpend AllocationMode = "ALLOCATE_LAST_MONTH_SPEND"
99-
)
100-
101-
type BudgetAllocationMode struct {
102-
Mode AllocationMode `json:"mode" example:"ALLOCATE_LAST_MONTH_SPEND"` // Mode to allocate budget with
103-
}
104-
10588
// RegisterBudgetRoutes registers the routes for budgets with
10689
// the RouterGroup that is passed.
10790
func (co Controller) RegisterBudgetRoutes(r *gin.RouterGroup) {
File renamed without changes.

0 commit comments

Comments
 (0)