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

Method List

internal/service/userExample.go:147–186  ·  view source on GitHub ↗

List get a paginated list of userExamples by custom conditions

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

Source from the content-addressed store, hash-verified

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) {
148 err := req.Validate()
149 if err != nil {
150 logger.Warn("req.Validate error", logger.Err(err), logger.Any("req", req), interceptor.ServerCtxRequestIDField(ctx))
151 return nil, ecode.StatusInvalidParams.Err()
152 }
153 ctx = interceptor.WrapServerCtx(ctx)
154
155 params := &query.Params{}
156 err = copier.Copy(params, req.Params)
157 if err != nil {
158 return nil, ecode.StatusListUserExample.Err()
159 }
160 // Note: if copier.Copy cannot assign a value to a field, add it here
161
162 records, total, err := s.iDao.GetByColumns(ctx, params)
163 if err != nil {
164 if strings.Contains(err.Error(), "query params error:") {
165 logger.Warn("GetByColumns error", logger.Err(err), logger.Any("params", params), interceptor.ServerCtxRequestIDField(ctx))
166 return nil, ecode.StatusInvalidParams.Err()
167 }
168 logger.Error("GetByColumns error", logger.Err(err), logger.Any("params", params), interceptor.ServerCtxRequestIDField(ctx))
169 return nil, ecode.StatusInternalServerError.ToRPCErr()
170 }
171
172 userExamples := []*serverNameExampleV1.UserExample{}
173 for _, record := range records {
174 data, err := convertUserExample(record)
175 if err != nil {
176 logger.Warn("convertUserExample error", logger.Err(err), logger.Any("id", record.ID), interceptor.ServerCtxRequestIDField(ctx))
177 continue
178 }
179 userExamples = append(userExamples, data)
180 }
181
182 return &serverNameExampleV1.ListUserExampleReply{
183 Total: total,
184 UserExamples: userExamples,
185 }, nil
186}
187
188func convertUserExample(record *model.UserExample) (*serverNameExampleV1.UserExample, error) {
189 value := &serverNameExampleV1.UserExample{}

Callers

nothing calls this directly

Calls 13

WarnFunction · 0.92
ErrFunction · 0.92
AnyFunction · 0.92
ServerCtxRequestIDFieldFunction · 0.92
WrapServerCtxFunction · 0.92
CopyFunction · 0.92
ErrorFunction · 0.92
ToRPCErrMethod · 0.80
convertUserExampleFunction · 0.70
ValidateMethod · 0.65
GetByColumnsMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected