code refactor
This commit is contained in:
@@ -21,16 +21,16 @@ type LatestExchangeRate struct {
|
||||
type LatestExchangeRateSlice []*LatestExchangeRate
|
||||
|
||||
// Len returns the count of items
|
||||
func (c LatestExchangeRateSlice) Len() int {
|
||||
return len(c)
|
||||
func (s LatestExchangeRateSlice) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Swap swaps two items
|
||||
func (c LatestExchangeRateSlice) Swap(i, j int) {
|
||||
c[i], c[j] = c[j], c[i]
|
||||
func (s LatestExchangeRateSlice) 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 (c LatestExchangeRateSlice) Less(i, j int) bool {
|
||||
return strings.Compare(c[i].Currency, c[j].Currency) < 0
|
||||
func (s LatestExchangeRateSlice) Less(i, j int) bool {
|
||||
return strings.Compare(s[i].Currency, s[j].Currency) < 0
|
||||
}
|
||||
|
||||
+31
-31
@@ -133,12 +133,12 @@ type TransactionInfoPageWrapperResponse struct {
|
||||
}
|
||||
|
||||
// IsEditable returns whether this transaction can be edited
|
||||
func (c *Transaction) IsEditable(account *Account, relatedAccount *Account) bool {
|
||||
func (t *Transaction) IsEditable(account *Account, relatedAccount *Account) bool {
|
||||
if account == nil || account.Hidden {
|
||||
return false
|
||||
}
|
||||
|
||||
if c.Type == TRANSACTION_DB_TYPE_TRANSFER_OUT {
|
||||
if t.Type == TRANSACTION_DB_TYPE_TRANSFER_OUT {
|
||||
if relatedAccount == nil || relatedAccount.Hidden {
|
||||
return false
|
||||
}
|
||||
@@ -148,52 +148,52 @@ func (c *Transaction) IsEditable(account *Account, relatedAccount *Account) bool
|
||||
}
|
||||
|
||||
// ToTransactionInfoResponse returns a view-object according to database model
|
||||
func (c *Transaction) ToTransactionInfoResponse(tagIds []int64, editable bool) *TransactionInfoResponse {
|
||||
func (t *Transaction) ToTransactionInfoResponse(tagIds []int64, editable bool) *TransactionInfoResponse {
|
||||
var transactionType TransactionType
|
||||
|
||||
if c.Type == TRANSACTION_DB_TYPE_MODIFY_BALANCE {
|
||||
if t.Type == TRANSACTION_DB_TYPE_MODIFY_BALANCE {
|
||||
transactionType = TRANSACTION_TYPE_MODIFY_BALANCE
|
||||
} else if c.Type == TRANSACTION_DB_TYPE_EXPENSE {
|
||||
} else if t.Type == TRANSACTION_DB_TYPE_EXPENSE {
|
||||
transactionType = TRANSACTION_TYPE_EXPENSE
|
||||
} else if c.Type == TRANSACTION_DB_TYPE_INCOME {
|
||||
} else if t.Type == TRANSACTION_DB_TYPE_INCOME {
|
||||
transactionType = TRANSACTION_TYPE_INCOME
|
||||
} else if c.Type == TRANSACTION_DB_TYPE_TRANSFER_OUT {
|
||||
} else if t.Type == TRANSACTION_DB_TYPE_TRANSFER_OUT {
|
||||
transactionType = TRANSACTION_TYPE_TRANSFER
|
||||
} else if c.Type == TRANSACTION_DB_TYPE_TRANSFER_IN {
|
||||
} else if t.Type == TRANSACTION_DB_TYPE_TRANSFER_IN {
|
||||
transactionType = TRANSACTION_TYPE_TRANSFER
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
sourceAccountId := c.AccountId
|
||||
sourceAmount := c.Amount
|
||||
sourceAccountId := t.AccountId
|
||||
sourceAmount := t.Amount
|
||||
|
||||
destinationAccountId := int64(0)
|
||||
destinationAmount := int64(0)
|
||||
|
||||
if c.Type == TRANSACTION_DB_TYPE_TRANSFER_OUT {
|
||||
destinationAccountId = c.RelatedAccountId
|
||||
destinationAmount = c.RelatedAccountAmount
|
||||
} else if c.Type == TRANSACTION_DB_TYPE_TRANSFER_IN {
|
||||
sourceAccountId = c.RelatedAccountId
|
||||
sourceAmount = c.RelatedAccountAmount
|
||||
if t.Type == TRANSACTION_DB_TYPE_TRANSFER_OUT {
|
||||
destinationAccountId = t.RelatedAccountId
|
||||
destinationAmount = t.RelatedAccountAmount
|
||||
} else if t.Type == TRANSACTION_DB_TYPE_TRANSFER_IN {
|
||||
sourceAccountId = t.RelatedAccountId
|
||||
sourceAmount = t.RelatedAccountAmount
|
||||
|
||||
destinationAccountId = c.AccountId
|
||||
destinationAmount = c.Amount
|
||||
destinationAccountId = t.AccountId
|
||||
destinationAmount = t.Amount
|
||||
}
|
||||
|
||||
return &TransactionInfoResponse{
|
||||
Id: c.TransactionId,
|
||||
TimeSequenceId: c.TransactionTime,
|
||||
Id: t.TransactionId,
|
||||
TimeSequenceId: t.TransactionTime,
|
||||
Type: transactionType,
|
||||
CategoryId: c.CategoryId,
|
||||
Time: utils.GetUnixTimeFromTransactionTime(c.TransactionTime),
|
||||
CategoryId: t.CategoryId,
|
||||
Time: utils.GetUnixTimeFromTransactionTime(t.TransactionTime),
|
||||
SourceAccountId: sourceAccountId,
|
||||
DestinationAccountId: destinationAccountId,
|
||||
SourceAmount: sourceAmount,
|
||||
DestinationAmount: destinationAmount,
|
||||
TagIds: utils.Int64ArrayToStringArray(tagIds),
|
||||
Comment: c.Comment,
|
||||
Comment: t.Comment,
|
||||
Editable: editable,
|
||||
}
|
||||
}
|
||||
@@ -202,20 +202,20 @@ func (c *Transaction) ToTransactionInfoResponse(tagIds []int64, editable bool) *
|
||||
type TransactionInfoResponseSlice []*TransactionInfoResponse
|
||||
|
||||
// Len returns the count of items
|
||||
func (c TransactionInfoResponseSlice) Len() int {
|
||||
return len(c)
|
||||
func (s TransactionInfoResponseSlice) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Swap swaps two items
|
||||
func (c TransactionInfoResponseSlice) Swap(i, j int) {
|
||||
c[i], c[j] = c[j], c[i]
|
||||
func (s TransactionInfoResponseSlice) 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 (c TransactionInfoResponseSlice) Less(i, j int) bool {
|
||||
if c[i].Time != c[j].Time {
|
||||
return c[i].Time > c[j].Time
|
||||
func (s TransactionInfoResponseSlice) Less(i, j int) bool {
|
||||
if s[i].Time != s[j].Time {
|
||||
return s[i].Time > s[j].Time
|
||||
}
|
||||
|
||||
return c[i].Id > c[j].Id
|
||||
return s[i].Id > s[j].Id
|
||||
}
|
||||
|
||||
@@ -132,16 +132,16 @@ func (c *TransactionCategory) ToTransactionCategoryInfoResponse() *TransactionCa
|
||||
type TransactionCategoryInfoResponseSlice []*TransactionCategoryInfoResponse
|
||||
|
||||
// Len returns the count of items
|
||||
func (c TransactionCategoryInfoResponseSlice) Len() int {
|
||||
return len(c)
|
||||
func (s TransactionCategoryInfoResponseSlice) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Swap swaps two items
|
||||
func (c TransactionCategoryInfoResponseSlice) Swap(i, j int) {
|
||||
c[i], c[j] = c[j], c[i]
|
||||
func (s TransactionCategoryInfoResponseSlice) 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 (c TransactionCategoryInfoResponseSlice) Less(i, j int) bool {
|
||||
return c[i].DisplayOrder < c[j].DisplayOrder
|
||||
func (s TransactionCategoryInfoResponseSlice) Less(i, j int) bool {
|
||||
return s[i].DisplayOrder < s[j].DisplayOrder
|
||||
}
|
||||
|
||||
@@ -60,12 +60,12 @@ type TransactionTagInfoResponse struct {
|
||||
}
|
||||
|
||||
// ToTransactionTagInfoResponse returns a view-object according to database model
|
||||
func (c *TransactionTag) ToTransactionTagInfoResponse() *TransactionTagInfoResponse {
|
||||
func (t *TransactionTag) ToTransactionTagInfoResponse() *TransactionTagInfoResponse {
|
||||
return &TransactionTagInfoResponse{
|
||||
Id: c.TagId,
|
||||
Name: c.Name,
|
||||
DisplayOrder: c.DisplayOrder,
|
||||
Hidden: c.Hidden,
|
||||
Id: t.TagId,
|
||||
Name: t.Name,
|
||||
DisplayOrder: t.DisplayOrder,
|
||||
Hidden: t.Hidden,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,16 +73,16 @@ func (c *TransactionTag) ToTransactionTagInfoResponse() *TransactionTagInfoRespo
|
||||
type TransactionTagInfoResponseSlice []*TransactionTagInfoResponse
|
||||
|
||||
// Len returns the count of items
|
||||
func (c TransactionTagInfoResponseSlice) Len() int {
|
||||
return len(c)
|
||||
func (s TransactionTagInfoResponseSlice) Len() int {
|
||||
return len(s)
|
||||
}
|
||||
|
||||
// Swap swaps two items
|
||||
func (c TransactionTagInfoResponseSlice) Swap(i, j int) {
|
||||
c[i], c[j] = c[j], c[i]
|
||||
func (s TransactionTagInfoResponseSlice) 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 (c TransactionTagInfoResponseSlice) Less(i, j int) bool {
|
||||
return c[i].DisplayOrder < c[j].DisplayOrder
|
||||
func (s TransactionTagInfoResponseSlice) Less(i, j int) bool {
|
||||
return s[i].DisplayOrder < s[j].DisplayOrder
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user