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

Method GetByID

internal/handler/userExample.go:169–198  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

167// @Router /api/v1/userExample/{id} [get]
168// @Security BearerAuth
169func (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

Callers

nothing calls this directly

Calls 13

ErrorFunction · 0.92
WrapCtxFunction · 0.92
WarnFunction · 0.92
ErrFunction · 0.92
AnyFunction · 0.92
GCtxRequestIDFieldFunction · 0.92
ErrorFunction · 0.92
OutputFunction · 0.92
CopyFunction · 0.92
SuccessFunction · 0.92
getUserExampleIDFromPathFunction · 0.85
ToHTTPCodeMethod · 0.80

Tested by

no test coverage detected