diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-28 17:32:40 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-28 17:32:40 -0600 |
| commit | f79995c0825cb754b2fabdd4845a1b94af73ecb1 (patch) | |
| tree | 1378e4da2da2c52ac961b6d3eda6282b7afb3e36 /app | |
| parent | 01eea6aa24b4754b6e81b3396980d713759d6370 (diff) | |
feat: add a temporary endpoint to restore sparkles
Diffstat (limited to 'app')
| -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}) + } + }) +} |
