Browse Source

Merge branch 'feature/contact_field_template' into debug

* feature/contact_field_template:
  更新和查询自定义字段模板
boweniac 3 weeks ago
parent
commit
3707fd7322

+ 1 - 1
desc/wechat/contact_field_template.api

@@ -61,5 +61,5 @@ service Wechat {
 
     // Get contact_field_template by ID | 通过ID获取 ContactFieldTemplate
     @handler getContactFieldTemplateById
-    post /contact_field_template (IDReq) returns (ContactFieldTemplateInfoResp)
+    post /contact_field_template () returns (ContactFieldTemplateInfoResp)
 }

+ 1 - 14
internal/handler/contact_field_template/get_contact_field_template_by_id_handler.go

@@ -7,7 +7,6 @@ import (
 
 	"wechat-api/internal/logic/contact_field_template"
 	"wechat-api/internal/svc"
-	"wechat-api/internal/types"
 )
 
 // swagger:route post /contact_field_template contact_field_template GetContactFieldTemplateById
@@ -16,25 +15,13 @@ import (
 //
 // Get contact_field_template by ID | 通过ID获取 ContactFieldTemplate
 //
-// Parameters:
-//  + name: body
-//    require: true
-//    in: body
-//    type: IDReq
-//
 // Responses:
 //  200: ContactFieldTemplateInfoResp
 
 func GetContactFieldTemplateByIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
 	return func(w http.ResponseWriter, r *http.Request) {
-		var req types.IDReq
-		if err := httpx.Parse(r, &req, true); err != nil {
-			httpx.ErrorCtx(r.Context(), w, err)
-			return
-		}
-
 		l := contact_field_template.NewGetContactFieldTemplateByIdLogic(r.Context(), svcCtx)
-		resp, err := l.GetContactFieldTemplateById(&req)
+		resp, err := l.GetContactFieldTemplateById()
 		if err != nil {
 			httpx.ErrorCtx(r.Context(), w, err)
 		} else {

+ 3 - 3
internal/logic/contact_field_template/get_contact_field_template_by_id_logic.go

@@ -27,11 +27,11 @@ func NewGetContactFieldTemplateByIdLogic(ctx context.Context, svcCtx *svc.Servic
 		svcCtx: svcCtx}
 }
 
-func (l *GetContactFieldTemplateByIdLogic) GetContactFieldTemplateById(req *types.IDReq) (resp *types.ContactFieldTemplateInfoResp, err error) {
+func (l *GetContactFieldTemplateByIdLogic) GetContactFieldTemplateById() (resp *types.ContactFieldTemplateInfoResp, err error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
-	data, err := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.ID(req.Id), contactfieldtemplate.OrganizationID(organizationId)).First(l.ctx)
+	data, err := l.svcCtx.DB.ContactFieldTemplate.Query().Where(contactfieldtemplate.OrganizationID(organizationId)).First(l.ctx)
 	if err != nil && !ent.IsNotFound(err) {
-		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, nil)
 	}
 
 	template := ConvertCustomToInternal(data.Template)

+ 1 - 7
internal/logic/contact_field_template/update_contact_field_template_logic.go

@@ -2,7 +2,6 @@ package contact_field_template
 
 import (
 	"context"
-	"errors"
 	"github.com/suyuan32/simple-admin-common/msg/errormsg"
 	"wechat-api/ent/contactfieldtemplate"
 	"wechat-api/internal/utils/dberrorhandler"
@@ -29,16 +28,11 @@ func NewUpdateContactFieldTemplateLogic(ctx context.Context, svcCtx *svc.Service
 func (l *UpdateContactFieldTemplateLogic) UpdateContactFieldTemplate(req *types.ContactFieldTemplateInfo) (resp *types.BaseMsgResp, err error) {
 	organizationId := l.ctx.Value("organizationId").(uint64)
 
-	if *req.Id <= 0 {
-		l.Error("记录ID不存在")
-		return nil, errors.New("记录ID不存在")
-	}
-
 	template := ConvertContactFieldTemplates(req.Template)
 
 	err = l.svcCtx.DB.ContactFieldTemplate.
 		Update().
-		Where(contactfieldtemplate.IDEQ(*req.Id), contactfieldtemplate.OrganizationID(organizationId)).
+		Where(contactfieldtemplate.OrganizationID(organizationId)).
 		SetTemplate(template).
 		Exec(l.ctx)