support transaction tag group
This commit is contained in:
@@ -3,10 +3,11 @@ package models
|
||||
// TransactionTag represents transaction tag data stored in database
|
||||
type TransactionTag struct {
|
||||
TagId int64 `xorm:"PK"`
|
||||
Uid int64 `xorm:"INDEX(IDX_tag_uid_deleted_order) NOT NULL"`
|
||||
Deleted bool `xorm:"INDEX(IDX_tag_uid_deleted_order) NOT NULL"`
|
||||
Uid int64 `xorm:"INDEX(IDX_tag_uid_deleted_group_order) NOT NULL"`
|
||||
Deleted bool `xorm:"INDEX(IDX_tag_uid_deleted_group_order) NOT NULL"`
|
||||
TagGroupId int64 `xorm:"INDEX(IDX_tag_uid_deleted_group_order) NOT NULL"`
|
||||
Name string `xorm:"VARCHAR(64) NOT NULL"`
|
||||
DisplayOrder int32 `xorm:"INDEX(IDX_tag_uid_deleted_order) NOT NULL"`
|
||||
DisplayOrder int32 `xorm:"INDEX(IDX_tag_uid_deleted_group_order) NOT NULL"`
|
||||
Hidden bool `xorm:"NOT NULL"`
|
||||
CreatedUnixTime int64
|
||||
UpdatedUnixTime int64
|
||||
@@ -20,19 +21,22 @@ type TransactionTagGetRequest struct {
|
||||
|
||||
// TransactionTagCreateRequest represents all parameters of transaction tag creation request
|
||||
type TransactionTagCreateRequest struct {
|
||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||
GroupId int64 `json:"groupId,string"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||
}
|
||||
|
||||
// TransactionTagCreateBatchRequest represents all parameters of transaction tag batch creation request
|
||||
type TransactionTagCreateBatchRequest struct {
|
||||
Tags []*TransactionTagCreateRequest `json:"tags" binding:"required"`
|
||||
GroupId int64 `json:"groupId,string"`
|
||||
SkipExists bool `json:"skipExists"`
|
||||
}
|
||||
|
||||
// TransactionTagModifyRequest represents all parameters of transaction tag modification request
|
||||
type TransactionTagModifyRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
GroupId int64 `json:"groupId,string"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||
}
|
||||
|
||||
// TransactionTagHideRequest represents all parameters of transaction tag hiding request
|
||||
@@ -61,6 +65,7 @@ type TransactionTagDeleteRequest struct {
|
||||
type TransactionTagInfoResponse struct {
|
||||
Id int64 `json:"id,string"`
|
||||
Name string `json:"name"`
|
||||
TagGroupId int64 `json:"groupId,string"`
|
||||
DisplayOrder int32 `json:"displayOrder"`
|
||||
Hidden bool `json:"hidden"`
|
||||
}
|
||||
@@ -71,6 +76,7 @@ func (t *TransactionTag) FillFromOtherTag(tag *TransactionTag) {
|
||||
t.Uid = tag.Uid
|
||||
t.Deleted = tag.Deleted
|
||||
t.Name = tag.Name
|
||||
t.TagGroupId = tag.TagGroupId
|
||||
t.DisplayOrder = tag.DisplayOrder
|
||||
t.Hidden = tag.Hidden
|
||||
t.CreatedUnixTime = tag.CreatedUnixTime
|
||||
@@ -83,6 +89,7 @@ func (t *TransactionTag) ToTransactionTagInfoResponse() *TransactionTagInfoRespo
|
||||
return &TransactionTagInfoResponse{
|
||||
Id: t.TagId,
|
||||
Name: t.Name,
|
||||
TagGroupId: t.TagGroupId,
|
||||
DisplayOrder: t.DisplayOrder,
|
||||
Hidden: t.Hidden,
|
||||
}
|
||||
@@ -103,5 +110,9 @@ func (s TransactionTagInfoResponseSlice) Swap(i, j int) {
|
||||
|
||||
// Less reports whether the first item is less than the second one
|
||||
func (s TransactionTagInfoResponseSlice) Less(i, j int) bool {
|
||||
if s[i].TagGroupId != s[j].TagGroupId {
|
||||
return s[i].TagGroupId < s[j].TagGroupId
|
||||
}
|
||||
|
||||
return s[i].DisplayOrder < s[j].DisplayOrder
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package models
|
||||
|
||||
// TransactionTagGroup represents transaction tag group data stored in database
|
||||
type TransactionTagGroup struct {
|
||||
TagGroupId int64 `xorm:"PK"`
|
||||
Uid int64 `xorm:"INDEX(IDX_tag_group_uid_deleted_order) NOT NULL"`
|
||||
Deleted bool `xorm:"INDEX(IDX_tag_group_uid_deleted_order) NOT NULL"`
|
||||
Name string `xorm:"VARCHAR(64) NOT NULL"`
|
||||
DisplayOrder int32 `xorm:"INDEX(IDX_tag_group_uid_deleted_order) NOT NULL"`
|
||||
CreatedUnixTime int64
|
||||
UpdatedUnixTime int64
|
||||
DeletedUnixTime int64
|
||||
}
|
||||
|
||||
// TransactionTagGroupGetRequest represents all parameters of transaction tag group getting request
|
||||
type TransactionTagGroupGetRequest struct {
|
||||
Id int64 `form:"id,string" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// TransactionTagGroupCreateRequest represents all parameters of transaction tag group creation request
|
||||
type TransactionTagGroupCreateRequest struct {
|
||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||
}
|
||||
|
||||
// TransactionTagGroupModifyRequest represents all parameters of transaction tag group modification request
|
||||
type TransactionTagGroupModifyRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
Name string `json:"name" binding:"required,notBlank,max=64"`
|
||||
}
|
||||
|
||||
// TransactionTagGroupMoveRequest represents all parameters of transaction tag group moving request
|
||||
type TransactionTagGroupMoveRequest struct {
|
||||
NewDisplayOrders []*TransactionTagGroupNewDisplayOrderRequest `json:"newDisplayOrders" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// TransactionTagGroupNewDisplayOrderRequest represents a data pair of id and display order
|
||||
type TransactionTagGroupNewDisplayOrderRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
DisplayOrder int32 `json:"displayOrder"`
|
||||
}
|
||||
|
||||
// TransactionTagGroupDeleteRequest represents all parameters of transaction tag group deleting request
|
||||
type TransactionTagGroupDeleteRequest struct {
|
||||
Id int64 `json:"id,string" binding:"required,min=1"`
|
||||
}
|
||||
|
||||
// TransactionTagGroupInfoResponse represents a view-object of transaction tag group
|
||||
type TransactionTagGroupInfoResponse struct {
|
||||
Id int64 `json:"id,string"`
|
||||
Name string `json:"name"`
|
||||
DisplayOrder int32 `json:"displayOrder"`
|
||||
}
|
||||
|
||||
// ToTransactionTagGroupInfoResponse returns a view-object according to database model
|
||||
func (t *TransactionTagGroup) ToTransactionTagGroupInfoResponse() *TransactionTagGroupInfoResponse {
|
||||
return &TransactionTagGroupInfoResponse{
|
||||
Id: t.TagGroupId,
|
||||
Name: t.Name,
|
||||
DisplayOrder: t.DisplayOrder,
|
||||
}
|
||||
}
|
||||
|
||||
// TransactionTagGroupInfoResponseSlice represents the slice data structure of TransactionTagGroupInfoResponse
|
||||
type TransactionTagGroupInfoResponseSlice []*TransactionTagGroupInfoResponse
|
||||
|
||||
// Len returns the count of items
|
||||
func (s TransactionTagGroupInfoResponseSlice) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Swap swaps two items
|
||||
func (s TransactionTagGroupInfoResponseSlice) Swap(i, j int) {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
|
||||
// Less reports whether the first item is less than the second one
|
||||
func (s TransactionTagGroupInfoResponseSlice) Less(i, j int) bool {
|
||||
return s[i].DisplayOrder < s[j].DisplayOrder
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTransactionTagGroupInfoResponseSliceLess(t *testing.T) {
|
||||
var transactionTagGroupRespSlice TransactionTagGroupInfoResponseSlice
|
||||
transactionTagGroupRespSlice = append(transactionTagGroupRespSlice, &TransactionTagGroupInfoResponse{
|
||||
Id: 1,
|
||||
DisplayOrder: 3,
|
||||
})
|
||||
transactionTagGroupRespSlice = append(transactionTagGroupRespSlice, &TransactionTagGroupInfoResponse{
|
||||
Id: 2,
|
||||
DisplayOrder: 1,
|
||||
})
|
||||
transactionTagGroupRespSlice = append(transactionTagGroupRespSlice, &TransactionTagGroupInfoResponse{
|
||||
Id: 3,
|
||||
DisplayOrder: 2,
|
||||
})
|
||||
|
||||
sort.Sort(transactionTagGroupRespSlice)
|
||||
|
||||
assert.Equal(t, int64(2), transactionTagGroupRespSlice[0].Id)
|
||||
assert.Equal(t, int64(3), transactionTagGroupRespSlice[1].Id)
|
||||
assert.Equal(t, int64(1), transactionTagGroupRespSlice[2].Id)
|
||||
}
|
||||
@@ -11,20 +11,41 @@ func TestTransactionTagInfoResponseSliceLess(t *testing.T) {
|
||||
var transactionTagRespSlice TransactionTagInfoResponseSlice
|
||||
transactionTagRespSlice = append(transactionTagRespSlice, &TransactionTagInfoResponse{
|
||||
Id: 1,
|
||||
TagGroupId: 0,
|
||||
DisplayOrder: 3,
|
||||
})
|
||||
transactionTagRespSlice = append(transactionTagRespSlice, &TransactionTagInfoResponse{
|
||||
Id: 2,
|
||||
DisplayOrder: 1,
|
||||
TagGroupId: 1,
|
||||
DisplayOrder: 2,
|
||||
})
|
||||
transactionTagRespSlice = append(transactionTagRespSlice, &TransactionTagInfoResponse{
|
||||
Id: 3,
|
||||
TagGroupId: 0,
|
||||
DisplayOrder: 1,
|
||||
})
|
||||
transactionTagRespSlice = append(transactionTagRespSlice, &TransactionTagInfoResponse{
|
||||
Id: 4,
|
||||
TagGroupId: 2,
|
||||
DisplayOrder: 1,
|
||||
})
|
||||
transactionTagRespSlice = append(transactionTagRespSlice, &TransactionTagInfoResponse{
|
||||
Id: 5,
|
||||
TagGroupId: 1,
|
||||
DisplayOrder: 1,
|
||||
})
|
||||
transactionTagRespSlice = append(transactionTagRespSlice, &TransactionTagInfoResponse{
|
||||
Id: 6,
|
||||
TagGroupId: 0,
|
||||
DisplayOrder: 2,
|
||||
})
|
||||
|
||||
sort.Sort(transactionTagRespSlice)
|
||||
|
||||
assert.Equal(t, int64(2), transactionTagRespSlice[0].Id)
|
||||
assert.Equal(t, int64(3), transactionTagRespSlice[1].Id)
|
||||
assert.Equal(t, int64(3), transactionTagRespSlice[0].Id)
|
||||
assert.Equal(t, int64(6), transactionTagRespSlice[1].Id)
|
||||
assert.Equal(t, int64(1), transactionTagRespSlice[2].Id)
|
||||
assert.Equal(t, int64(5), transactionTagRespSlice[3].Id)
|
||||
assert.Equal(t, int64(2), transactionTagRespSlice[4].Id)
|
||||
assert.Equal(t, int64(4), transactionTagRespSlice[5].Id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user