// ==========================================================================
// 生成日期：{{.CreatedAt}}
// 生成路径: apps/{{.PackageName}}/router/{{.TableName}}.go
// 生成人：{{.FunctionAuthor}}
// ==========================================================================
package router

import (
    "github.com/PandaXGO/PandaKit/model"
    "github.com/PandaXGO/PandaKit/restfulx"
	"pandax/apps/{{.PackageName}}/api"
	"pandax/apps/{{.PackageName}}/entity"
	"pandax/apps/{{.PackageName}}/services"

	restfulspec "github.com/emicklei/go-restful-openapi/v2"
    "github.com/emicklei/go-restful/v3"
)

func Init{{.ClassName}}Router(container *restful.Container) {
	s := &api.{{.ClassName}}Api{
		{{.ClassName}}App: services.{{.ClassName}}ModelDao,
	}

	ws := new(restful.WebService)
    	ws.Path("/{{.PackageName}}/{{.BusinessName}}").Produces(restful.MIME_JSON)
    	tags := []string{"{{.BusinessName}}"}


    ws.Route(ws.GET("/list").To(func(request *restful.Request, response *restful.Response) {
    		restfulx.NewReqCtx(request, response).WithLog("获取{{.FunctionName}}分页列表").Handle(s.Get{{.ClassName}}List)
    }).
    	Doc("获取{{.FunctionName}}分页列表").
    	Param(ws.QueryParameter("pageNum", "页数").Required(true).DataType("int")).
        Param(ws.QueryParameter("pageSize", "每页条数").Required(true).DataType("int")).
    	Metadata(restfulspec.KeyOpenAPITags, tags).
    	Writes(model.ResultPage{}).
    	Returns(200, "OK", model.ResultPage{}))

    ws.Route(ws.GET("/{{"{"}}{{.PkJsonField}}{{"}"}}").To(func(request *restful.Request, response *restful.Response) {
    	restfulx.NewReqCtx(request, response).WithLog("获取{{.FunctionName}}信息").Handle(s.Get{{.ClassName}})
    }).
    	Doc("获取{{.FunctionName}}信息").
    	Param(ws.PathParameter("{{.PkJsonField}}", "Id").DataType("{{.PkGoType}}")).
    	Metadata(restfulspec.KeyOpenAPITags, tags).
    	Writes(entity.{{.ClassName}}{}). // on the response
    	Returns(200, "OK", entity.{{.ClassName}}{}).
    	Returns(404, "Not Found", nil))

    ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
    	restfulx.NewReqCtx(request, response).WithLog("添加{{.FunctionName}}信息").Handle(s.Insert{{.ClassName}})
    }).
    	Doc("添加{{.FunctionName}}信息").
    	Metadata(restfulspec.KeyOpenAPITags, tags).
    	Reads(entity.{{.ClassName}}{}))

    ws.Route(ws.PUT("").To(func(request *restful.Request, response *restful.Response) {
    	restfulx.NewReqCtx(request, response).WithLog("修改{{.FunctionName}}信息").Handle(s.Update{{.ClassName}})
    }).
    	Doc("修改{{.FunctionName}}信息").
    	Metadata(restfulspec.KeyOpenAPITags, tags).
    	Reads(entity.{{.ClassName}}{}))

    ws.Route(ws.DELETE("/{{"{"}}{{.PkJsonField}}{{"}"}}").To(func(request *restful.Request, response *restful.Response) {
    	restfulx.NewReqCtx(request, response).WithLog("删除{{.FunctionName}}信息").Handle(s.Delete{{.ClassName}})
    }).
    	Doc("删除{{.FunctionName}}信息").
    	Metadata(restfulspec.KeyOpenAPITags, tags).
    	Param(ws.PathParameter("{{.PkJsonField}}", "多id 1,2,3").DataType("string")))

    container.Add(ws)
}

