diff options
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/sparkles/controller.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/controllers/sparkles/controller.go b/app/controllers/sparkles/controller.go index 4ae028b..dbb5f55 100644 --- a/app/controllers/sparkles/controller.go +++ b/app/controllers/sparkles/controller.go @@ -24,6 +24,9 @@ func (c *Controller) MountTo(mux *http.ServeMux) { mux.HandleFunc("GET /sparkles", c.Index) mux.Handle("POST /sparkles", requireUser(http.HandlerFunc(c.Create))) + + // This is a temporary endpoint to restore a backup + mux.HandleFunc("POST /sparkles/restore", c.Restore) } func (c *Controller) Index(w http.ResponseWriter, r *http.Request) { @@ -54,3 +57,16 @@ func (c *Controller) Create(w http.ResponseWriter, r *http.Request) { return } } + +// This is a temporary endpoint to restore a backup +// of sparkles and can be deleted once we have an actual database +func (c *Controller) Restore(w http.ResponseWriter, r *http.Request) { + sparkles, _ := serde.FromHTTP[[]*domain.Sparkle](r) + log.WithFields(r.Context(), log.Fields{"sparkles": sparkles}) + + x.Each(sparkles, func(sparkle *domain.Sparkle) { + if err := c.db.Save(sparkle); err != nil { + log.WithFields(r.Context(), log.Fields{"error": err}) + } + }) +} |
