Skip to content

Commit

Permalink
feat: add month-config resource and API endpoints
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
morremeyer committed Nov 7, 2022
1 parent c05bd33 commit 75db336
Show file tree
Hide file tree
Showing 11 changed files with 1,762 additions and 14 deletions.
387 changes: 387 additions & 0 deletions api/docs.go

Large diffs are not rendered by default.

387 changes: 387 additions & 0 deletions api/swagger.json

Large diffs are not rendered by default.

263 changes: 263 additions & 0 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,52 @@ definitions:
data:
$ref: '#/definitions/controllers.Envelope'
type: object
controllers.MonthConfig:
properties:
createdAt:
example: "2022-04-02T19:28:44.491514Z"
type: string
deletedAt:
example: "2022-04-22T21:01:05.058161Z"
type: string
envelopeId:
example: 10b9705d-3356-459e-9d5a-28d42a6c4547
type: string
links:
$ref: '#/definitions/controllers.MonthConfigLinks'
month:
description: This is always set to 00:00 UTC on the first of the month.
example: "1969-06-01T00:00:00.000000Z"
type: string
overspendMode:
default: AFFECT_AVAILABLE
example: AFFECT_ENVELOPE
type: string
updatedAt:
example: "2022-04-17T20:14:01.048145Z"
type: string
type: object
controllers.MonthConfigLinks:
properties:
envelope:
example: https://example.com/api/v1/envelopes/61027ebb-ab75-4a49-9e23-a104ddd9ba6b
type: string
self:
example: https://example.com/api/v1/month-configs/61027ebb-ab75-4a49-9e23-a104ddd9ba6b/2017-10
type: string
type: object
controllers.MonthConfigListResponse:
properties:
data:
items:
$ref: '#/definitions/controllers.MonthConfig'
type: array
type: object
controllers.MonthConfigResponse:
properties:
data:
$ref: '#/definitions/controllers.MonthConfig'
type: object
controllers.MonthResponse:
properties:
data:
Expand Down Expand Up @@ -606,6 +652,13 @@ definitions:
example: Zero budget
type: string
type: object
models.MonthConfigCreate:
properties:
overspendMode:
default: AFFECT_AVAILABLE
example: AFFECT_ENVELOPE
type: string
type: object
models.TransactionCreate:
properties:
amount:
Expand Down Expand Up @@ -1938,6 +1991,216 @@ paths:
summary: Import
tags:
- Import
/v1/month-configs:
get:
description: Returns a list of MonthConfigs
parameters:
- description: Filter by name
in: query
name: envelope
type: string
- description: Filter by month
in: query
name: month
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.MonthConfigListResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/httperrors.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/httperrors.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/httperrors.HTTPError'
summary: List MonthConfigs
tags:
- MonthConfigs
options:
description: Returns an empty response with the HTTP Header "allow" set to the
allowed HTTP verbs.
responses:
"204":
description: No Content
summary: Allowed HTTP verbs
tags:
- MonthConfigs
/v1/month-configs/{envelopeId}/{month}:
delete:
description: Deletes configuration settings for a specific month
parameters:
- description: ID of the Envelope
in: path
name: envelopeId
required: true
type: string
- description: The month in YYYY-MM format
in: path
name: month
required: true
type: string
produces:
- application/json
responses:
"204":
description: No Content
"400":
description: Bad Request
schema:
$ref: '#/definitions/httperrors.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/httperrors.HTTPError'
summary: Delete MonthConfig
tags:
- MonthConfigs
get:
description: Returns configuration for a specific month
parameters:
- description: ID of the Envelope
in: path
name: envelopeId
required: true
type: string
- description: The month in YYYY-MM format
in: path
name: month
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/controllers.MonthConfigResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/httperrors.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/httperrors.HTTPError'
summary: Get MonthConfig
tags:
- MonthConfigs
options:
description: Returns an empty response with the HTTP Header "allow" set to the
allowed HTTP verbs
parameters:
- description: ID of the Envelope
in: path
name: envelopeId
required: true
type: string
- description: The month in YYYY-MM format
in: path
name: month
required: true
type: string
responses:
"204":
description: No Content
"400":
description: Bad Request
schema:
$ref: '#/definitions/httperrors.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/httperrors.HTTPError'
summary: Allowed HTTP verbs
tags:
- MonthConfigs
patch:
description: Creates a new MonthConfig
parameters:
- description: ID of the Envelope
in: path
name: envelopeId
required: true
type: string
- description: The month in YYYY-MM format
in: path
name: month
required: true
type: string
- description: MonthConfig
in: body
name: monthConfig
required: true
schema:
$ref: '#/definitions/models.MonthConfigCreate'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/controllers.MonthConfigResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/httperrors.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/httperrors.HTTPError'
summary: Create MonthConfig
tags:
- MonthConfigs
post:
description: Creates a new MonthConfig
parameters:
- description: ID of the Envelope
in: path
name: envelopeId
required: true
type: string
- description: The month in YYYY-MM format
in: path
name: month
required: true
type: string
- description: MonthConfig
in: body
name: monthConfig
required: true
schema:
$ref: '#/definitions/models.MonthConfigCreate'
produces:
- application/json
responses:
"201":
description: Created
schema:
$ref: '#/definitions/controllers.MonthConfigResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/httperrors.HTTPError'
"404":
description: Not Found
schema:
$ref: '#/definitions/httperrors.HTTPError'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/httperrors.HTTPError'
summary: Create MonthConfig
tags:
- MonthConfigs
/v1/months:
delete:
description: Deletes all allocation for the specified month
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/month.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type MonthResponse struct {
// the budget resource itself.
func (co Controller) parseMonthQuery(c *gin.Context) (time.Time, models.Budget, bool) {
var query struct {
Month time.Time `form:"month" time_format:"2006-01" time_utc:"1" example:"2022-07"`
BudgetID string `form:"budget" example:"81b0c9ce-6fd3-4e1e-becc-106055898a2a"`
QueryMonth
BudgetID string `form:"budget" example:"81b0c9ce-6fd3-4e1e-becc-106055898a2a"`
}

if err := c.Bind(&query); err != nil {
Expand Down
Loading

0 comments on commit 75db336

Please sign in to comment.