List get a paginated list of userExamples by custom conditions
(ctx context.Context, req *serverNameExampleV1.ListUserExampleRequest)
| 133 | |
| 134 | // List get a paginated list of userExamples by custom conditions |
| 135 | func (h *userExamplePbHandler) List(ctx context.Context, req *serverNameExampleV1.ListUserExampleRequest) (*serverNameExampleV1.ListUserExampleReply, error) { |
| 136 | err := req.Validate() |
| 137 | if err != nil { |
| 138 | logger.Warn("req.Validate error", logger.Err(err), logger.Any("req", req), middleware.CtxRequestIDField(ctx)) |
| 139 | return nil, ecode.InvalidParams.Err() |
| 140 | } |
| 141 | |
| 142 | params := &query.Params{} |
| 143 | err = copier.Copy(params, req.Params) |
| 144 | if err != nil { |
| 145 | return nil, ecode.ErrListUserExample.Err() |
| 146 | } |
| 147 | // Note: if copier.Copy cannot assign a value to a field, add it here |
| 148 | |
| 149 | records, total, err := h.userExampleDao.GetByColumns(ctx, params) |
| 150 | if err != nil { |
| 151 | if strings.Contains(err.Error(), "query params error:") { |
| 152 | logger.Warn("GetByColumns error", logger.Err(err), logger.Any("params", params), middleware.CtxRequestIDField(ctx)) |
| 153 | return nil, ecode.InvalidParams.Err() |
| 154 | } |
| 155 | logger.Error("GetByColumns error", logger.Err(err), logger.Any("params", params), middleware.CtxRequestIDField(ctx)) |
| 156 | return nil, ecode.InternalServerError.Err() |
| 157 | } |
| 158 | |
| 159 | userExamples := []*serverNameExampleV1.UserExample{} |
| 160 | for _, record := range records { |
| 161 | data, err := convertUserExamplePb(record) |
| 162 | if err != nil { |
| 163 | logger.Warn("convertUserExample error", logger.Err(err), logger.Any("id", record.ID), middleware.CtxRequestIDField(ctx)) |
| 164 | continue |
| 165 | } |
| 166 | userExamples = append(userExamples, data) |
| 167 | } |
| 168 | |
| 169 | return &serverNameExampleV1.ListUserExampleReply{ |
| 170 | Total: total, |
| 171 | UserExamples: userExamples, |
| 172 | }, nil |
| 173 | } |
| 174 | |
| 175 | func convertUserExamplePb(record *model.UserExample) (*serverNameExampleV1.UserExample, error) { |
| 176 | value := &serverNameExampleV1.UserExample{} |
nothing calls this directly
no test coverage detected