-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (50 loc) · 1.88 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"github.com/sense475/sa-64-lab5/controller"
"github.com/sense475/sa-64-lab5/entity"
"github.com/gin-gonic/gin"
)
func main() {
entity.SetupDatabase()
r := gin.Default()
r.Use(CORSMiddleware())
// User Routes
r.GET("/users", controller.ListUsers)
r.GET("/user/:id", controller.GetUser)
r.POST("/users", controller.CreateUser)
r.PATCH("/users", controller.UpdateUser)
r.DELETE("/users/:id", controller.DeleteUser)
// Video Routes
r.GET("/patients", controller.ListPatient)
r.GET("/patient/:id", controller.GetPatient)
r.POST("/patients", controller.CreatePatient)
r.PATCH("/patients", controller.UpdatePatient)
r.DELETE("/patients/:id", controller.DeletePatient)
// Playlist Routes
r.GET("/treatments", controller.ListTreatment)
r.GET("/treatment/:id", controller.GetTreatment)
r.POST("/treatments", controller.CreateTreatment)
r.PATCH("/treatments", controller.UpdateTreatment)
r.DELETE("/treatments/:id", controller.DeleteTreatment)
// Resolution Routes
r.GET("/payments", controller.ListPayment)
r.GET("/payment/:id", controller.GetPayment)
r.POST("/payments", controller.CreatePayment)
r.PATCH("/payments", controller.UpdatePayment)
r.DELETE("/payments/:id", controller.DeletePayment)
// Run the server
r.Run()
}
func CORSMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(204)
return
}
c.Next()
}
}