新增index首页服务

This commit is contained in:
2024-10-02 22:10:58 +08:00
parent 30f3ec55c2
commit 9fd6f70630
12 changed files with 357 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package product
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"tianyuan-api/apps/index/internal/logic/product"
"tianyuan-api/apps/index/internal/svc"
"tianyuan-api/apps/index/internal/types"
xhttp "github.com/zeromicro/x/http"
)
func GetProductByIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductByIdReq
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := product.NewGetProductByIdLogic(r.Context(), svcCtx)
resp, err := l.GetProductById(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,30 @@
package product
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"tianyuan-api/apps/index/internal/logic/product"
"tianyuan-api/apps/index/internal/svc"
"tianyuan-api/apps/index/internal/types"
xhttp "github.com/zeromicro/x/http"
)
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetProductListReq
if err := httpx.Parse(r, &req); err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
return
}
l := product.NewGetProductListLogic(r.Context(), svcCtx)
resp, err := l.GetProductList(&req)
if err != nil {
xhttp.JsonBaseResponseCtx(r.Context(), w, err)
} else {
xhttp.JsonBaseResponseCtx(r.Context(), w, resp)
}
}
}