tests pass for POST /v1/feeds
parent
e2eb0afe06
commit
e4e5529887
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in New Issue