Skip to content

Commit 869eb8b

Browse files
authored
feat: make ynab4 import available at /v1/import/ynab4 (#467)
1 parent e23ffb7 commit 869eb8b

File tree

5 files changed

+218
-2
lines changed

5 files changed

+218
-2
lines changed

api/docs.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,73 @@ const docTemplate = `{
17681768
}
17691769
},
17701770
"/v1/import": {
1771+
"post": {
1772+
"description": "Imports budgets from YNAB 4. **Please use /v1/import/ynab4, which works exactly the same.**",
1773+
"consumes": [
1774+
"multipart/form-data"
1775+
],
1776+
"produces": [
1777+
"application/json"
1778+
],
1779+
"tags": [
1780+
"Import"
1781+
],
1782+
"summary": "Import",
1783+
"deprecated": true,
1784+
"parameters": [
1785+
{
1786+
"type": "file",
1787+
"description": "File to import",
1788+
"name": "file",
1789+
"in": "formData",
1790+
"required": true
1791+
},
1792+
{
1793+
"type": "string",
1794+
"description": "Name of the Budget to create",
1795+
"name": "budgetName",
1796+
"in": "query"
1797+
}
1798+
],
1799+
"responses": {
1800+
"204": {
1801+
"description": "No Content"
1802+
},
1803+
"400": {
1804+
"description": "Bad Request",
1805+
"schema": {
1806+
"$ref": "#/definitions/httperrors.HTTPError"
1807+
}
1808+
},
1809+
"500": {
1810+
"description": "Internal Server Error",
1811+
"schema": {
1812+
"$ref": "#/definitions/httperrors.HTTPError"
1813+
}
1814+
}
1815+
}
1816+
},
1817+
"options": {
1818+
"description": "Returns an empty response with the HTTP Header \"allow\" set to the allowed HTTP verbs. **Please use /v1/import/ynab4, which works exactly the same.**",
1819+
"tags": [
1820+
"Import"
1821+
],
1822+
"summary": "Allowed HTTP verbs",
1823+
"deprecated": true,
1824+
"responses": {
1825+
"204": {
1826+
"description": "No Content"
1827+
},
1828+
"500": {
1829+
"description": "Internal Server Error",
1830+
"schema": {
1831+
"$ref": "#/definitions/httperrors.HTTPError"
1832+
}
1833+
}
1834+
}
1835+
}
1836+
},
1837+
"/v1/import/ynab4": {
17711838
"post": {
17721839
"description": "Imports budgets from YNAB 4",
17731840
"consumes": [

api/swagger.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,73 @@
17561756
}
17571757
},
17581758
"/v1/import": {
1759+
"post": {
1760+
"description": "Imports budgets from YNAB 4. **Please use /v1/import/ynab4, which works exactly the same.**",
1761+
"consumes": [
1762+
"multipart/form-data"
1763+
],
1764+
"produces": [
1765+
"application/json"
1766+
],
1767+
"tags": [
1768+
"Import"
1769+
],
1770+
"summary": "Import",
1771+
"deprecated": true,
1772+
"parameters": [
1773+
{
1774+
"type": "file",
1775+
"description": "File to import",
1776+
"name": "file",
1777+
"in": "formData",
1778+
"required": true
1779+
},
1780+
{
1781+
"type": "string",
1782+
"description": "Name of the Budget to create",
1783+
"name": "budgetName",
1784+
"in": "query"
1785+
}
1786+
],
1787+
"responses": {
1788+
"204": {
1789+
"description": "No Content"
1790+
},
1791+
"400": {
1792+
"description": "Bad Request",
1793+
"schema": {
1794+
"$ref": "#/definitions/httperrors.HTTPError"
1795+
}
1796+
},
1797+
"500": {
1798+
"description": "Internal Server Error",
1799+
"schema": {
1800+
"$ref": "#/definitions/httperrors.HTTPError"
1801+
}
1802+
}
1803+
}
1804+
},
1805+
"options": {
1806+
"description": "Returns an empty response with the HTTP Header \"allow\" set to the allowed HTTP verbs. **Please use /v1/import/ynab4, which works exactly the same.**",
1807+
"tags": [
1808+
"Import"
1809+
],
1810+
"summary": "Allowed HTTP verbs",
1811+
"deprecated": true,
1812+
"responses": {
1813+
"204": {
1814+
"description": "No Content"
1815+
},
1816+
"500": {
1817+
"description": "Internal Server Error",
1818+
"schema": {
1819+
"$ref": "#/definitions/httperrors.HTTPError"
1820+
}
1821+
}
1822+
}
1823+
}
1824+
},
1825+
"/v1/import/ynab4": {
17591826
"post": {
17601827
"description": "Imports budgets from YNAB 4",
17611828
"consumes": [

api/swagger.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,54 @@ paths:
19441944
tags:
19451945
- Envelopes
19461946
/v1/import:
1947+
options:
1948+
deprecated: true
1949+
description: Returns an empty response with the HTTP Header "allow" set to the
1950+
allowed HTTP verbs. **Please use /v1/import/ynab4, which works exactly the
1951+
same.**
1952+
responses:
1953+
"204":
1954+
description: No Content
1955+
"500":
1956+
description: Internal Server Error
1957+
schema:
1958+
$ref: '#/definitions/httperrors.HTTPError'
1959+
summary: Allowed HTTP verbs
1960+
tags:
1961+
- Import
1962+
post:
1963+
consumes:
1964+
- multipart/form-data
1965+
deprecated: true
1966+
description: Imports budgets from YNAB 4. **Please use /v1/import/ynab4, which
1967+
works exactly the same.**
1968+
parameters:
1969+
- description: File to import
1970+
in: formData
1971+
name: file
1972+
required: true
1973+
type: file
1974+
- description: Name of the Budget to create
1975+
in: query
1976+
name: budgetName
1977+
type: string
1978+
produces:
1979+
- application/json
1980+
responses:
1981+
"204":
1982+
description: No Content
1983+
"400":
1984+
description: Bad Request
1985+
schema:
1986+
$ref: '#/definitions/httperrors.HTTPError'
1987+
"500":
1988+
description: Internal Server Error
1989+
schema:
1990+
$ref: '#/definitions/httperrors.HTTPError'
1991+
summary: Import
1992+
tags:
1993+
- Import
1994+
/v1/import/ynab4:
19471995
options:
19481996
description: Returns an empty response with the HTTP Header "allow" set to the
19491997
allowed HTTP verbs

pkg/controllers/import.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,35 @@ func (co Controller) RegisterImportRoutes(r *gin.RouterGroup) {
2424
{
2525
r.OPTIONS("", co.OptionsImport)
2626
r.POST("", co.Import)
27+
28+
r.OPTIONS("/ynab4", co.OptionsImportYnab4)
29+
r.POST("/ynab4", co.ImportYnab4)
2730
}
2831
}
2932

3033
// @Summary Allowed HTTP verbs
31-
// @Description Returns an empty response with the HTTP Header "allow" set to the allowed HTTP verbs
34+
// @Description Returns an empty response with the HTTP Header "allow" set to the allowed HTTP verbs. **Please use /v1/import/ynab4, which works exactly the same.**
3235
// @Tags Import
3336
// @Success 204
3437
// @Failure 500 {object} httperrors.HTTPError
3538
// @Router /v1/import [options]
39+
// @Deprecated true
3640
func (co Controller) OptionsImport(c *gin.Context) {
3741
httputil.OptionsPost(c)
3842
}
3943

44+
// @Summary Allowed HTTP verbs
45+
// @Description Returns an empty response with the HTTP Header "allow" set to the allowed HTTP verbs
46+
// @Tags Import
47+
// @Success 204
48+
// @Failure 500 {object} httperrors.HTTPError
49+
// @Router /v1/import/ynab4 [options]
50+
func (co Controller) OptionsImportYnab4(c *gin.Context) {
51+
httputil.OptionsPost(c)
52+
}
53+
4054
// @Summary Import
41-
// @Description Imports budgets from YNAB 4
55+
// @Description Imports budgets from YNAB 4. **Please use /v1/import/ynab4, which works exactly the same.**
4256
// @Tags Import
4357
// @Accept multipart/form-data
4458
// @Produce json
@@ -48,7 +62,23 @@ func (co Controller) OptionsImport(c *gin.Context) {
4862
// @Param file formData file true "File to import"
4963
// @Param budgetName query string false "Name of the Budget to create"
5064
// @Router /v1/import [post]
65+
// @Deprecated true
5166
func (co Controller) Import(c *gin.Context) {
67+
co.ImportYnab4(c)
68+
}
69+
70+
// @Summary Import
71+
// @Description Imports budgets from YNAB 4
72+
// @Tags Import
73+
// @Accept multipart/form-data
74+
// @Produce json
75+
// @Success 204
76+
// @Failure 400 {object} httperrors.HTTPError
77+
// @Failure 500 {object} httperrors.HTTPError
78+
// @Param file formData file true "File to import"
79+
// @Param budgetName query string false "Name of the Budget to create"
80+
// @Router /v1/import/ynab4 [post]
81+
func (co Controller) ImportYnab4(c *gin.Context) {
5282
var query ImportQuery
5383
if err := c.BindQuery(&query); err != nil {
5484
httperrors.New(c, http.StatusBadRequest, "The budgetName parameter must be set")

pkg/controllers/import_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (suite *TestSuiteStandard) TestOptionsImport() {
4141
recorder := test.Request(suite.controller, suite.T(), http.MethodOptions, "http://example.com/v1/import", "")
4242
suite.Assert().Equal(http.StatusNoContent, recorder.Code, "Request ID %s", recorder.Header().Get("x-request-id"))
4343
suite.Assert().Equal(recorder.Header().Get("allow"), "OPTIONS, POST")
44+
45+
recorder = test.Request(suite.controller, suite.T(), http.MethodOptions, "http://example.com/v1/import/ynab4", "")
46+
suite.Assert().Equal(http.StatusNoContent, recorder.Code, "Request ID %s", recorder.Header().Get("x-request-id"))
47+
suite.Assert().Equal(recorder.Header().Get("allow"), "OPTIONS, POST")
4448
}
4549

4650
func (suite *TestSuiteStandard) TestImportFails() {

0 commit comments

Comments
 (0)