MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / Create

Method Create

internal/handler/userExample.go:57–83  ·  view source on GitHub ↗

Create a new userExample @Summary Create a new userExample @Description Creates a new userExample entity using the provided data in the request body. @Tags userExample @Accept json @Produce json @Param data body types.CreateUserExampleRequest true "userExample information" @Success 200 {object} type

(c *gin.Context)

Source from the content-addressed store, hash-verified

55// @Router /api/v1/userExample [post]
56// @Security BearerAuth
57func (h *userExampleHandler) Create(c *gin.Context) {
58 form := &types.CreateUserExampleRequest{}
59 err := c.ShouldBindJSON(form)
60 if err != nil {
61 logger.Warn("ShouldBindJSON error: ", logger.Err(err), middleware.GCtxRequestIDField(c))
62 response.Error(c, ecode.InvalidParams)
63 return
64 }
65
66 userExample := &model.UserExample{}
67 err = copier.Copy(userExample, form)
68 if err != nil {
69 response.Error(c, ecode.ErrCreateUserExample)
70 return
71 }
72 // Note: if copier.Copy cannot assign a value to a field, add it here
73
74 ctx := middleware.WrapCtx(c)
75 err = h.iDao.Create(ctx, userExample)
76 if err != nil {
77 logger.Error("Create error", logger.Err(err), logger.Any("form", form), middleware.GCtxRequestIDField(c))
78 response.Output(c, ecode.InternalServerError.ToHTTPCode())
79 return
80 }
81
82 response.Success(c, gin.H{"id": userExample.ID})
83}
84
85// DeleteByID delete a userExample by id
86// @Summary Delete a userExample by id

Callers

nothing calls this directly

Calls 12

WarnFunction · 0.92
ErrFunction · 0.92
GCtxRequestIDFieldFunction · 0.92
ErrorFunction · 0.92
CopyFunction · 0.92
WrapCtxFunction · 0.92
ErrorFunction · 0.92
AnyFunction · 0.92
OutputFunction · 0.92
SuccessFunction · 0.92
ToHTTPCodeMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected