(w http.ResponseWriter, r *http.Request)
| 49 | } |
| 50 | |
| 51 | func (a *API) loadUser(w http.ResponseWriter, r *http.Request) (context.Context, error) { |
| 52 | ctx := r.Context() |
| 53 | db := a.db.WithContext(ctx) |
| 54 | |
| 55 | userID, err := uuid.FromString(chi.URLParam(r, "user_id")) |
| 56 | if err != nil { |
| 57 | return nil, apierrors.NewNotFoundError(apierrors.ErrorCodeValidationFailed, "user_id must be an UUID") |
| 58 | } |
| 59 | |
| 60 | observability.LogEntrySetField(r, "user_id", userID) |
| 61 | |
| 62 | u, err := models.FindUserByID(db, userID) |
| 63 | if err != nil { |
| 64 | if models.IsNotFoundError(err) { |
| 65 | return nil, apierrors.NewNotFoundError(apierrors.ErrorCodeUserNotFound, "User not found") |
| 66 | } |
| 67 | return nil, apierrors.NewInternalServerError("Database error loading user").WithInternalError(err) |
| 68 | } |
| 69 | |
| 70 | return withUser(ctx, u), nil |
| 71 | } |
| 72 | |
| 73 | // Use only after requireAuthentication, so that there is a valid user |
| 74 | func (a *API) loadFactor(w http.ResponseWriter, r *http.Request) (context.Context, error) { |
nothing calls this directly
no test coverage detected