Skip to content

Commit

Permalink
fix: rename hidden to archived
Browse files Browse the repository at this point in the history
As planned for API v3
  • Loading branch information
morremeyer committed Dec 2, 2023
1 parent da8a8a9 commit 2d68690
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3947,8 +3947,8 @@ const docTemplate = `{
},
{
"type": "boolean",
"description": "Is the account hidden?",
"name": "hidden",
"description": "Is the account archived?",
"name": "archived",
"in": "query"
},
{
Expand Down
4 changes: 2 additions & 2 deletions api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3936,8 +3936,8 @@
},
{
"type": "boolean",
"description": "Is the account hidden?",
"name": "hidden",
"description": "Is the account archived?",
"name": "archived",
"in": "query"
},
{
Expand Down
4 changes: 2 additions & 2 deletions api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4699,9 +4699,9 @@ paths:
in: query
name: external
type: boolean
- description: Is the account hidden?
- description: Is the account archived?
in: query
name: hidden
name: archived
type: boolean
- description: Search for this text in name and note
in: query
Expand Down
29 changes: 18 additions & 11 deletions pkg/controllers/account_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func (a *AccountV3) links(c *gin.Context) {
}

type AccountQueryFilterV3 struct {
Name string `form:"name" filterField:"false"` // Fuzzy filter for the account name
Note string `form:"note" filterField:"false"` // Fuzzy filter for the note
BudgetID string `form:"budget"` // By budget ID
OnBudget bool `form:"onBudget"` // Is the account on-budget?
External bool `form:"external"` // Is the account external?
Hidden bool `form:"hidden"` // Is the account hidden?
Search string `form:"search" filterField:"false"` // By string in name or note
Offset uint `form:"offset" filterField:"false"` // The offset of the first Transaction returned. Defaults to 0.
Limit int `form:"limit" filterField:"false"` // Maximum number of transactions to return. Defaults to 50.
Name string `form:"name" filterField:"false"` // Fuzzy filter for the account name
Note string `form:"note" filterField:"false"` // Fuzzy filter for the note
BudgetID string `form:"budget"` // By budget ID
OnBudget bool `form:"onBudget"` // Is the account on-budget?
External bool `form:"external"` // Is the account external?
Archived bool `form:"archived" filterField:"false"` // Is the account hidden?
Search string `form:"search" filterField:"false"` // By string in name or note
Offset uint `form:"offset" filterField:"false"` // The offset of the first Transaction returned. Defaults to 0.
Limit int `form:"limit" filterField:"false"` // Maximum number of transactions to return. Defaults to 50.
}

func (f AccountQueryFilterV3) ToCreate() (models.AccountCreate, httperrors.Error) {
Expand All @@ -73,7 +73,7 @@ func (f AccountQueryFilterV3) ToCreate() (models.AccountCreate, httperrors.Error
BudgetID: budgetID,
OnBudget: f.OnBudget,
External: f.External,
Hidden: f.Hidden,
Hidden: f.Archived,
}, httperrors.Error{}
}

Expand Down Expand Up @@ -256,7 +256,7 @@ func (co Controller) CreateAccountsV3(c *gin.Context) {
// @Param budget query string false "Filter by budget ID"
// @Param onBudget query bool false "Is the account on-budget?"
// @Param external query bool false "Is the account external?"
// @Param hidden query bool false "Is the account hidden?"
// @Param archived query bool false "Is the account archived?"
// @Param search query string false "Search for this text in name and note"
// @Param offset query uint false "The offset of the first Transaction returned. Defaults to 0."
// @Param limit query int false "Maximum number of transactions to return. Defaults to 50."
Expand All @@ -270,6 +270,13 @@ func (co Controller) GetAccountsV3(c *gin.Context) {
// Get the set parameters in the query string
queryFields, setFields := httputil.GetURLFields(c.Request.URL, filter)

// If the archived parameter is set, add "Hidden" to the query fields
// This is done since in v3, we're using the name "Archived", but the
// field is not yet updated in the database, which will happen later
if slices.Contains(setFields, "Archived") {
queryFields = append(queryFields, "Hidden")
}

// Convert the QueryFilter to a Create struct
create, err := filter.ToCreate()
if !err.Nil() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controllers/account_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (suite *TestSuiteStandard) TestAccountsV3GetFilter() {
{"Off budget", "onBudget=false", 4},
{"External", "external=true", 2},
{"Internal", "external=false", 3},
{"Not Hidden", "hidden=false", 3},
{"Hidden", "hidden=true", 2},
{"Not Archived", "archived=false", 3},
{"Archived", "archived=true", 2},
{"Search for 'na", "search=na", 3},
{"Search for 'fi", "search=fi", 4},
{"Offset 2", "offset=2", 3},
Expand Down

0 comments on commit 2d68690

Please sign in to comment.