Skip to content

Commit 1718110

Browse files
authored
fix: mark archived envelopes as archived (#984)
1 parent 40b0f17 commit 1718110

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

api/docs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4608,6 +4608,9 @@ const docTemplate = `{
46084608
"v4.RecentEnvelope": {
46094609
"type": "object",
46104610
"properties": {
4611+
"archived": {
4612+
"type": "boolean"
4613+
},
46114614
"id": {
46124615
"type": "string"
46134616
},

api/swagger.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4597,6 +4597,9 @@
45974597
"v4.RecentEnvelope": {
45984598
"type": "object",
45994599
"properties": {
4600+
"archived": {
4601+
"type": "boolean"
4602+
},
46004603
"id": {
46014604
"type": "string"
46024605
},

api/swagger.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,8 @@ definitions:
11451145
type: object
11461146
v4.RecentEnvelope:
11471147
properties:
1148+
archived:
1149+
type: boolean
11481150
id:
11491151
type: string
11501152
name:

pkg/controllers/v4/account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func GetAccountRecentEnvelopes(c *gin.Context) {
275275
latest := models.DB.
276276
Model(&models.Transaction{}).
277277
Joins("LEFT JOIN envelopes ON envelopes.id = transactions.envelope_id AND envelopes.deleted_at IS NULL").
278-
Select("envelopes.id as e_id, envelopes.name as name, datetime(envelopes.created_at) as created").
278+
Select("envelopes.id as e_id, envelopes.name as name, datetime(envelopes.created_at) as created, envelopes.archived as archived").
279279
Where(&models.Transaction{
280280
DestinationAccountID: account.ID,
281281
}).
@@ -286,7 +286,7 @@ func GetAccountRecentEnvelopes(c *gin.Context) {
286286
err = models.DB.
287287
Table("(?)", latest).
288288
// Set the nil UUID as ID if the envelope ID is NULL, since count() only counts non-null values
289-
Select("IIF(e_id IS NOT NULL, e_id, NULL) as id, name").
289+
Select("IIF(e_id IS NOT NULL, e_id, NULL) as id, name, archived").
290290
Group("id").
291291
Order("count(IIF(e_id IS NOT NULL, e_id, '0')) DESC"). // Order with a different IIF since NULL is ignored for count
292292
Order("created ASC").

pkg/controllers/v4/account_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,9 +608,15 @@ func (suite *TestSuiteStandard) TestAccountRecentEnvelopes() {
608608

609609
envelopeIDs := []*uuid.UUID{}
610610
for i := 0; i < 3; i++ {
611+
archived := false
612+
if i%2 == 0 {
613+
archived = true
614+
}
615+
611616
envelope := createTestEnvelope(suite.T(), v4.EnvelopeEditable{
612617
CategoryID: category.Data.ID,
613618
Name: strconv.Itoa(i),
619+
Archived: archived,
614620
})
615621

616622
envelopeIDs = append(envelopeIDs, &envelope.Data.ID)
@@ -668,10 +674,14 @@ func (suite *TestSuiteStandard) TestAccountRecentEnvelopes() {
668674
// The last envelope needs to be the first in the sort since it
669675
// has been the most common one
670676
suite.Assert().Equal(envelopeIDs[2], data[0].ID)
677+
suite.Assert().Equal(true, data[0].Archived)
671678

672679
// Income is the second one since it appears three times
673680
var nilUUIDPointer *uuid.UUID
674681
suite.Assert().Equal(nilUUIDPointer, data[1].ID)
682+
suite.Assert().Equal(false, data[1].Archived)
675683

676-
// Order for envelopes with the same frequency is undefined
684+
// Order for envelopes with the same frequency is undefined and therefore not tested
685+
// Only one of the two is archived, but since the order is undefined we XOR them
686+
suite.Assert().Equal(true, data[2].Archived != data[3].Archived)
677687
}

pkg/controllers/v4/account_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ type RecentEnvelopesResponse struct {
138138
}
139139

140140
type RecentEnvelope struct {
141-
Name string `json:"name"`
142-
ID *uuid.UUID `json:"id"`
141+
ID *uuid.UUID `json:"id"`
142+
Name string `json:"name"`
143+
Archived bool `json:"archived"`
143144
}
144145

145146
type AccountComputedRequest struct {

0 commit comments

Comments
 (0)