List get a paginated list of userExamples by custom conditions
(ctx context.Context, req *serverNameExampleV1.ListUserExampleRequest)
| 145 | |
| 146 | // List get a paginated list of userExamples by custom conditions |
| 147 | func (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 | |
| 188 | func convertUserExample(record *model.UserExample) (*serverNameExampleV1.UserExample, error) { |
| 189 | value := &serverNameExampleV1.UserExample{} |
nothing calls this directly
no test coverage detected