From 09ddf53b018b9ffa6d3e82efec69eefec6e6e310 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 1 Sep 2024 00:33:11 +0800 Subject: [PATCH] limit maximum count of tags in a transaction --- pkg/api/transactions.go | 8 ++++++++ pkg/errs/transaction_tag.go | 1 + src/locales/en.json | 1 + src/locales/zh_Hans.json | 1 + 4 files changed, 11 insertions(+) diff --git a/pkg/api/transactions.go b/pkg/api/transactions.go index 50731f91..daeb5791 100644 --- a/pkg/api/transactions.go +++ b/pkg/api/transactions.go @@ -646,6 +646,10 @@ func (a *TransactionsApi) TransactionCreateHandler(c *core.WebContext) (any, *er return nil, errs.ErrTransactionTagIdInvalid } + if len(tagIds) > 10 { + return nil, errs.ErrTransactionTagTooMuch + } + pictureIds, err := utils.StringArrayToInt64Array(transactionCreateReq.PictureIds) if err != nil { @@ -772,6 +776,10 @@ func (a *TransactionsApi) TransactionModifyHandler(c *core.WebContext) (any, *er return nil, errs.ErrTransactionTagIdInvalid } + if len(tagIds) > 10 { + return nil, errs.ErrTransactionTagTooMuch + } + pictureIds, err := utils.StringArrayToInt64Array(transactionModifyReq.PictureIds) if err != nil { diff --git a/pkg/errs/transaction_tag.go b/pkg/errs/transaction_tag.go index 2ee54321..401b913e 100644 --- a/pkg/errs/transaction_tag.go +++ b/pkg/errs/transaction_tag.go @@ -10,4 +10,5 @@ var ( ErrTransactionTagNameAlreadyExists = NewNormalError(NormalSubcategoryTag, 3, http.StatusBadRequest, "transaction tag name already exists") ErrTransactionTagInUseCannotBeDeleted = NewNormalError(NormalSubcategoryTag, 4, http.StatusBadRequest, "transaction tag is in use and cannot be deleted") ErrTransactionTagIndexNotFound = NewNormalError(NormalSubcategoryTag, 5, http.StatusBadRequest, "transaction tag index not found") + ErrTransactionTagTooMuch = NewNormalError(NormalSubcategoryTag, 6, http.StatusBadRequest, "transaction tags too much") ) diff --git a/src/locales/en.json b/src/locales/en.json index b62c9acd..ba11bffa 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1081,6 +1081,7 @@ "transaction tag name already exists": "Transaction tag title already exists", "transaction tag is in use and cannot be deleted": "Transaction tag is in use and it cannot be deleted", "transaction tag index not found": "Transaction tag index is not found", + "transaction tags too much": "There are too many transaction tags", "data export not allowed": "User data export is not allowed", "transaction template id is invalid": "Transaction template ID is invalid", "transaction template not found": "Transaction template is not found", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index dc73812c..0f4ad497 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1081,6 +1081,7 @@ "transaction tag name already exists": "交易标签标题已经存在", "transaction tag is in use and cannot be deleted": "交易标签正在被使用,无法删除", "transaction tag index not found": "交易标签索引不存在", + "transaction tags too much": "交易标签过多", "data export not allowed": "不允许用户数据导出", "transaction template id is invalid": "交易模板ID无效", "transaction template not found": "交易模板不存在",