Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: MonthConfigs #441

Merged
merged 3 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion pkg/controllers/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (co Controller) getAccountResource(c *gin.Context, id uuid.UUID) (models.Ac
var account models.Account

if !queryWithRetry(c, co.DB.Where(&models.Account{
Model: models.Model{
DefaultModel: models.DefaultModel{
ID: id,
},
}).First(&account), "No account found for the specified ID") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (co Controller) getAllocationResource(c *gin.Context, id uuid.UUID) (models
var allocation models.Allocation

if !queryWithRetry(c, co.DB.First(&allocation, &models.Allocation{
Model: models.Model{
DefaultModel: models.DefaultModel{
ID: id,
},
}), "No allocation found for the specified ID") {
Expand Down
5 changes: 2 additions & 3 deletions pkg/controllers/budget.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func (co Controller) CreateBudget(c *gin.Context) {
// @Success 200 {object} BudgetListResponse
// @Failure 500 {object} httperrors.HTTPError
// @Router /v1/budgets [get]
// @Router /v1/budgets [get]
// @Param name query string false "Filter by name"
// @Param note query string false "Filter by note"
// @Param currency query string false "Filter by currency"
Expand Down Expand Up @@ -592,7 +591,7 @@ func (co Controller) SetAllocationsMonth(c *gin.Context) {
// If the mode is the spend of last month, calculate and set it
amount := allocation.Amount
if data.Mode == AllocateLastMonthSpend {
amount = models.Envelope{Model: models.Model{ID: allocation.EnvelopeID}}.Spent(co.DB, pastMonth)
amount = models.Envelope{DefaultModel: models.DefaultModel{ID: allocation.EnvelopeID}}.Spent(co.DB, pastMonth)
}

if !queryWithRetry(c, co.DB.Create(&models.Allocation{
Expand Down Expand Up @@ -621,7 +620,7 @@ func (co Controller) getBudgetResource(c *gin.Context, id uuid.UUID) (models.Bud
var budget models.Budget

if !queryWithRetry(c, co.DB.Where(&models.Budget{
Model: models.Model{
DefaultModel: models.DefaultModel{
ID: id,
},
}).First(&budget), "No budget found for the specified ID") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (co Controller) getCategoryResource(c *gin.Context, id uuid.UUID) (models.C
var category models.Category

if !queryWithRetry(c, co.DB.Where(&models.Category{
Model: models.Model{
DefaultModel: models.DefaultModel{
ID: id,
},
}).First(&category), "No category found for the specified ID") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (co Controller) getEnvelopeResource(c *gin.Context, id uuid.UUID) (models.E
var envelope models.Envelope

if !queryWithRetry(c, co.DB.Where(&models.Envelope{
Model: models.Model{
DefaultModel: models.DefaultModel{
ID: id,
},
}).First(&envelope), "No envelope found for the specified ID") {
Expand Down
6 changes: 3 additions & 3 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 Expand Up @@ -268,7 +268,7 @@ func (co Controller) SetAllocations(c *gin.Context) {
// If the mode is the spend of last month, calculate and set it
amount := allocation.Amount
if data.Mode == AllocateLastMonthSpend {
amount = models.Envelope{Model: models.Model{ID: allocation.EnvelopeID}}.Spent(co.DB, pastMonth)
amount = models.Envelope{DefaultModel: models.DefaultModel{ID: allocation.EnvelopeID}}.Spent(co.DB, pastMonth)
}

if !queryWithRetry(c, co.DB.Create(&models.Allocation{
Expand Down
Loading