diff options
| author | mo khan <mo@mokhan.ca> | 2025-04-11 17:52:29 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-04-11 17:52:29 -0600 |
| commit | ff15873b766f5be308c9967859bfeb7da7cfa21a (patch) | |
| tree | 5a3799dda610dc6fd7bda3adeab931fb60e986a0 /app/controllers/sparkles | |
| parent | 6d525bb541230c707a160ef670449b7588abf43b (diff) | |
refactor: split routes to separate controller files
Diffstat (limited to 'app/controllers/sparkles')
| -rw-r--r-- | app/controllers/sparkles/controller.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/controllers/sparkles/controller.go b/app/controllers/sparkles/controller.go new file mode 100644 index 0000000..365184f --- /dev/null +++ b/app/controllers/sparkles/controller.go @@ -0,0 +1,27 @@ +package sparkles + +import ( + "net/http" + + "github.com/xlgmokha/x/pkg/serde" + "gitlab.com/mokhax/sparkled/pkg/db" + "gitlab.com/mokhax/sparkled/pkg/domain" +) + +type Controller struct { + db db.Repository +} + +func New(db db.Repository) *Controller { + return &Controller{db: db} +} + +func (c *Controller) Index(w http.ResponseWriter, r *http.Request) { + serde.ToHTTP(w, r, c.db.All()) +} + +func (c *Controller) Create(w http.ResponseWriter, r *http.Request) { + sparkle, _ := serde.FromHTTP[*domain.Sparkle](r) + c.db.Save(sparkle) + w.WriteHeader(http.StatusCreated) +} |
