规范气站客服工单枚举
This commit is contained in:
@@ -47,7 +47,9 @@ func CreateTicket(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
var request ticketRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil ||
|
||||
!isSupportedTicketCategory(request.Category) ||
|
||||
!isSupportedTicketPriority(request.Priority) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
@@ -77,7 +79,9 @@ func UpdateTicket(ctx *gin.Context) {
|
||||
return
|
||||
}
|
||||
var request ticketRequest
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil {
|
||||
if err := ctx.ShouldBindJSON(&request); err != nil ||
|
||||
!isSupportedTicketCategory(request.Category) ||
|
||||
!isSupportedTicketPriority(request.Priority) {
|
||||
infra.Response.Error(ctx, errcode.ErrInvalidArgument)
|
||||
return
|
||||
}
|
||||
|
||||
24
backend/api/internal/logic/gas/ticket_values.go
Normal file
24
backend/api/internal/logic/gas/ticket_values.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Package gas 定义气站客服工单允许写入的业务枚举。
|
||||
// 版本:v1.0.0
|
||||
package gas
|
||||
|
||||
var supportedTicketCategories = map[string]struct{}{
|
||||
"delivery": {}, "installation": {}, "repair": {},
|
||||
"inspection": {}, "reinspection": {}, "customer_service": {},
|
||||
}
|
||||
|
||||
var supportedTicketPriorities = map[string]struct{}{
|
||||
"low": {}, "normal": {}, "high": {}, "urgent": {},
|
||||
}
|
||||
|
||||
// isSupportedTicketCategory 判断工单分类是否属于气站端公开枚举。
|
||||
func isSupportedTicketCategory(category string) bool {
|
||||
_, ok := supportedTicketCategories[category]
|
||||
return ok
|
||||
}
|
||||
|
||||
// isSupportedTicketPriority 判断工单优先级是否属于气站端公开枚举。
|
||||
func isSupportedTicketPriority(priority string) bool {
|
||||
_, ok := supportedTicketPriorities[priority]
|
||||
return ok
|
||||
}
|
||||
22
backend/api/internal/logic/gas/ticket_values_test.go
Normal file
22
backend/api/internal/logic/gas/ticket_values_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package gas
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestSupportedTicketValues 验证气站端工单枚举白名单。
|
||||
func TestSupportedTicketValues(t *testing.T) {
|
||||
for _, category := range []string{"delivery", "installation", "repair", "inspection", "reinspection", "customer_service"} {
|
||||
if !isSupportedTicketCategory(category) {
|
||||
t.Fatalf("标准工单分类未通过校验:%s", category)
|
||||
}
|
||||
}
|
||||
for _, priority := range []string{"low", "normal", "high", "urgent"} {
|
||||
if !isSupportedTicketPriority(priority) {
|
||||
t.Fatalf("标准工单优先级未通过校验:%s", priority)
|
||||
}
|
||||
}
|
||||
for _, value := range []string{"", "unknown", " normal "} {
|
||||
if isSupportedTicketCategory(value) || isSupportedTicketPriority(value) {
|
||||
t.Fatalf("非标准工单枚举不应通过校验:%q", value)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user