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)
| 55 | // @Router /api/v1/userExample [post] |
| 56 | // @Security BearerAuth |
| 57 | func (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 |
nothing calls this directly
no test coverage detected