Skip to content

Commit d33c03d

Browse files
authored
fix!: prevent duplicate accounts names (#753)
Duplicate account names are confusing, which is why we don't want them. BREAKING CHANGE: With this change, account names must be unique for every budget. Existing duplicate account names are updated automatically with a number to make them unique.
1 parent 261bb27 commit d33c03d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+525
-592
lines changed

.goreleaser.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ builds:
99
- amd64
1010
- arm64
1111
ldflags:
12-
- -X github.com/envelope-zero/backend/v2/pkg/router.version={{.Version}}
12+
- -X github.com/envelope-zero/backend/v3/pkg/router.version={{.Version}}
1313

1414
snapshot:
1515
name_template: "{{ incpatch .Version }}-next"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ coverage: test
2525
VERSION ?= $(shell git rev-parse HEAD)
2626
.PHONY: build
2727
build:
28-
go build -ldflags "-X github.com/envelope-zero/backend/v2/pkg/router.version=${VERSION}"
28+
go build -ldflags "-X github.com/envelope-zero/backend/v3/pkg/router.version=${VERSION}"
2929

3030

3131
.PHONY: docs

docs/upgrading.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
# Upgrading
22

3+
:warning: You cannot skip major versions on upgrades. You have to upgrade to at least one release of each major version.
4+
35
If upgrades between versions require manual actions, those are described here.
46

5-
## to any version > v1.0.0
7+
# to v3.0.0
8+
9+
v3.0.0 does not require manual steps. With v3.0.0, account names must be unique per budget.
10+
11+
# to v2.0.0
12+
13+
v2.0.0 does not require manual steps. With v2.0.0, spent amounts are now negative values instead of positive values.
14+
15+
## < v1.0.0 to v1.0.0
616

717
If you are running a version below `v0.35.0`, you _must_ upgrade to `v1.0.0` before you upgrade any further.
818

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/envelope-zero/backend/v2
1+
module github.com/envelope-zero/backend/v3
22

33
go 1.19
44

main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
"syscall"
1111
"time"
1212

13-
"github.com/envelope-zero/backend/v2/pkg/controllers"
14-
"github.com/envelope-zero/backend/v2/pkg/database"
15-
"github.com/envelope-zero/backend/v2/pkg/models"
16-
"github.com/envelope-zero/backend/v2/pkg/router"
13+
"github.com/envelope-zero/backend/v3/pkg/controllers"
14+
"github.com/envelope-zero/backend/v3/pkg/database"
15+
"github.com/envelope-zero/backend/v3/pkg/models"
16+
"github.com/envelope-zero/backend/v3/pkg/router"
1717
"github.com/gin-gonic/gin"
1818
"github.com/rs/zerolog"
1919
"github.com/rs/zerolog/log"

pkg/controllers/account.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package controllers
33
import (
44
"net/http"
55

6-
"github.com/envelope-zero/backend/v2/pkg/httperrors"
7-
"github.com/envelope-zero/backend/v2/pkg/httputil"
8-
"github.com/envelope-zero/backend/v2/pkg/models"
6+
"github.com/envelope-zero/backend/v3/pkg/httperrors"
7+
"github.com/envelope-zero/backend/v3/pkg/httputil"
8+
"github.com/envelope-zero/backend/v3/pkg/models"
99
"github.com/gin-gonic/gin"
1010
"github.com/google/uuid"
1111
)

pkg/controllers/account_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"strings"
77
"testing"
88

9-
"github.com/envelope-zero/backend/v2/pkg/controllers"
10-
"github.com/envelope-zero/backend/v2/pkg/models"
11-
"github.com/envelope-zero/backend/v2/test"
9+
"github.com/envelope-zero/backend/v3/pkg/controllers"
10+
"github.com/envelope-zero/backend/v3/pkg/models"
11+
"github.com/envelope-zero/backend/v3/test"
1212
"github.com/google/uuid"
1313
"github.com/stretchr/testify/assert"
1414
)
@@ -48,13 +48,13 @@ func (suite *TestSuiteStandard) TestOptionsAccount() {
4848
recorder = test.Request(suite.controller, suite.T(), http.MethodOptions, "http://example.com/v1/accounts/NotParseableAsUUID", "")
4949
assert.Equal(suite.T(), http.StatusBadRequest, recorder.Code, "Request ID %s", recorder.Header().Get("x-request-id"))
5050

51-
path = suite.createTestAccount(models.AccountCreate{}).Data.Links.Self
51+
path = suite.createTestAccount(models.AccountCreate{Name: "TestOptionsAccount"}).Data.Links.Self
5252
recorder = test.Request(suite.controller, suite.T(), http.MethodOptions, path, "")
5353
assert.Equal(suite.T(), http.StatusNoContent, recorder.Code, "Request ID %s", recorder.Header().Get("x-request-id"))
5454
}
5555

