mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
support aggregating account/category and tag info in transaction list/get api
This commit is contained in:
@@ -78,6 +78,27 @@ func (s *TransactionCategoryService) GetCategoryByCategoryId(uid int64, category
|
||||
return category, nil
|
||||
}
|
||||
|
||||
// GetCategoriesByCategoryIds returns transaction category models according to transaction category ids
|
||||
func (s *TransactionCategoryService) GetCategoriesByCategoryIds(uid int64, categoryIds []int64) (map[int64]*models.TransactionCategory, error) {
|
||||
if uid <= 0 {
|
||||
return nil, errs.ErrUserIdInvalid
|
||||
}
|
||||
|
||||
if categoryIds == nil {
|
||||
return nil, errs.ErrTransactionCategoryIdInvalid
|
||||
}
|
||||
|
||||
var categories []*models.TransactionCategory
|
||||
err := s.UserDataDB(uid).Where("uid=? AND deleted=?", uid, false).In("category_id", categoryIds).Find(&categories)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
categoryMap := s.GetCategoryMapByList(categories)
|
||||
return categoryMap, err
|
||||
}
|
||||
|
||||
// GetMaxDisplayOrder returns the max display order according to transaction category type
|
||||
func (s *TransactionCategoryService) GetMaxDisplayOrder(uid int64, categoryType models.TransactionCategoryType) (int, error) {
|
||||
if uid <= 0 {
|
||||
|
||||
@@ -63,6 +63,27 @@ func (s *TransactionTagService) GetTagByTagId(uid int64, tagId int64) (*models.T
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
// GetTagsByTagIds returns transaction tag models according to transaction tag ids
|
||||
func (s *TransactionTagService) GetTagsByTagIds(uid int64, tagIds []int64) (map[int64]*models.TransactionTag, error) {
|
||||
if uid <= 0 {
|
||||
return nil, errs.ErrUserIdInvalid
|
||||
}
|
||||
|
||||
if tagIds == nil {
|
||||
return nil, errs.ErrTransactionTagIdInvalid
|
||||
}
|
||||
|
||||
var tags []*models.TransactionTag
|
||||
err := s.UserDataDB(uid).Where("uid=? AND deleted=?", uid, false).In("tag_id", tagIds).Find(&tags)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tagMap := s.GetTagMapByList(tags)
|
||||
return tagMap, err
|
||||
}
|
||||
|
||||
// GetMaxDisplayOrder returns the max display order
|
||||
func (s *TransactionTagService) GetMaxDisplayOrder(uid int64) (int, error) {
|
||||
if uid <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user