Export endpoint
This commit is contained in:
parent
8177ae7065
commit
062236e5e4
1 changed files with 22 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
||||||
package rest
|
package rest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"dynatron.me/x/stillbox/internal/forms"
|
"dynatron.me/x/stillbox/internal/forms"
|
||||||
|
@ -32,6 +33,8 @@ func (tga *talkgroupAPI) Subrouter() http.Handler {
|
||||||
|
|
||||||
r.Post("/import", tga.tgImport)
|
r.Post("/import", tga.tgImport)
|
||||||
|
|
||||||
|
r.Post("/export", tga.tgExport)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +159,25 @@ func (tga *talkgroupAPI) put(w http.ResponseWriter, r *http.Request) {
|
||||||
respond(w, r, record)
|
respond(w, r, record)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tga *talkgroupAPI) tgExport(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var expJob xport.ExportJob
|
||||||
|
ctx := r.Context()
|
||||||
|
|
||||||
|
err := forms.Unmarshal(r, &expJob, forms.WithAcceptBlank(), forms.WithOmitEmpty())
|
||||||
|
if err != nil {
|
||||||
|
wErr(w, r, badRequest(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=stillbox_%s", expJob.TemplateFileName))
|
||||||
|
w.Header().Set("Content-Type", "text/xml")
|
||||||
|
|
||||||
|
err = expJob.Export(ctx, w)
|
||||||
|
if err != nil {
|
||||||
|
wErr(w, r, autoError(err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (tga *talkgroupAPI) tgImport(w http.ResponseWriter, r *http.Request) {
|
func (tga *talkgroupAPI) tgImport(w http.ResponseWriter, r *http.Request) {
|
||||||
var impJob xport.ImportJob
|
var impJob xport.ImportJob
|
||||||
err := forms.Unmarshal(r, &impJob, forms.WithTag("json"), forms.WithAcceptBlank(), forms.WithOmitEmpty())
|
err := forms.Unmarshal(r, &impJob, forms.WithTag("json"), forms.WithAcceptBlank(), forms.WithOmitEmpty())
|
||||||
|
|
Loading…
Reference in a new issue