5656
func (suite *TestSuiteStandard) TestGetAccounts() {
57-
_ = suite.createTestAccount(models.AccountCreate{})
57+
_ = suite.createTestAccount(models.AccountCreate{Name: "TestGetAccounts"})
5858

5959
var response controllers.AccountListResponse
6060
recorder := test.Request(suite.controller, suite.T(), http.MethodGet, "http://example.com/v1/accounts", "")
@@ -200,7 +200,7 @@ func (suite *TestSuiteStandard) TestAccountInvalidIDs() {
200200
}
201201

202202
func (suite *TestSuiteStandard) TestCreateAccount() {
203-
_ = suite.createTestAccount(models.AccountCreate{Name: "Test account for creation"})
203+
_ = suite.createTestAccount(models.AccountCreate{Name: "TestCreateAccount"})
204204
}
205205

206206
func (suite *TestSuiteStandard) TestCreateAccountNoBudget() {
@@ -235,7 +235,7 @@ func (suite *TestSuiteStandard) TestCreateAccountNoBody() {
235235
}
236236

237237
func (suite *TestSuiteStandard) TestGetAccount() {
238-
a := suite.createTestAccount(models.AccountCreate{})
238+
a := suite.createTestAccount(models.AccountCreate{Name: "TestGetAccount"})
239239

240240
r := test.Request(suite.controller, suite.T(), http.MethodGet, a.Data.Links.Self, "")
241241
assert.Equal(suite.T(), http.StatusOK, r.Code)
@@ -266,7 +266,7 @@ func (suite *TestSuiteStandard) TestUpdateAccount() {
266266

267267
func (suite *TestSuiteStandard) TestUpdateAccountBrokenJSON() {
268268
a := suite.createTestAccount(models.AccountCreate{
269-
Name: "New Account",
269+
Name: "TestUpdateAccountBrokenJSON",
270270
Note: "More tests something something",
271271
})
272272

@@ -276,7 +276,7 @@ func (suite *TestSuiteStandard) TestUpdateAccountBrokenJSON() {
276276

277277
func (suite *TestSuiteStandard) TestUpdateAccountInvalidType() {
278278
a := suite.createTestAccount(models.AccountCreate{
279-
Name: "New Account",
279+
Name: "TestUpdateAccountInvalidType",
280280
Note: "More tests something something",
281281
})
282282

@@ -288,7 +288,7 @@ func (suite *TestSuiteStandard) TestUpdateAccountInvalidType() {
288288

289289
func (suite *TestSuiteStandard) TestUpdateAccountInvalidBudgetID() {
290290
a := suite.createTestAccount(models.AccountCreate{
291-
Name: "New Account",
291+
Name: "TestUpdateAccountInvalidBudgetID",
292292
Note: "More tests something something",
293293
})
294294

@@ -327,7 +327,7 @@ func (suite *TestSuiteStandard) TestDeleteNonExistingAccount() {
327327
}
328328

329329
func (suite *TestSuiteStandard) TestDeleteAccountWithBody() {
330-
a := suite.createTestAccount(models.AccountCreate{Name: "Delete me now!"})
330+
a := suite.createTestAccount(models.AccountCreate{Name: "TestDeleteAccountWithBody"})
331331

332332
r := test.Request(suite.controller, suite.T(), http.MethodDelete, a.Data.Links.Self, models.AccountCreate{Name: "Some other account"})
333333
assertHTTPStatus(suite.T(), &r, http.StatusNoContent)

pkg/controllers/allocation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66
"github.com/google/uuid"
77
"github.com/shopspring/decimal"
88

9-
"github.com/envelope-zero/backend/v2/internal/types"
10-
"github.com/envelope-zero/backend/v2/pkg/httperrors"
11-
"github.com/envelope-zero/backend/v2/pkg/httputil"
12-
"github.com/envelope-zero/backend/v2/pkg/models"
9+
"github.com/envelope-zero/backend/v3/internal/types"
10+
"github.com/envelope-zero/backend/v3/pkg/httperrors"
11+
"github.com/envelope-zero/backend/v3/pkg/httputil"
12+
"github.com/envelope-zero/backend/v3/pkg/models"
1313
"github.com/gin-gonic/gin"
1414
)
1515

pkg/controllers/allocation_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/envelope-zero/backend/v2/internal/types"
11-
"github.com/envelope-zero/backend/v2/pkg/controllers"
12-
"github.com/envelope-zero/backend/v2/pkg/models"
13-
"github.com/envelope-zero/backend/v2/test"
10+
"github.com/envelope-zero/backend/v3/internal/types"
11+
"github.com/envelope-zero/backend/v3/pkg/controllers"
12+
"github.com/envelope-zero/backend/v3/pkg/models"
13+
"github.com/envelope-zero/backend/v3/test"
1414
"github.com/google/uuid"
1515
"github.com/shopspring/decimal"
1616
"github.com/stretchr/testify/assert"

pkg/controllers/budget.go

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package controllers
33
import (
44
"net/http"
55

6-
"github.com/envelope-zero/backend/v2/internal/types"
7-
"github.com/envelope-zero/backend/v2/pkg/httperrors"
8-
"github.com/envelope-zero/backend/v2/pkg/httputil"
9-
"github.com/envelope-zero/backend/v2/pkg/models"
6+
"github.com/envelope-zero/backend/v3/internal/types"
7+
"github.com/envelope-zero/backend/v3/pkg/httperrors"
8+
"github.com/envelope-zero/backend/v3/pkg/httputil"
9+
"github.com/envelope-zero/backend/v3/pkg/models"
1010
"github.com/gin-gonic/gin"
1111
"github.com/google/uuid"
1212
"github.com/shopspring/decimal"
@@ -194,11 +194,6 @@ func (co Controller) CreateBudget(c *gin.Context) {
194194
return
195195
}
196196

197-
// TODO: Delete
198-
// budgetObject, ok := co.getBudgetResource(c, budget.ID)
199-
// if !ok {
200-
// return
201-
// }
202197
c.JSON(http.StatusCreated, BudgetResponse{Data: budget})
203198
}
204199

@@ -431,12 +426,6 @@ func (co Controller) UpdateBudget(c *gin.Context) {
431426
return
432427
}
433428

434-
// TODO: delete
435-
// budgetObject, ok := co.getBudgetObject(c, budget.ID)
436-
// if !ok {
437-
// httperrors.Handler(c, err)
438-
// return
439-
// }
440429
c.JSON(http.StatusOK, BudgetResponse{Data: budget})
441430
}
442431

0 commit comments

Comments
 (0)