tests pass for POST /v1/feeds

main
Bel LaPointe 2025-04-28 22:08:32 -06:00
parent e2eb0afe06
commit e4e5529887
2 changed files with 18 additions and 1 deletions

View File

@ -2,14 +2,16 @@ package handler
import (
"context"
"encoding/json"
"io"
"net/http"
"show-rss/src/feeds"
)
func (h Handler) feeds(w http.ResponseWriter, r *http.Request) error {
switch r.Method {
case http.MethodPost:
return h.feedsPost(ctx, r.Body)
return h.feedsPost(r.Context(), r.Body)
default:
http.NotFound(w, r)
}
@ -17,4 +19,18 @@ func (h Handler) feeds(w http.ResponseWriter, r *http.Request) error {
}
func (h Handler) feedsPost(ctx context.Context, r io.Reader) error {
var req struct {
URL string
Cron string
Pattern string
WebhookMethod string
WebhookURL string
WebhookBody string
}
if err := json.NewDecoder(r).Decode(&req); err != nil {
return err
}
_, err := feeds.Insert(ctx, req.URL, req.Cron, req.Pattern, req.WebhookMethod, req.WebhookURL, req.WebhookBody)
return err
}

View File

@ -25,6 +25,7 @@ func TestFeeds(t *testing.T) {
"webhookURL": "wurl",
"webhookBody": "wbody"
}`))
r = r.WithContext(ctx)
h.ServeHTTP(w, r)
if w.Code != http.StatusOK {
t.Errorf("(%d) %s", w.Code, w.Body.Bytes())