ExtractNotificationTemplateParam grabs a notification template from the "notification_template" URL parameter.
(db database.Store)
| 22 | |
| 23 | // ExtractNotificationTemplateParam grabs a notification template from the "notification_template" URL parameter. |
| 24 | func ExtractNotificationTemplateParam(db database.Store) func(http.Handler) http.Handler { |
| 25 | return func(next http.Handler) http.Handler { |
| 26 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 27 | ctx := r.Context() |
| 28 | notifTemplateID, parsed := ParseUUIDParam(rw, r, "notification_template") |
| 29 | if !parsed { |
| 30 | return |
| 31 | } |
| 32 | nt, err := db.GetNotificationTemplateByID(r.Context(), notifTemplateID) |
| 33 | if httpapi.Is404Error(err) { |
| 34 | httpapi.ResourceNotFound(rw) |
| 35 | return |
| 36 | } |
| 37 | if err != nil { |
| 38 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 39 | Message: "Internal error fetching notification template.", |
| 40 | Detail: err.Error(), |
| 41 | }) |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | ctx = context.WithValue(ctx, notificationTemplateParamContextKey{}, nt) |
| 46 | next.ServeHTTP(rw, r.WithContext(ctx)) |
| 47 | }) |
| 48 | } |
| 49 | } |
no test coverage detected