GetByID get a userExample by id
(ctx context.Context, req *serverNameExampleV1.GetUserExampleByIDRequest)
| 117 | |
| 118 | // GetByID get a userExample by id |
| 119 | func (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 |
| 147 | func (s *userExample) List(ctx context.Context, req *serverNameExampleV1.ListUserExampleRequest) (*serverNameExampleV1.ListUserExampleReply, error) { |
nothing calls this directly
no test coverage detected