ui can edit
parent
bd67eb0dfe
commit
d7f098bea0
|
|
@ -10,18 +10,18 @@ import (
|
||||||
|
|
||||||
func (h Handler) feeds(w http.ResponseWriter, r *http.Request) error {
|
func (h Handler) feeds(w http.ResponseWriter, r *http.Request) error {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case http.MethodPost:
|
case http.MethodPost, http.MethodPut:
|
||||||
if err := r.ParseForm(); err != nil {
|
if err := r.ParseForm(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return h.feedsPost(r.Context(), r.Form)
|
return h.feedsUpsert(r.Context(), r.URL.Query().Get("id"), r.Form)
|
||||||
default:
|
default:
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Handler) feedsPost(ctx context.Context, form url.Values) error {
|
func (h Handler) feedsUpsert(ctx context.Context, id string, form url.Values) error {
|
||||||
var req feeds.Version
|
var req feeds.Version
|
||||||
for k, v := range map[string]*string{
|
for k, v := range map[string]*string{
|
||||||
"Cron": &req.Cron,
|
"Cron": &req.Cron,
|
||||||
|
|
@ -36,6 +36,9 @@ func (h Handler) feedsPost(ctx context.Context, form url.Values) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if id == "" {
|
||||||
_, err := feeds.Insert(ctx, req.URL, req.Cron, req.Pattern, req.WebhookMethod, req.WebhookURL, req.WebhookBody)
|
_, err := feeds.Insert(ctx, req.URL, req.Cron, req.Pattern, req.WebhookMethod, req.WebhookURL, req.WebhookBody)
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
return feeds.Update(ctx, id, req.URL, req.Cron, req.Pattern, req.WebhookMethod, req.WebhookURL, req.WebhookBody)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
Update <code><a target="_blank" href="{{ .editing_url }}">{{ .editing.URL }}</a></code> (<a href="?">clear</a>)
|
Update <code><a target="_blank" href="{{ .editing_url }}">{{ .editing.URL }}</a></code> (<a href="?">clear</a>)
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</h3>
|
</h3>
|
||||||
<form method="POST" action="/v1/feeds">
|
<form method="POST" action="/v1/feeds?id={{ .editing.ID }}">
|
||||||
{{ range $k, $v := .editing }}
|
{{ range $k, $v := .editing }}
|
||||||
{{ if not (in $k "Created" "Deleted" "Updated" "ID") }}
|
{{ if not (in $k "Created" "Deleted" "Updated" "ID") }}
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue