From 636ac974b8e740488797373971ae18d6fc9f3f9d Mon Sep 17 00:00:00 2001 From: MaysWind Date: Fri, 30 Aug 2024 21:58:25 +0800 Subject: [PATCH] show transaction pictures in data management page --- pkg/api/data_managements.go | 17 +++++++++ pkg/models/data_management.go | 1 + pkg/services/transaction_pictures.go | 35 +++++++++++++++++++ src/locales/en.json | 1 + src/locales/zh_Hans.json | 1 + .../tabs/UserDataManagementSettingTab.vue | 9 +++++ src/views/mobile/users/DataManagementPage.vue | 2 ++ 7 files changed, 66 insertions(+) diff --git a/pkg/api/data_managements.go b/pkg/api/data_managements.go index d15854b7..7b7c060c 100644 --- a/pkg/api/data_managements.go +++ b/pkg/api/data_managements.go @@ -26,6 +26,7 @@ type DataManagementsApi struct { users *services.UserService accounts *services.AccountService transactions *services.TransactionService + pictures *services.TransactionPictureService categories *services.TransactionCategoryService tags *services.TransactionTagService templates *services.TransactionTemplateService @@ -43,6 +44,7 @@ var ( users: services.Users, accounts: services.Accounts, transactions: services.Transactions, + pictures: services.TransactionPictures, categories: services.TransactionCategories, tags: services.TransactionTags, templates: services.TransactionTemplates, @@ -90,6 +92,13 @@ func (a *DataManagementsApi) DataStatisticsHandler(c *core.WebContext) (any, *er return nil, errs.ErrOperationFailed } + totalTransactionPictureCount, err := a.pictures.GetTotalTransactionPicturesCountByUid(c, uid) + + if err != nil { + log.Errorf(c, "[data_managements.DataStatisticsHandler] failed to get total transaction picture count for user \"uid:%d\", because %s", uid, err.Error()) + return nil, errs.ErrOperationFailed + } + totalTransactionTemplateCount, err := a.templates.GetTotalNormalTemplateCountByUid(c, uid) if err != nil { @@ -109,6 +118,7 @@ func (a *DataManagementsApi) DataStatisticsHandler(c *core.WebContext) (any, *er TotalTransactionCategoryCount: totalTransactionCategoryCount, TotalTransactionTagCount: totalTransactionTagCount, TotalTransactionCount: totalTransactionCount, + TotalTransactionPictureCount: totalTransactionPictureCount, TotalTransactionTemplateCount: totalTransactionTemplateCount, TotalScheduledTransactionCount: totalScheduledTransactionCount, } @@ -148,6 +158,13 @@ func (a *DataManagementsApi) ClearDataHandler(c *core.WebContext) (any, *errs.Er return nil, errs.Or(err, errs.ErrOperationFailed) } + err = a.pictures.DeleteAllPictures(c, uid) + + if err != nil { + log.Errorf(c, "[data_managements.ClearDataHandler] failed to delete all transaction pictures, because %s", err.Error()) + return nil, errs.Or(err, errs.ErrOperationFailed) + } + err = a.transactions.DeleteAllTransactions(c, uid) if err != nil { diff --git a/pkg/models/data_management.go b/pkg/models/data_management.go index dc2bf305..3efa6307 100644 --- a/pkg/models/data_management.go +++ b/pkg/models/data_management.go @@ -11,6 +11,7 @@ type DataStatisticsResponse struct { TotalTransactionCategoryCount int64 `json:"totalTransactionCategoryCount,string"` TotalTransactionTagCount int64 `json:"totalTransactionTagCount,string"` TotalTransactionCount int64 `json:"totalTransactionCount,string"` + TotalTransactionPictureCount int64 `json:"totalTransactionPictureCount,string"` TotalTransactionTemplateCount int64 `json:"totalTransactionTemplateCount,string"` TotalScheduledTransactionCount int64 `json:"totalScheduledTransactionCount,string"` } diff --git a/pkg/services/transaction_pictures.go b/pkg/services/transaction_pictures.go index 9b0732fb..746dfcec 100644 --- a/pkg/services/transaction_pictures.go +++ b/pkg/services/transaction_pictures.go @@ -38,6 +38,17 @@ var ( } ) +// GetTotalTransactionPicturesCountByUid returns total transaction pictures count of user +func (s *TransactionPictureService) GetTotalTransactionPicturesCountByUid(c core.Context, uid int64) (int64, error) { + if uid <= 0 { + return 0, errs.ErrUserIdInvalid + } + + count, err := s.UserDataDB(uid).NewSession(c).Where("uid=? AND deleted=?", uid, false).Count(&models.TransactionPictureInfo{}) + + return count, err +} + // GetPictureInfoByPictureId returns a transaction picture info model according to transaction picture id func (s *TransactionPictureService) GetPictureInfoByPictureId(c core.Context, uid int64, pictureId int64) (*models.TransactionPictureInfo, error) { if uid <= 0 { @@ -138,3 +149,27 @@ func (s *TransactionPictureService) UploadPicture(c core.Context, pictureInfo *m return err }) } + +// DeleteAllPictures deletes all existed transaction pictures from database +func (s *TransactionPictureService) DeleteAllPictures(c core.Context, uid int64) error { + if uid <= 0 { + return errs.ErrUserIdInvalid + } + + now := time.Now().Unix() + + updateModel := &models.TransactionPictureInfo{ + Deleted: true, + DeletedUnixTime: now, + } + + return s.UserDataDB(uid).DoTransaction(c, func(sess *xorm.Session) error { + _, err := sess.Cols("deleted", "deleted_unix_time").Where("uid=? AND deleted=?", uid, false).Update(updateModel) + + if err != nil { + return err + } + + return nil + }) +} diff --git a/src/locales/en.json b/src/locales/en.json index babbb3cd..9873c56b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1413,6 +1413,7 @@ "Unable to delete this account": "Unable to delete this account", "Transaction": "Transaction", "Transactions": "Transactions", + "Transaction Pictures": "Transaction Pictures", "Add Transaction": "Add Transaction", "Edit Transaction": "Edit Transaction", "Add Transaction Template": "Add Transaction Template", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 9ab0882d..948ac20a 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1413,6 +1413,7 @@ "Unable to delete this account": "无法删除该账户", "Transaction": "交易", "Transactions": "交易", + "Transaction Pictures": "交易图片", "Add Transaction": "添加交易", "Edit Transaction": "编辑交易", "Add Transaction Template": "添加交易模板", diff --git a/src/views/desktop/user/settings/tabs/UserDataManagementSettingTab.vue b/src/views/desktop/user/settings/tabs/UserDataManagementSettingTab.vue index 73e761d6..30b19346 100644 --- a/src/views/desktop/user/settings/tabs/UserDataManagementSettingTab.vue +++ b/src/views/desktop/user/settings/tabs/UserDataManagementSettingTab.vue @@ -43,6 +43,12 @@ icon: icons.tags, color: 'secondary' }, + { + title: 'Transaction Pictures', + count: displayDataStatistics ? displayDataStatistics.totalTransactionPictureCount : '-', + icon: icons.pictures, + color: 'error-darken-1' + }, { title: 'Transaction Templates', count: displayDataStatistics ? displayDataStatistics.totalTransactionTemplateCount : '-', @@ -167,6 +173,7 @@ import { mdiViewDashboardOutline, mdiTagOutline, mdiClipboardTextOutline, + mdiImage, mdiClipboardTextClockOutline, mdiAlert } from '@mdi/js'; @@ -185,6 +192,7 @@ export default { accounts: mdiCreditCardOutline, categories: mdiViewDashboardOutline, tags: mdiTagOutline, + pictures: mdiImage, templates: mdiClipboardTextOutline, scheduledTransactions: mdiClipboardTextClockOutline, alert: mdiAlert @@ -205,6 +213,7 @@ export default { totalAccountCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalAccountCount), totalTransactionCategoryCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionCategoryCount), totalTransactionTagCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionTagCount), + totalTransactionPictureCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionPictureCount), totalTransactionTemplateCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionTemplateCount), totalScheduledTransactionCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalScheduledTransactionCount) }; diff --git a/src/views/mobile/users/DataManagementPage.vue b/src/views/mobile/users/DataManagementPage.vue index 53a5b506..06d7a326 100644 --- a/src/views/mobile/users/DataManagementPage.vue +++ b/src/views/mobile/users/DataManagementPage.vue @@ -16,6 +16,7 @@ + @@ -111,6 +112,7 @@ export default { totalAccountCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalAccountCount), totalTransactionCategoryCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionCategoryCount), totalTransactionTagCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionTagCount), + totalTransactionPictureCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionPictureCount), totalTransactionTemplateCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalTransactionTemplateCount), totalScheduledTransactionCount: self.$locale.appendDigitGroupingSymbol(self.userStore, self.dataStatistics.totalScheduledTransactionCount) };