From 60fe273d7f45951f62edf101b21b74771da4cdbc Mon Sep 17 00:00:00 2001 From: rogerogers Date: Sun, 12 May 2024 16:55:21 +0800 Subject: [PATCH] fix(gomall): category page Signed-off-by: rogerogers --- .../biz/handler/category/category_service.go | 2 +- .../biz/handler/product/product_service.go | 19 +++ .../handler/product/product_service_test.go | 15 +++ .../frontend/biz/router/product/middleware.go | 5 + .../biz/router/product/product_page.go | 1 + gomall/app/frontend/biz/service/category.go | 12 +- .../frontend/biz/service/search_producs.go | 45 +++++++ gomall/app/frontend/hertz_gen/api/api.pb.go | 13 +- .../frontend/category/category_page.pb.go | 41 ++++--- .../hertz_gen/frontend/common/common.pb.go | 14 +-- .../frontend/product/product_page.pb.go | 116 ++++++++++++++---- gomall/app/frontend/template/search.tmpl | 4 +- gomall/idl/frontend/category_page.proto | 4 +- gomall/idl/frontend/product_page.proto | 17 ++- 14 files changed, 241 insertions(+), 67 deletions(-) create mode 100644 gomall/app/frontend/biz/service/search_producs.go diff --git a/gomall/app/frontend/biz/handler/category/category_service.go b/gomall/app/frontend/biz/handler/category/category_service.go index 892dde1e..06d123a6 100644 --- a/gomall/app/frontend/biz/handler/category/category_service.go +++ b/gomall/app/frontend/biz/handler/category/category_service.go @@ -41,5 +41,5 @@ func Category(ctx context.Context, c *app.RequestContext) { return } - utils.SendSuccessResponse(ctx, c, consts.StatusOK, resp) + c.HTML(consts.StatusOK, "category", resp) } diff --git a/gomall/app/frontend/biz/handler/product/product_service.go b/gomall/app/frontend/biz/handler/product/product_service.go index f8dd8102..04a41117 100644 --- a/gomall/app/frontend/biz/handler/product/product_service.go +++ b/gomall/app/frontend/biz/handler/product/product_service.go @@ -42,3 +42,22 @@ func GetProduct(ctx context.Context, c *app.RequestContext) { } c.HTML(consts.StatusOK, "product", utils.WarpResponse(ctx, c, resp)) } + +// SearchProducs . +// @router /search [GET] +func SearchProducs(ctx context.Context, c *app.RequestContext) { + var err error + var req product.SearchProductsReq + err = c.BindAndValidate(&req) + if err != nil { + utils.SendErrResponse(ctx, c, consts.StatusOK, err) + return + } + + resp, err := service.NewSearchProducsService(ctx, c).Run(&req) + if err != nil { + utils.SendErrResponse(ctx, c, consts.StatusOK, err) + return + } + c.HTML(consts.StatusOK, "search", utils.WarpResponse(ctx, c, resp)) +} diff --git a/gomall/app/frontend/biz/handler/product/product_service_test.go b/gomall/app/frontend/biz/handler/product/product_service_test.go index fcc17757..6d9e2815 100644 --- a/gomall/app/frontend/biz/handler/product/product_service_test.go +++ b/gomall/app/frontend/biz/handler/product/product_service_test.go @@ -37,3 +37,18 @@ func TestGetProduct(t *testing.T) { // assert.DeepEqual(t, 200, resp.StatusCode()) // assert.DeepEqual(t, "null", string(resp.Body())) } + +func TestSearchProducs(t *testing.T) { + h := server.Default() + h.GET("/search", SearchProducs) + path := "/search" // todo: you can customize query + body := &ut.Body{Body: bytes.NewBufferString(""), Len: 1} // todo: you can customize body + header := ut.Header{} // todo: you can customize header + w := ut.PerformRequest(h.Engine, "GET", path, body, header) + resp := w.Result() + t.Log(string(resp.Body())) + + // todo edit your unit test. + // assert.DeepEqual(t, 200, resp.StatusCode()) + // assert.DeepEqual(t, "null", string(resp.Body())) +} diff --git a/gomall/app/frontend/biz/router/product/middleware.go b/gomall/app/frontend/biz/router/product/middleware.go index 3d24ae53..da8712eb 100644 --- a/gomall/app/frontend/biz/router/product/middleware.go +++ b/gomall/app/frontend/biz/router/product/middleware.go @@ -29,3 +29,8 @@ func _getproductMw() []app.HandlerFunc { // your code... return nil } + +func _searchproducsMw() []app.HandlerFunc { + // your code... + return nil +} diff --git a/gomall/app/frontend/biz/router/product/product_page.go b/gomall/app/frontend/biz/router/product/product_page.go index 9fe9e6a5..8d7b2cae 100644 --- a/gomall/app/frontend/biz/router/product/product_page.go +++ b/gomall/app/frontend/biz/router/product/product_page.go @@ -32,4 +32,5 @@ func Register(r *server.Hertz) { root := r.Group("/", rootMw()...) root.GET("/product", append(_getproductMw(), product.GetProduct)...) + root.GET("/search", append(_searchproducsMw(), product.SearchProducs)...) } diff --git a/gomall/app/frontend/biz/service/category.go b/gomall/app/frontend/biz/service/category.go index 47b22f63..f3483095 100644 --- a/gomall/app/frontend/biz/service/category.go +++ b/gomall/app/frontend/biz/service/category.go @@ -18,8 +18,10 @@ import ( "context" category "github.com/cloudwego/biz-demo/gomall/app/frontend/hertz_gen/frontend/category" - common "github.com/cloudwego/biz-demo/gomall/app/frontend/hertz_gen/frontend/common" + "github.com/cloudwego/biz-demo/gomall/app/frontend/infra/rpc" + "github.com/cloudwego/biz-demo/gomall/rpc_gen/kitex_gen/product" "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/utils" ) type CategoryService struct { @@ -31,6 +33,10 @@ func NewCategoryService(Context context.Context, RequestContext *app.RequestCont return &CategoryService{RequestContext: RequestContext, Context: Context} } -func (h *CategoryService) Run(req *category.CategoryReq) (resp *common.Empty, err error) { - return +func (h *CategoryService) Run(req *category.CategoryReq) (resp map[string]any, err error) { + p, _ := rpc.ProductClient.ListProducts(h.Context, &product.ListProductsReq{CategoryName: req.Category}) + return utils.H{ + "title": "Category", + "items": p.Products, + }, nil } diff --git a/gomall/app/frontend/biz/service/search_producs.go b/gomall/app/frontend/biz/service/search_producs.go new file mode 100644 index 00000000..bb45f44a --- /dev/null +++ b/gomall/app/frontend/biz/service/search_producs.go @@ -0,0 +1,45 @@ +// Copyright 2024 CloudWeGo Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package service + +import ( + "context" + + product "github.com/cloudwego/biz-demo/gomall/app/frontend/hertz_gen/frontend/product" + "github.com/cloudwego/biz-demo/gomall/app/frontend/infra/rpc" + rpcproduct "github.com/cloudwego/biz-demo/gomall/rpc_gen/kitex_gen/product" + "github.com/cloudwego/hertz/pkg/app" + "github.com/cloudwego/hertz/pkg/common/utils" +) + +type SearchProducsService struct { + RequestContext *app.RequestContext + Context context.Context +} + +func NewSearchProducsService(Context context.Context, RequestContext *app.RequestContext) *SearchProducsService { + return &SearchProducsService{RequestContext: RequestContext, Context: Context} +} + +func (h *SearchProducsService) Run(req *product.SearchProductsReq) (resp map[string]any, err error) { + p, err := rpc.ProductClient.SearchProducts(h.Context, &rpcproduct.SearchProductsReq{Query: req.Q}) + if err != nil { + return nil, err + } + return utils.H{ + "items": p.Results, + "q": req.Q, + }, nil +} diff --git a/gomall/app/frontend/hertz_gen/api/api.pb.go b/gomall/app/frontend/hertz_gen/api/api.pb.go index 0b4a7aa5..47545392 100644 --- a/gomall/app/frontend/hertz_gen/api/api.pb.go +++ b/gomall/app/frontend/hertz_gen/api/api.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v4.22.0 +// protoc v5.26.1 // source: api.proto package api @@ -606,11 +606,12 @@ var file_api_proto_rawDesc = []byte{ 0x07, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x12, 0x1f, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x8e, 0x8d, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x88, 0x01, 0x01, 0x42, 0x38, 0x5a, - 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x69, 0x79, - 0x75, 0x74, 0x61, 0x6e, 0x67, 0x2f, 0x67, 0x6f, 0x6d, 0x61, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, - 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x68, 0x65, 0x72, 0x74, 0x7a, 0x5f, - 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x88, 0x01, 0x01, 0x42, 0x41, 0x5a, + 0x3f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, + 0x64, 0x77, 0x65, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x67, + 0x6f, 0x6d, 0x61, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x2f, 0x68, 0x65, 0x72, 0x74, 0x7a, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var file_api_proto_goTypes = []interface{}{ diff --git a/gomall/app/frontend/hertz_gen/frontend/category/category_page.pb.go b/gomall/app/frontend/hertz_gen/frontend/category/category_page.pb.go index 5ccff0d8..38befcc3 100644 --- a/gomall/app/frontend/hertz_gen/frontend/category/category_page.pb.go +++ b/gomall/app/frontend/hertz_gen/frontend/category/category_page.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v4.22.0 +// protoc v5.26.1 // source: category_page.proto package category @@ -27,7 +27,7 @@ type CategoryReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Category string `protobuf:"bytes,1,opt,name=category,proto3" json:"category,omitempty" form:"category" query:"category"` + Category string `protobuf:"bytes,1,opt,name=category,proto3" json:"category,omitempty" path:"category"` } func (x *CategoryReq) Reset() { @@ -74,24 +74,25 @@ var File_category_page_proto protoreflect.FileDescriptor var file_category_page_proto_rawDesc = []byte{ 0x0a, 0x13, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, - 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x1a, 0x15, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x64, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x29, 0x0a, 0x0b, 0x43, 0x61, - 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x74, - 0x65, 0x67, 0x6f, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x74, - 0x65, 0x67, 0x6f, 0x72, 0x79, 0x32, 0x6e, 0x0a, 0x0f, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, - 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5b, 0x0a, 0x08, 0x43, 0x61, 0x74, 0x65, - 0x67, 0x6f, 0x72, 0x79, 0x12, 0x1e, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, - 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, - 0x79, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, - 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x17, 0xca, 0xc1, - 0x18, 0x13, 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x2f, 0x3a, 0x63, 0x61, 0x74, - 0x65, 0x67, 0x6f, 0x72, 0x79, 0x42, 0x46, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, - 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x69, 0x79, 0x75, 0x74, 0x61, 0x6e, 0x67, 0x2f, 0x67, 0x6f, - 0x6d, 0x61, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x2f, 0x68, 0x65, 0x72, 0x74, 0x7a, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x66, 0x72, 0x6f, 0x6e, - 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x15, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x37, 0x0a, 0x0b, 0x43, 0x61, + 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x65, 0x71, 0x12, 0x28, 0x0a, 0x08, 0x63, 0x61, 0x74, + 0x65, 0x67, 0x6f, 0x72, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0c, 0xd2, 0xbb, 0x18, + 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, + 0x6f, 0x72, 0x79, 0x32, 0x6e, 0x0a, 0x0f, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x5b, 0x0a, 0x08, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, + 0x72, 0x79, 0x12, 0x1e, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x63, 0x61, + 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x2e, 0x43, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x52, + 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x17, 0xca, 0xc1, 0x18, 0x13, + 0x2f, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x2f, 0x3a, 0x63, 0x61, 0x74, 0x65, 0x67, + 0x6f, 0x72, 0x79, 0x42, 0x4f, 0x5a, 0x4d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x77, 0x65, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2d, + 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x67, 0x6f, 0x6d, 0x61, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x2f, + 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x68, 0x65, 0x72, 0x74, 0x7a, 0x5f, 0x67, + 0x65, 0x6e, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x63, 0x61, 0x74, 0x65, + 0x67, 0x6f, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/gomall/app/frontend/hertz_gen/frontend/common/common.pb.go b/gomall/app/frontend/hertz_gen/frontend/common/common.pb.go index cda41d6c..04703d5f 100644 --- a/gomall/app/frontend/hertz_gen/frontend/common/common.pb.go +++ b/gomall/app/frontend/hertz_gen/frontend/common/common.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v4.22.0 +// protoc v5.26.1 // source: frontend/common.proto package common @@ -122,12 +122,12 @@ var file_frontend_common_proto_rawDesc = []byte{ 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x75, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, - 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x44, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x62, 0x61, 0x69, 0x79, 0x75, 0x74, 0x61, 0x6e, 0x67, - 0x2f, 0x67, 0x6f, 0x6d, 0x61, 0x6c, 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x72, 0x6f, 0x6e, - 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x68, 0x65, 0x72, 0x74, 0x7a, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x4d, 0x5a, 0x4b, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x77, 0x65, 0x67, 0x6f, + 0x2f, 0x62, 0x69, 0x7a, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x67, 0x6f, 0x6d, 0x61, 0x6c, 0x6c, + 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x68, 0x65, + 0x72, 0x74, 0x7a, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, + 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/gomall/app/frontend/hertz_gen/frontend/product/product_page.pb.go b/gomall/app/frontend/hertz_gen/frontend/product/product_page.pb.go index 17ee6ed5..db43761c 100644 --- a/gomall/app/frontend/hertz_gen/frontend/product/product_page.pb.go +++ b/gomall/app/frontend/hertz_gen/frontend/product/product_page.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.28.1 -// protoc v4.22.0 +// protoc v5.26.1 // source: product_page.proto package product @@ -69,28 +69,83 @@ func (x *ProductReq) GetId() uint32 { return 0 } +type SearchProductsReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Q string `protobuf:"bytes,1,opt,name=q,proto3" json:"q,omitempty" query:"q"` +} + +func (x *SearchProductsReq) Reset() { + *x = SearchProductsReq{} + if protoimpl.UnsafeEnabled { + mi := &file_product_page_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SearchProductsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SearchProductsReq) ProtoMessage() {} + +func (x *SearchProductsReq) ProtoReflect() protoreflect.Message { + mi := &file_product_page_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SearchProductsReq.ProtoReflect.Descriptor instead. +func (*SearchProductsReq) Descriptor() ([]byte, []int) { + return file_product_page_proto_rawDescGZIP(), []int{1} +} + +func (x *SearchProductsReq) GetQ() string { + if x != nil { + return x.Q + } + return "" +} + var File_product_page_proto protoreflect.FileDescriptor var file_product_page_proto_rawDesc = []byte{ 0x0a, 0x12, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x70, 0x61, 0x67, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x70, - 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x1a, 0x15, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, - 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x09, 0x61, - 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x24, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x64, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x15, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, + 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x24, 0x0a, 0x0a, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0d, 0x42, 0x06, 0xb2, 0xbb, 0x18, 0x02, 0x69, 0x64, 0x52, 0x02, 0x69, 0x64, 0x32, 0x62, - 0x0a, 0x0e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x12, 0x50, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x1c, + 0x28, 0x0d, 0x42, 0x06, 0xb2, 0xbb, 0x18, 0x02, 0x69, 0x64, 0x52, 0x02, 0x69, 0x64, 0x22, 0x28, + 0x0a, 0x11, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, + 0x52, 0x65, 0x71, 0x12, 0x13, 0x0a, 0x01, 0x71, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x05, + 0xb2, 0xbb, 0x18, 0x01, 0x71, 0x52, 0x01, 0x71, 0x32, 0xbd, 0x01, 0x0a, 0x0e, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x50, 0x0a, 0x0a, 0x47, + 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x1c, 0x2e, 0x66, 0x72, 0x6f, 0x6e, + 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x2e, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, + 0x0c, 0xca, 0xc1, 0x18, 0x08, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x59, 0x0a, + 0x0d, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x73, 0x12, 0x23, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, - 0x74, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x22, 0x0c, 0xca, 0xc1, 0x18, 0x08, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, - 0x63, 0x74, 0x42, 0x45, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x62, 0x61, 0x69, 0x79, 0x75, 0x74, 0x61, 0x6e, 0x67, 0x2f, 0x67, 0x6f, 0x6d, 0x61, 0x6c, - 0x6c, 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x68, - 0x65, 0x72, 0x74, 0x7a, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x74, 0x2e, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, + 0x52, 0x65, 0x71, 0x1a, 0x16, 0x2e, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2e, 0x63, + 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x0b, 0xca, 0xc1, 0x18, + 0x07, 0x2f, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x42, 0x4e, 0x5a, 0x4c, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x77, 0x65, 0x67, 0x6f, + 0x2f, 0x62, 0x69, 0x7a, 0x2d, 0x64, 0x65, 0x6d, 0x6f, 0x2f, 0x67, 0x6f, 0x6d, 0x61, 0x6c, 0x6c, + 0x2f, 0x61, 0x70, 0x70, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x2f, 0x68, 0x65, + 0x72, 0x74, 0x7a, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, + 0x2f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -105,16 +160,19 @@ func file_product_page_proto_rawDescGZIP() []byte { return file_product_page_proto_rawDescData } -var file_product_page_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_product_page_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_product_page_proto_goTypes = []interface{}{ - (*ProductReq)(nil), // 0: frontend.product.ProductReq - (*common.Empty)(nil), // 1: frontend.common.Empty + (*ProductReq)(nil), // 0: frontend.product.ProductReq + (*SearchProductsReq)(nil), // 1: frontend.product.SearchProductsReq + (*common.Empty)(nil), // 2: frontend.common.Empty } var file_product_page_proto_depIdxs = []int32{ 0, // 0: frontend.product.ProductService.GetProduct:input_type -> frontend.product.ProductReq - 1, // 1: frontend.product.ProductService.GetProduct:output_type -> frontend.common.Empty - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type + 1, // 1: frontend.product.ProductService.SearchProducs:input_type -> frontend.product.SearchProductsReq + 2, // 2: frontend.product.ProductService.GetProduct:output_type -> frontend.common.Empty + 2, // 3: frontend.product.ProductService.SearchProducs:output_type -> frontend.common.Empty + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -138,6 +196,18 @@ func file_product_page_proto_init() { return nil } } + file_product_page_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SearchProductsReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -145,7 +215,7 @@ func file_product_page_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_product_page_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 1, }, diff --git a/gomall/app/frontend/template/search.tmpl b/gomall/app/frontend/template/search.tmpl index 8a4885ba..deaecb23 100644 --- a/gomall/app/frontend/template/search.tmpl +++ b/gomall/app/frontend/template/search.tmpl @@ -4,7 +4,7 @@
{{ .q }} - +
@@ -29,4 +29,4 @@ {{ end}}
{{ template "footer" . }} -{{ end }} \ No newline at end of file +{{ end }} diff --git a/gomall/idl/frontend/category_page.proto b/gomall/idl/frontend/category_page.proto index 0e475fb9..f0473e19 100644 --- a/gomall/idl/frontend/category_page.proto +++ b/gomall/idl/frontend/category_page.proto @@ -7,7 +7,9 @@ import "frontend/common.proto"; option go_package = "/frontend/category"; -message CategoryReq { string category = 1; } +message CategoryReq { + string category = 1 [(api.path) = "category"]; +} service CategoryService { rpc Category(CategoryReq) returns (common.Empty) { diff --git a/gomall/idl/frontend/product_page.proto b/gomall/idl/frontend/product_page.proto index 4a7a2333..51163e32 100644 --- a/gomall/idl/frontend/product_page.proto +++ b/gomall/idl/frontend/product_page.proto @@ -2,15 +2,24 @@ syntax = "proto3"; package frontend.product; -import "frontend/common.proto"; import "api.proto"; +import "frontend/common.proto"; option go_package = "frontend/product"; -message ProductReq { uint32 id = 1 [ (api.query) = "id" ]; } +message ProductReq { + uint32 id = 1 [(api.query) = "id"]; +} + +message SearchProductsReq { + string q = 1 [(api.query) = "q"]; +} service ProductService { rpc GetProduct(ProductReq) returns (common.Empty) { option (api.get) = "/product"; - }; -} \ No newline at end of file + } + rpc SearchProducs(SearchProductsReq) returns (common.Empty) { + option (api.get) = "/search"; + } +}