GetByID get a userExample by id @Summary Get a userExample by id @Description Gets detailed information of a userExample specified by the given id in the path. @Tags userExample @Param id path string true "id" @Accept json @Produce json @Success 200 {object} types.GetUserExampleByIDReply{} @Router /
(c *gin.Context)
| 167 | // @Router /api/v1/userExample/{id} [get] |
| 168 | // @Security BearerAuth |
| 169 | func (h *userExampleHandler) GetByID(c *gin.Context) { |
| 170 | _, id, isAbort := getUserExampleIDFromPath(c) |
| 171 | if isAbort { |
| 172 | response.Error(c, ecode.InvalidParams) |
| 173 | return |
| 174 | } |
| 175 | |
| 176 | ctx := middleware.WrapCtx(c) |
| 177 | userExample, err := h.iDao.GetByID(ctx, id) |
| 178 | if err != nil { |
| 179 | if errors.Is(err, database.ErrRecordNotFound) { |
| 180 | logger.Warn("GetByID not found", logger.Err(err), logger.Any("id", id), middleware.GCtxRequestIDField(c)) |
| 181 | response.Error(c, ecode.NotFound) |
| 182 | } else { |
| 183 | logger.Error("GetByID error", logger.Err(err), logger.Any("id", id), middleware.GCtxRequestIDField(c)) |
| 184 | response.Output(c, ecode.InternalServerError.ToHTTPCode()) |
| 185 | } |
| 186 | return |
| 187 | } |
| 188 | |
| 189 | data := &types.UserExampleObjDetail{} |
| 190 | err = copier.Copy(data, userExample) |
| 191 | if err != nil { |
| 192 | response.Error(c, ecode.ErrGetByIDUserExample) |
| 193 | return |
| 194 | } |
| 195 | // Note: if copier.Copy cannot assign a value to a field, add it here |
| 196 | |
| 197 | response.Success(c, gin.H{"userExample": data}) |
| 198 | } |
| 199 | |
| 200 | // List get a paginated list of userExamples by custom conditions |
| 201 | // @Summary Get a paginated list of userExamples by custom conditions |
nothing calls this directly
no test coverage detected