浏览代码

完成请求的文档添加

yjp 1 年之前
父节点
当前提交
f4fa2884e4

+ 27 - 12
framework/core/api/request/common.go

@@ -1,10 +1,12 @@
 package request
 
+// IDRequestParam 包含ID字段的请求参数接口
 type IDRequestParam interface {
 	Params
 	GetID() string
 }
 
+// IDJsonBody JsonBody中包含ID字段的定义结构
 type IDJsonBody struct {
 	ID string `json:"id" binding:"required" assign:"toField:ID"`
 }
@@ -13,27 +15,31 @@ func (id *IDJsonBody) GetID() string {
 	return id.ID
 }
 
-type IDPathParam struct {
-	ID string `uri:"id" binding:"required" assign:"toField:ID"`
+// IDQueryParam 查询参数中包含ID字段的定义结构
+type IDQueryParam struct {
+	ID string `form:"id" binding:"required" assign:"toField:ID"`
 }
 
-func (id *IDPathParam) GetID() string {
+func (id *IDQueryParam) GetID() string {
 	return id.ID
 }
 
-type IDQueryParam struct {
-	ID string `form:"id" binding:"required" assign:"toField:ID"`
+// IDPathParam 路径参数中包含ID字段的定义结构
+type IDPathParam struct {
+	ID string `uri:"id" binding:"required" assign:"toField:ID"`
 }
 
-func (id *IDQueryParam) GetID() string {
+func (id *IDPathParam) GetID() string {
 	return id.ID
 }
 
+// TenantIDRequestParam 包含租户ID字段的请求参数接口
 type TenantIDRequestParam interface {
 	Params
 	GetTenantID() string
 }
 
+// TenantIDJsonBody JsonBody中包含租户ID字段的定义结构
 type TenantIDJsonBody struct {
 	TenantID string `json:"tenantId" binding:"required" assign:"toField:TenantID"`
 }
@@ -42,28 +48,32 @@ func (id *IDJsonBody) GetTenantID() string {
 	return id.ID
 }
 
-type TenantIDPathParam struct {
-	TenantID string `uri:"tenantId" binding:"required" assign:"toField:TenantID"`
+// TenantIDQueryParam 查询参数中包含租户ID字段的定义结构
+type TenantIDQueryParam struct {
+	TenantID string `form:"tenantId" binding:"required" assign:"toField:TenantID"`
 }
 
-func (id *IDPathParam) GetTenantID() string {
+func (id *IDQueryParam) GetTenantID() string {
 	return id.ID
 }
 
-type TenantIDQueryParam struct {
-	TenantID string `form:"tenantId" binding:"required" assign:"toField:TenantID"`
+// TenantIDPathParam 路径参数中包含租户ID字段的定义结构
+type TenantIDPathParam struct {
+	TenantID string `uri:"tenantId" binding:"required" assign:"toField:TenantID"`
 }
 
-func (id *IDQueryParam) GetTenantID() string {
+func (id *IDPathParam) GetTenantID() string {
 	return id.ID
 }
 
+// QueryRequestParams 包含查询请求需要字段的查询参数接口
 type QueryRequestParams interface {
 	Params
 	GetPageNo() int
 	GetPageSize() int
 }
 
+// BaseQueryParams 包含查询请求需要字段的查询参数基础实现
 type BaseQueryParams struct {
 	PageNo   int `form:"pageNo" assign:"-"`
 	PageSize int `form:"pageSize" assign:"-"`
@@ -77,24 +87,29 @@ func (q *BaseQueryParams) GetPageSize() int {
 	return q.PageSize
 }
 
+// QueryWithIDRequestParams 包含查通过ID查询需要字段的查询参数接口
 type QueryWithIDRequestParams interface {
 	IDRequestParam
 	QueryRequestParams
 }
 
+// BaseQueryWithIDParams 包含查通过ID查询需要字段的查询参数基础实现
 type BaseQueryWithIDParams struct {
 	IDQueryParam
 	BaseQueryParams
 }
 
+// CreateUserIDJsonBody JsonBody中包含创建用户ID字段的定义结构
 type CreateUserIDJsonBody struct {
 	CreateUserID string `json:"createUserId" binding:"required" assign:"toField:CreateUserID"`
 }
 
+// UpdateUserIDJsonBody JsonBody中包含最近更新用户ID字段的定义结构
 type UpdateUserIDJsonBody struct {
 	UpdateUserID string `json:"updateUserId" binding:"required" assign:"toField:LastUpdateUserID"`
 }
 
+// DeleteUserIDQueryParams JsonBody中包含删除用户ID字段的定义结构
 type DeleteUserIDQueryParams struct {
 	DeleteUserID string `form:"deleteUserId" binding:"required" assign:"toField:LastUpdateUserID"`
 }

+ 24 - 0
framework/core/api/request/params.go

@@ -8,12 +8,28 @@ import (
 	"reflect"
 )
 
+// Params 请求参数接口(抽象类)
 type Params interface{}
 
+// AssignRequestParamsToDomainObject 基于assign tag将请求参数赋值到领域对象
+// 参数:
+// - params: 请求参数
+// - domainObject: 领域对象
+// 返回值:
+// - 错误
 func AssignRequestParamsToDomainObject(params Params, domainObject domain.Object) error {
 	return assign.DefaultUsage(params, domainObject)
 }
 
+// Field 获取请求对象中的字段值
+// 泛型参数:
+// - T: 请求对象中的字段值的类型
+// 参数:
+// - params: 请求参数
+// - fieldName: 字段名
+// 返回值:
+// - 请求对象中的字段值
+// - 错误
 func Field[T any](params Params, fieldName string) (T, error) {
 	zero := reflectutils.Zero[T]()
 
@@ -38,6 +54,14 @@ func Field[T any](params Params, fieldName string) (T, error) {
 	return retValue, nil
 }
 
+// ToConcrete 将请求参数转换为具体的请求参数结构类型
+// 泛型参数:
+// - T: 具体的请求参数结构类型
+// 参数:
+// - params: 请求参数
+// 返回值:
+// - 具体的请求参数结构
+// - 错误
 func ToConcrete[T Params](params Params) (T, error) {
 	zero := reflectutils.Zero[T]()
 

+ 37 - 0
framework/core/api/request/params_bind_func.go

@@ -6,8 +6,15 @@ import (
 	"github.com/pkg/errors"
 )
 
+// BindRequestParamsFunc 请求绑定函数
 type BindRequestParamsFunc func(c *api.Context, params Params) error
 
+// BindJsonBody 绑定Json类型的Body请求到请求参数接口
+// 参数:
+// - c: 上下文
+// - params: 请求参数接口
+// 返回值:
+// - 错误
 func BindJsonBody(c *api.Context, params Params) error {
 	err := c.ShouldBindJSON(params)
 	if err != nil {
@@ -17,6 +24,12 @@ func BindJsonBody(c *api.Context, params Params) error {
 	return nil
 }
 
+// BindQueryParams 绑定查询参数到请求参数接口
+// 参数:
+// - c: 上下文
+// - params: 请求参数接口
+// 返回值:
+// - 错误
 func BindQueryParams(c *api.Context, params Params) error {
 	err := c.ShouldBindQuery(params)
 	if err != nil {
@@ -26,6 +39,12 @@ func BindQueryParams(c *api.Context, params Params) error {
 	return nil
 }
 
+// BindPathParams 绑定路径参数到请求参数接口
+// 参数:
+// - c: 上下文
+// - params: 请求参数接口
+// 返回值:
+// - 错误
 func BindPathParams(c *api.Context, params Params) error {
 	err := c.ShouldBindUri(params)
 	if err != nil {
@@ -35,6 +54,12 @@ func BindPathParams(c *api.Context, params Params) error {
 	return nil
 }
 
+// BindMultipartForm 绑定multipart body到请求参数接口
+// 参数:
+// - c: 上下文
+// - params: 请求参数接口
+// 返回值:
+// - 错误
 func BindMultipartForm(c *api.Context, params Params) error {
 	err := c.ShouldBindWith(params, binding.FormMultipart)
 	if err != nil {
@@ -44,6 +69,12 @@ func BindMultipartForm(c *api.Context, params Params) error {
 	return nil
 }
 
+// BindFormBody 绑定form body到请求参数接口
+// 参数:
+// - c: 上下文
+// - params: 请求参数接口
+// 返回值:
+// - 错误
 func BindFormBody(c *api.Context, params Params) error {
 	err := c.ShouldBindWith(params, binding.Form)
 	if err != nil {
@@ -53,6 +84,12 @@ func BindFormBody(c *api.Context, params Params) error {
 	return nil
 }
 
+// BindXMLBody 绑定xml body到请求参数接口
+// 参数:
+// - c: 上下文
+// - params: 请求参数接口
+// 返回值:
+// - 错误
 func BindXMLBody(c *api.Context, params Params) error {
 	err := c.ShouldBindXML(params)
 	if err != nil {