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