diff options
author | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-15 12:40:12 +0200 |
---|---|---|
committer | Gabriel A. Giovanini <mail@gabrielgio.me> | 2022-06-15 12:40:12 +0200 |
commit | 64496464b3812839c1e4b440bdf69cc84f39c491 (patch) | |
tree | a695e52f736c39e8518247bf48b9743506a3c32f /routes | |
parent | 04a10f2acd73d88f90433755bfbe667c5174acb5 (diff) | |
download | mdir-64496464b3812839c1e4b440bdf69cc84f39c491.tar.gz mdir-64496464b3812839c1e4b440bdf69cc84f39c491.tar.bz2 mdir-64496464b3812839c1e4b440bdf69cc84f39c491.zip |
ref: Move to a MVC like approach
Before everything was dumped into the controller file, now it is spread
out a bit.
It is still far from good, like the controller is not really a
controller... baby steps I guess
The refactored was based on this post:
https://www.alexedwards.net/blog/organising-database-access
Diffstat (limited to 'routes')
-rw-r--r-- | routes/routes.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/routes/routes.go b/routes/routes.go index d78acc7..a960277 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -2,17 +2,23 @@ package routes import ( "git.sr.ht/~gabrielgio/midr/controller" + "git.sr.ht/~gabrielgio/midr/db" "github.com/gin-gonic/gin" ) func HandleRequests() { + + env := &controller.Env{ + Entries: db.EntryModel{DB: db.DB}, + } + r := gin.Default() r.LoadHTMLGlob("templates/*") - r.GET("/", controller.GetEntries) - r.GET("entries/", controller.GetEntry) - r.POST("entries/", controller.CreateEntry) - r.GET("entries/:id", controller.GetEntry) - r.POST("entries/:id", controller.UpdateEntry) - r.DELETE("entries/:id", controller.DeleteEntry) + r.GET("/", env.GetEntries) + r.GET("entries/", env.GetEntry) + r.POST("entries/", env.CreateEntry) + r.GET("entries/:id", env.GetEntry) + r.POST("entries/:id", env.UpdateEntry) + r.DELETE("entries/:id", env.DeleteEntry) r.Run(":8000") } |