Skip to content

Commit 7567209

Browse files
committed
feat: add month-config resource and API endpoints
This new resource will group configurations that are specific for a month for a specific envelope. For now, it will only contain the overspend handling. Future versions will deprecate the Allocation resource in favor of this endpoint.
1 parent f06ecf7 commit 7567209

File tree

11 files changed

+1762
-14
lines changed

11 files changed

+1762
-14
lines changed

api/docs.go

Lines changed: 387 additions & 0 deletions
Large diffs are not rendered by default.

api/swagger.json

Lines changed: 387 additions & 0 deletions
Large diffs are not rendered by default.

api/swagger.yaml

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,52 @@ definitions:
325325
data:
326326
$ref: '#/definitions/controllers.Envelope'
327327
type: object
328+
controllers.MonthConfig:
329+
properties:
330+
createdAt:
331+
example: "2022-04-02T19:28:44.491514Z"
332+
type: string
333+
deletedAt:
334+
example: "2022-04-22T21:01:05.058161Z"
335+
type: string
336+
envelopeId:
337+
example: 10b9705d-3356-459e-9d5a-28d42a6c4547
338+
type: string
339+
links:
340+
$ref: '#/definitions/controllers.MonthConfigLinks'
341+
month:
342+
description: This is always set to 00:00 UTC on the first of the month.
343+
example: "1969-06-01T00:00:00.000000Z"
344+
type: string
345+
overspendMode:
346+
default: AFFECT_AVAILABLE
347+
example: AFFECT_ENVELOPE
348+
type: string
349+
updatedAt:
350+
example: "2022-04-17T20:14:01.048145Z"
351+
type: string
352+
type: object
353+
controllers.MonthConfigLinks:
354+
properties:
355+
envelope:
356+
example: https://example.com/api/v1/envelopes/61027ebb-ab75-4a49-9e23-a104ddd9ba6b
357+
type: string
358+
self:
359+
example: https://example.com/api/v1/month-configs/61027ebb-ab75-4a49-9e23-a104ddd9ba6b/2017-10
360+
type: string
361+
type: object
362+
controllers.MonthConfigListResponse:
363+
properties:
364+
data:
365+
items:
366+
$ref: '#/definitions/controllers.MonthConfig'
367+
type: array
368+
type: object
369+
controllers.MonthConfigResponse:
370+
properties:
371+
data:
372+
$ref: '#/definitions/controllers.MonthConfig'
373+
type: object
328374
controllers.MonthResponse:
329375
properties:
330376
data:
@@ -606,6 +652,13 @@ definitions:
606652
example: Zero budget
607653
type: string
608654
type: object
655+
models.MonthConfigCreate:
656+
properties:
657+
overspendMode:
658+
default: AFFECT_AVAILABLE
659+
example: AFFECT_ENVELOPE
660+
type: string
661+
type: object
609662
models.TransactionCreate:
610663
properties:
611664
amount:
@@ -1938,6 +1991,216 @@ paths:
19381991
summary: Import
19391992
tags:
19401993
- Import
1994+
/v1/month-configs:
1995+
get:
1996+
description: Returns a list of MonthConfigs
1997+
parameters:
1998+
- description: Filter by name
1999+
in: query
2000+
name: envelope
2001+
type: string
2002+
- description: Filter by month
2003+
in: query
2004+
name: month
2005+
type: string
2006+
produces:
2007+
- application/json
2008+
responses:
2009+
"200":
2010+
description: OK
2011+
schema:
2012+
$ref: '#/definitions/controllers.MonthConfigListResponse'
2013+
"400":
2014+
description: Bad Request
2015+
schema:
2016+
$ref: '#/definitions/httperrors.HTTPError'
2017+
"404":
2018+
description: Not Found
2019+
schema:
2020+
$ref: '#/definitions/httperrors.HTTPError'
2021+
"500":
2022+
description: Internal Server Error
2023+
schema:
2024+
$ref: '#/definitions/httperrors.HTTPError'
2025+
summary: List MonthConfigs
2026+
tags:
2027+
- MonthConfigs
2028+
options:
2029+
description: Returns an empty response with the HTTP Header "allow" set to the
2030+
allowed HTTP verbs.
2031+
responses:
2032+
"204":
2033+
description: No Content
2034+
summary: Allowed HTTP verbs
2035+
tags:
2036+
- MonthConfigs
2037+
/v1/month-configs/{envelopeId}/{month}:
2038+
delete:
2039+
description: Deletes configuration settings for a specific month
2040+
parameters:
2041+
- description: ID of the Envelope
2042+
in: path
2043+
name: envelopeId
2044+
required: true
2045+
type: string
2046+
- description: The month in YYYY-MM format
2047+
in: path
2048+
name: month
2049+
required: true
2050+
type: string
2051+
produces:
2052+
- application/json
2053+
responses:
2054+
"204":
2055+
description: No Content
2056+
"400":
2057+
description: Bad Request
2058+
schema:
2059+
$ref: '#/definitions/httperrors.HTTPError'
2060+
"404":
2061+
description: Not Found
2062+
schema:
2063+
$ref: '#/definitions/httperrors.HTTPError'
2064+
summary: Delete MonthConfig
2065+
tags:
2066+
- MonthConfigs
2067+
get:
2068+
description: Returns configuration for a specific month
2069+
parameters:
2070+
- description: ID of the Envelope
2071+
in: path
2072+
name: envelopeId
2073+
required: true
2074+
type: string
2075+
- description: The month in YYYY-MM format
2076+
in: path
2077+
name: month
2078+
required: true
2079+
type: string
2080+
produces:
2081+
- application/json
2082+
responses:
2083+
"200":
2084+
description: OK
2085+
schema:
2086+
$ref: '#/definitions/controllers.MonthConfigResponse'
2087+
"400":
2088+
description: Bad Request
2089+
schema:
2090+
$ref: '#/definitions/httperrors.HTTPError'
2091+
"404":
2092+
description: Not Found
2093+
schema:
2094+
$ref: '#/definitions/httperrors.HTTPError'
2095+
summary: Get MonthConfig
2096+
tags:
2097+
- MonthConfigs
2098+
options:
2099+
description: Returns an empty response with the HTTP Header "allow" set to the
2100+
allowed HTTP verbs
2101+
parameters:
2102+
- description: ID of the Envelope
2103+
in: path
2104+
name: envelopeId
2105+
required: true
2106+
type: string
2107+
- description: The month in YYYY-MM format
2108+
in: path
2109+
name: month
2110+
required: true
2111+
type: string
2112+
responses:
2113+
"204":
2114+
description: No Content
2115+
"400":
2116+
description: Bad Request
2117+
schema:
2118+
$ref: '#/definitions/httperrors.HTTPError'
2119+
"404":
2120+
description: Not Found
2121+
schema:
2122+
$ref: '#/definitions/httperrors.HTTPError'
2123+
summary: Allowed HTTP verbs
2124+
tags:
2125+
- MonthConfigs
2126+
patch:
2127+
description: Creates a new MonthConfig
2128+
parameters:
2129+
- description: ID of the Envelope
2130+
in: path
2131+
name: envelopeId
2132+
required: true
2133+
type: string
2134+
- description: The month in YYYY-MM format
2135+
in: path
2136+
name: month
2137+
required: true
2138+
type: string
2139+
- description: MonthConfig
2140+
in: body
2141+
name: monthConfig
2142+
required: true
2143+
schema:
2144+
$ref: '#/definitions/models.MonthConfigCreate'
2145+
produces:
2146+
- application/json
2147+
responses:
2148+
"201":
2149+
description: Created
2150+
schema:
2151+
$ref: '#/definitions/controllers.MonthConfigResponse'
2152+
"400":
2153+
description: Bad Request
2154+
schema:
2155+
$ref: '#/definitions/httperrors.HTTPError'
2156+
"500":
2157+
description: Internal Server Error
2158+
schema:
2159+
$ref: '#/definitions/httperrors.HTTPError'
2160+
summary: Create MonthConfig
2161+
tags:
2162+
- MonthConfigs
2163+
post:
2164+
description: Creates a new MonthConfig
2165+
parameters:
2166+
- description: ID of the Envelope
2167+
in: path
2168+
name: envelopeId
2169+
required: true
2170+
type: string
2171+
- description: The month in YYYY-MM format
2172+
in: path
2173+
name: month
2174+
required: true
2175+
type: string
2176+
- description: MonthConfig
2177+
in: body
2178+
name: monthConfig
2179+
required: true
2180+
schema:
2181+
$ref: '#/definitions/models.MonthConfigCreate'
2182+
produces:
2183+
- application/json
2184+
responses:
2185+
"201":
2186+
description: Created
2187+
schema:
2188+
$ref: '#/definitions/controllers.MonthConfigResponse'
2189+
"400":
2190+
description: Bad Request
2191+
schema:
2192+
$ref: '#/definitions/httperrors.HTTPError'
2193+
"404":
2194+
description: Not Found
2195+
schema:
2196+
$ref: '#/definitions/httperrors.HTTPError'
2197+
"500":
2198+
description: Internal Server Error
2199+
schema:
2200+
$ref: '#/definitions/httperrors.HTTPError'
2201+
summary: Create MonthConfig
2202+
tags:
2203+
- MonthConfigs
19412204
/v1/months:
19422205
delete:
19432206
description: Deletes all allocation for the specified month

pkg/controllers/month.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type MonthResponse struct {
2323
// the budget resource itself.
2424
func (co Controller) parseMonthQuery(c *gin.Context) (time.Time, models.Budget, bool) {
2525
var query struct {
26-
Month time.Time `form:"month" time_format:"2006-01" time_utc:"1" example:"2022-07"`
27-
BudgetID string `form:"budget" example:"81b0c9ce-6fd3-4e1e-becc-106055898a2a"`
26+
QueryMonth
27+
BudgetID string `form:"budget" example:"81b0c9ce-6fd3-4e1e-becc-106055898a2a"`
2828
}
2929

3030
if err := c.Bind(&query); err != nil {

0 commit comments

Comments
 (0)