midr @ 40407573e35ff9b617faf84ac715de3d791282e4

 1package routes
 2
 3import (
 4	"embed"
 5	"html/template"
 6	"net/http"
 7
 8	"git.sr.ht/~gabrielgio/midr/controller"
 9	"git.sr.ht/~gabrielgio/midr/db"
10	"git.sr.ht/~gabrielgio/midr/worker"
11	"github.com/gin-gonic/gin"
12)
13
14func HandleRequests(f embed.FS) {
15
16	models := db.EntryModel{DB: db.DB}
17	worker := worker.NewWorkder()
18
19	env := &controller.Env{
20		Entries: models,
21		Worker:  worker,
22	}
23
24	env.StartScheduler()
25
26	r := gin.Default()
27
28	templ := template.Must(template.New("").ParseFS(f, "templates/*.tmpl"))
29	r.SetHTMLTemplate(templ)
30	r.StaticFS("/p", http.FS(f))
31
32	r.GET("/", env.GetEntries)
33	r.GET("/entries/", env.GetEntries)
34	r.GET("entries/createEntry", env.GetEntry)
35	r.POST("entries/", env.CreateEntry)
36	r.GET("entries/:id", env.GetEntry)
37	r.POST("entries/:id", env.UpdateEntry)
38	r.DELETE("entries/:id", env.DeleteEntry)
39	r.GET("jobs/", env.GetJobs)
40	r.Run(":8000")
41}