func registerRoutes(e *gin.Engine) { controller := rc.ResourceController{} controller.DatabaseProvider = Database resourceNames := []string{"RecordMatchContext", "RecordMatchSystemInterface", "RecordSet"} for _, name := range resourceNames { e.GET("/"+name+"/:id", controller.GetResource) e.POST("/"+name, controller.CreateResource) e.PUT("/"+name+"/:id", controller.UpdateResource) e.DELETE("/"+name+"/:id", controller.DeleteResource) e.GET("/"+name, controller.GetResources) } e.POST("/AnswerKey", controller.SetAnswerKey) name := "RecordMatchRun" e.GET("/"+name, controller.GetResources) e.GET("/"+name+"/:id", controller.GetResource) e.POST("/"+name, rc.CreateRecordMatchRunHandler(Database)) e.PUT("/"+name+"/:id", controller.UpdateResource) e.DELETE("/"+name+"/:id", controller.DeleteResource) e.GET("/RecordMatchRunMetrics", rc.GetRecordMatchRunMetricsHandler(Database)) e.GET("/RecordMatchRunLinks/:id", rc.GetRecordMatchRunLinksHandler(Database)) e.Static("/ptmatch/api/", "api") }
func RegisterRoutes(r *gin.Engine) { r.GET("/", func(c *gin.Context) { // c.String(http.StatusOK, "this is our home page") c.HTML(http.StatusOK, "index.html", nil) }) // --------------------------- user apis --------------- r.POST("/v1/users", controllers.User_new) r.GET("/v1/users/:userId", controllers.User_get) r.PUT("/v1/users/:userId", controllers.User_update) r.DELETE("/v1/users/:userId", controllers.User_delete) // --------------------------- system apis --------------- r.GET("/sys/install", controllers.Sys_getInstall) r.POST("/sys/install", controllers.Sys_install) }
func (h *UserHandlers) RegisterHandlers(g *gin.Engine) { g.GET("/user", h.All) g.GET("/user/:id", h.GetUser) g.PUT("/user", h.CreateUser) g.POST("/user/:id", h.UpdateUser) g.DELETE("/user/:id", h.DeleteUser) g.POST("/user/:id/password", h.ChangePassword) }
// Controller for taxonomies resources func Controller(r *gin.Engine, db *sql.DB) { r.GET("/taxonomies", func(c *gin.Context) { taxonomies, err := ListAllTaxonomies(db) if err != nil { c.AbortWithError(400, err) return } c.Header("Content-Type", "application/json") c.String(200, taxonomies) }) r.POST("/taxonomy", func(c *gin.Context) { tax := new(Taxonomy) err := c.BindJSON(&tax) if err != nil { c.Error(err) return } err = CreateTaxonomy(tax, db) if err != nil { c.AbortWithError(400, err) return } c.String(200, "") }) r.DELETE("/taxonomy/:id", func(c *gin.Context) { defer func() { if r := recover(); r != nil { c.AbortWithError(400, r.(error)) } }() id := getID(c) err := DeleteTaxonomy(id, db) if err != nil { panic(err) } c.String(200, "") }) r.PUT("/taxonomy/:id", func(c *gin.Context) { defer func() { if r := recover(); r != nil { c.AbortWithError(400, r.(error)) } }() id := getID(c) tax := new(Taxonomy) err := c.BindJSON(&tax) if err != nil { panic(err) } err = UpdateTaxonomy(id, tax, db) if err != nil { c.AbortWithError(400, err) return } c.String(200, "") }) }
func (tr *TemplatesResource) RegisterRoutes(c *gin.Engine) { c.GET("/api/templates", tr.Index) c.GET("/api/templates/:id", tr.Show) c.POST("/api/templates", tr.Create) c.POST("/api/templates/:id", tr.Update) c.PUT("/api/templates/:id", tr.Update) c.DELETE("/api/templates/:id", tr.Delete) c.POST("/api/templates/:id/convert", tr.Convert) c.POST("/api/convert", tr.ConvertRaw) }
func Register(engine *gin.Engine) { engine.Use(Recovery) engine.Use(Errors) engine.GET("/events", eventsGet) engine.GET("/profile", profileGet) engine.POST("/profile", profilePost) engine.DELETE("/profile", profileDel) engine.GET("/ping", pingGet) engine.POST("/stop", stopPost) engine.GET("/status", statusGet) }
func DeleteUserHttpSession(db gorm.DB, router *gin.Engine) { router.DELETE("/user_http_session/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { user_http_session := &model.UserHttpSession{ UserHttpSessionId: model.UserHttpSessionId{Id: id}, } if err := db.First(user_http_session).Error; err == nil { db.Delete(user_http_session) c.AbortWithStatus(http.StatusOK) } else { c.AbortWithStatus(http.StatusNotFound) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func DeleteLike(db gorm.DB, router *gin.Engine) { router.DELETE("/like/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { like := &model.Like{ LikeId: model.LikeId{Id: id}, } if err := db.First(like).Error; err == nil { db.Delete(like) c.AbortWithStatus(http.StatusOK) } else { c.AbortWithStatus(http.StatusNotFound) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func DeleteWallEntry(db gorm.DB, router *gin.Engine) { router.DELETE("/wall_entry/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { wall_entry := &model.WallEntry{ WallEntryId: model.WallEntryId{Id: id}, } if err := db.First(wall_entry).Error; err == nil { db.Delete(wall_entry) c.AbortWithStatus(http.StatusOK) } else { c.AbortWithStatus(http.StatusNotFound) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func DeleteGroupAdmin(db gorm.DB, router *gin.Engine) { router.DELETE("/group_admin/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { group_admin := &model.GroupAdmin{ GroupAdminId: model.GroupAdminId{Id: id}, } if err := db.First(group_admin).Error; err == nil { db.Delete(group_admin) c.AbortWithStatus(http.StatusOK) } else { c.AbortWithStatus(http.StatusNotFound) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
//Mount mount routes func (p *Engine) Mount(r *gin.Engine) { ag := r.Group("/admin", p.Jwt.CurrentUserHandler(true), p.Jwt.MustAdminHandler()) ag.GET("/site/info", p.getAdminSiteInfo) ag.POST("/site/info", web.Rest(p.postAdminSiteInfo)) ag.DELETE("/cache", web.Rest(p.deleteAdminCache)) ag.GET("/notices", web.Rest(p.getNotices)) ag.POST("/notices", web.Rest(p.postNotices)) ag.DELETE("/notices/:id", web.Rest(p.deleteNotice)) r.GET("/notices", p.Cache.Page(time.Hour*24, web.Rest(p.getNotices))) r.GET("/personal/self", p.Jwt.CurrentUserHandler(true), web.Rest(p.getPersonalSelf)) r.GET("/personal/logs", p.Jwt.CurrentUserHandler(true), web.Rest(p.getPersonalLogs)) r.DELETE("/personal/signOut", p.Jwt.CurrentUserHandler(true), p.deleteSignOut) r.GET("/locales/:lang", p.Cache.Page(time.Hour*24, p.getLocale)) r.GET("/site/info", p.Cache.Page(time.Hour*24, p.getSiteInfo)) r.POST("/oauth2/callback", web.Rest(p.postOauth2Callback)) }
func DeleteSpaceSetting(db gorm.DB, router *gin.Engine) { router.DELETE("/space_setting/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { space_setting := &model.SpaceSetting{ SpaceSettingId: model.SpaceSettingId{Id: id}, } if err := db.First(space_setting).Error; err == nil { db.Delete(space_setting) c.AbortWithStatus(http.StatusOK) } else { c.AbortWithStatus(http.StatusNotFound) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func DeleteModuleEnabled(db gorm.DB, router *gin.Engine) { router.DELETE("/module_enabled/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { module_enabled := &model.ModuleEnabled{ ModuleEnabledId: model.ModuleEnabledId{Id: id}, } if err := db.First(module_enabled).Error; err == nil { db.Delete(module_enabled) c.AbortWithStatus(http.StatusOK) } else { c.AbortWithStatus(http.StatusNotFound) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func Register(r *gin.Engine) { r.Use(func(c *gin.Context) { // Run this on all requests // Should be moved to a proper middleware c.Writer.Header().Set("Access-Control-Allow-Origin", "*") c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type,Token") c.Next() }) r.GET("/", func(c *gin.Context) { c.String(200, "Y'all ready for this? \n\nOh no! They were ready for that.") //c.JSON(200, gin.H{"Pong": "Ping"}) }) //Auth authHandler := new(handlers.CCAuthHandler) r.POST("/auth/login", authHandler.BasicAuth) //Middleware // r.Use(authHandler.TokenAuthMiddleware()) // User routes userApi := new(api.CCUser) r.GET("/user", userApi.Get) r.POST("/user", userApi.Post) r.DELETE("/user", userApi.Delete) // Program routes programApi := new(api.CCProgram) r.GET("/program", programApi.Get) r.POST("/program", programApi.Post) r.DELETE("/program", programApi.Delete) // Event routes eventApi := new(api.CCEvent) r.GET("/event", eventApi.Get) r.POST("/event", eventApi.Post) r.PUT("/event/edit", eventApi.Edit) r.DELETE("/event", eventApi.Delete) // Volunteer routes volunteerApi := new(api.CCVolunteer) r.GET("/event/volunteer", volunteerApi.Get) r.POST("/event/volunteer", volunteerApi.Post) r.PUT("/event/volunteer/log", volunteerApi.LogTime) r.DELETE("/event/volunteer", volunteerApi.Delete) // Moments routes momentApi := new(api.CCMoment) r.GET("/event/moment", momentApi.Get) r.DELETE("/event/moment", momentApi.Delete) r.POST("/event/moment", momentApi.Post) //Rating r.POST("/event/moment/rate", momentApi.Rate) //Credits r.GET("/event/moment/credit", momentApi.Credit) //Image Upload //Auth uploadHandler := new(handlers.CCUploadHandler) r.POST("/upload", uploadHandler.Upload) }