Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post request cannot deal #3497

Closed
YoungBoyGod opened this issue Apr 19, 2024 · 1 comment
Closed

post request cannot deal #3497

YoungBoyGod opened this issue Apr 19, 2024 · 1 comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@YoungBoyGod
Copy link

What version of Go and system type/arch are you using?
go 1.22.0, linux/amd64

What version of GoFrame are you using?
2.7.0

Can this bug be re-produced with the latest release?
post a request

What did you do?
when i post a request {"id":0,"ProductName":"","ProductStatus":""} to goframe ,but get {"id":0,"ProductName":"","ProductStatus":""}
//post
curl --location --request POST 'http://192.168.10.211:8888/v1/product/update' --header 'Content-Type: application/json' --header 'Accept: /' --header 'Host: 192.168.10.211:8888' --header 'Connection: keep-alive' --data-raw '{
"id": 5,
"product_name": "xxxx",
"product_status": "开发中",
}'
{"id":0,"ProductName":"","ProductStatus":""}

//controller
func (c *ControllerV1) UpdateSysProduct(ctx context.Context, req *v1.UpdateSysProductReq) (res *v1.UpdateSysProductRes, err error) {
r := g.RequestFromCtx(ctx)
fmt.Println(req)
r.Response.WriteJson(req)
data := model.UpdateSysProductInput{}
err = gconv.Scan(req, &data)
if err != nil {
return nil, err
}
// 调用服务层方法更新部门信息
err = service.SysProduct().UpdateSysProduct(ctx, model.UpdateSysProductInput{
//Id: req.Id,
//ProductName: req.ProductName,
//ProductStatus: req.ProductStatus,
})

if err != nil {
	return &v1.UpdateSysProductRes{
		Message: gcode.CodeInvalidParameter.Message(),
		Code:    gcode.CodeInvalidParameter.Code(),
	}, err
}
// 更新成功,返回成功的响应
return &v1.UpdateSysProductRes{
	Message: "Product updated successfully",
}, err

}

//api struct
type UpdateSysProductReq struct {
g.Meta path:"/product/update" method:"post" tags:"product管理" summary:"更新单个product信息"
Id int v:"min:1#请选择需要update的内容" json:"id" dc:"productID" // productID
ProductCommonData
}

type UpdateSysProductRes struct {
Message string json:"message" dc:"消息" // 消息
Code int json:"code" dc:"状态码" // 状态码
}

What did you expect to see?

how can i deal it
What did you see instead?

@YoungBoyGod YoungBoyGod added the bug It is confirmed a bug, but don't worry, we'll handle it. label Apr 19, 2024
@YoungBoyGod
Copy link
Author

i am so foolish i have find the root cause due to my json format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

No branches or pull requests

1 participant