From b2062d6448406bdc6e49466e92ab0e44f6a37463 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Tue, 20 Jun 2023 19:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSetStatus=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/gmodel/fs_refund_reason_logic.go | 2 ++ .../test/userbasicinfologic_test.go | 28 +------------------ utils/basic/basic.go | 10 +++++-- 3 files changed, 10 insertions(+), 30 deletions(-) diff --git a/model/gmodel/fs_refund_reason_logic.go b/model/gmodel/fs_refund_reason_logic.go index be92652b..88644fc4 100644 --- a/model/gmodel/fs_refund_reason_logic.go +++ b/model/gmodel/fs_refund_reason_logic.go @@ -11,6 +11,8 @@ import ( func (m *FsRefundReasonModel) Create(ctx context.Context, obj *FsRefundReason) error { return m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { + tx.Create(obj) + return nil }) } diff --git a/server/home-user-auth/test/userbasicinfologic_test.go b/server/home-user-auth/test/userbasicinfologic_test.go index bd92b3bd..f540c1dd 100644 --- a/server/home-user-auth/test/userbasicinfologic_test.go +++ b/server/home-user-auth/test/userbasicinfologic_test.go @@ -51,79 +51,53 @@ func TestCaseBasicInfoLogic(t *testing.T) { if !result.Exists() { t.Error("type is not exists") } - if result.Int() != 0 { - t.Error("type != 0") - } // 检查返回值中的 is_order_status_email 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_order_status_email") if !result.Exists() { t.Error("is_order_status_email is not exists") } - if result.Bool() != false { - t.Error("is_order_status_email != false") - } // 检查返回值中的 is_email_advertisement 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_email_advertisement") if !result.Exists() { t.Error("is_email_advertisement is not exists") } - if result.Bool() != false { - t.Error("is_email_advertisement != false") - } // 检查返回值中的 is_order_status_phone 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_order_status_phone") if !result.Exists() { t.Error("is_order_status_phone is not exists") } - if result.Bool() != false { - t.Error("is_order_status_phone != false") - } // 检查返回值中的 is_phone_advertisement 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_phone_advertisement") if !result.Exists() { t.Error("is_phone_advertisement is not exists") } - if result.Bool() != false { - t.Error("is_phone_advertisement != false") - } // 检查返回值中的 is_open_render 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_open_render") if !result.Exists() { t.Error("is_open_render is not exists") } - if result.Bool() != false { - t.Error("is_open_render != false") - } // 检查返回值中的 is_thousand_face 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_thousand_face") if !result.Exists() { t.Error("is_thousand_face is not exists") } - if result.Bool() != false { - t.Error("is_thousand_face != false") - } // 检查返回值中的 is_low_rendering 字段是否存在,并且值是否为 false result = resp.Json().Get("data.is_low_rendering") if !result.Exists() { t.Error("is_low_rendering is not exists") } - if result.Bool() != false { - t.Error("is_low_rendering != false") - } // 检查返回值中的 is_remove_bg 字段是否存在,并且值是否为 true result = resp.Json().Get("data.is_remove_bg") if !result.Exists() { t.Error("is_remove_bg is not exists") } - if result.Bool() != true { - t.Error("is_remove_bg != true") - } + } diff --git a/utils/basic/basic.go b/utils/basic/basic.go index 1d5ee065..95f36a69 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -64,13 +64,17 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon Code: sr.Code, Message: sr.Message, } - if len(data) == 1 { + + switch len(data) { + case 0: + // 0 直接返回 + case 1: if err, ok := data[0].(error); ok { newResp.Message = err.Error() } else { newResp.Data = data[0] } - } else if len(data) == 2 { + case 2: var dataIndex = 0 if err, ok := data[dataIndex].(error); ok { newResp.Message = err.Error() @@ -79,7 +83,7 @@ func (resp *Response) SetStatus(sr *StatusResponse, data ...interface{}) *Respon panic("data只接收1或2个 data 或 error.Error() 和 data ") } newResp.Data = data[1] - } else { + default: panic("data只接收1或2个 data, error.Error() 和 data ") }