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

Method GetByID

internal/service/userExample.go:119–144  ·  view source on GitHub ↗

GetByID get a userExample by id

(ctx context.Context, req *serverNameExampleV1.GetUserExampleByIDRequest)

Source from the content-addressed store, hash-verified

117
118// GetByID get a userExample by id
119func (s *userExample) GetByID(ctx context.Context, req *serverNameExampleV1.GetUserExampleByIDRequest) (*serverNameExampleV1.GetUserExampleByIDReply, error) {
120 err := req.Validate()
121 if err != nil {
122 logger.Warn("req.Validate error", logger.Err(err), logger.Any("req", req), interceptor.ServerCtxRequestIDField(ctx))
123 return nil, ecode.StatusInvalidParams.Err()
124 }
125 ctx = interceptor.WrapServerCtx(ctx)
126
127 record, err := s.iDao.GetByID(ctx, req.Id)
128 if err != nil {
129 if errors.Is(err, database.ErrRecordNotFound) {
130 logger.Warn("GetByID error", logger.Err(err), logger.Any("id", req.Id), interceptor.ServerCtxRequestIDField(ctx))
131 return nil, ecode.StatusNotFound.Err()
132 }
133 logger.Error("GetByID error", logger.Err(err), logger.Any("id", req.Id), interceptor.ServerCtxRequestIDField(ctx))
134 return nil, ecode.StatusInternalServerError.ToRPCErr()
135 }
136
137 data, err := convertUserExample(record)
138 if err != nil {
139 logger.Warn("convertUserExample error", logger.Err(err), logger.Any("userExample", record), interceptor.ServerCtxRequestIDField(ctx))
140 return nil, ecode.StatusGetByIDUserExample.Err()
141 }
142
143 return &serverNameExampleV1.GetUserExampleByIDReply{UserExample: data}, nil
144}
145
146// List get a paginated list of userExamples by custom conditions
147func (s *userExample) List(ctx context.Context, req *serverNameExampleV1.ListUserExampleRequest) (*serverNameExampleV1.ListUserExampleReply, error) {

Callers

nothing calls this directly

Calls 11

WarnFunction · 0.92
ErrFunction · 0.92
AnyFunction · 0.92
ServerCtxRequestIDFieldFunction · 0.92
WrapServerCtxFunction · 0.92
ErrorFunction · 0.92
ToRPCErrMethod · 0.80
convertUserExampleFunction · 0.70
ValidateMethod · 0.65
GetByIDMethod · 0.65
ErrMethod · 0.45

Tested by

no test coverage detected