func PutSpaceSetting(db gorm.DB, router *gin.Engine) {
	// PUT /space_setting
	// Update space_setting data by id
	router.PUT("/space_setting/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var space_settingData model.SpaceSettingData
			if err := c.BindJSON(&space_settingData); err == nil {
				space_setting := &model.SpaceSetting{
					SpaceSettingData: space_settingData,
					SpaceSettingId:   model.SpaceSettingId{Id: id},
				}
				if err := checkDataSpaceSetting(space_setting.SpaceSettingData); err {
					checkSpaceSetting := &model.SpaceSetting{
						SpaceSettingData: space_settingData,
						SpaceSettingId:   model.SpaceSettingId{Id: id},
					}
					if err := db.First(checkSpaceSetting).Error; err == nil {
						db.Save(&space_setting)
						c.JSON(http.StatusOK, space_setting)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
func PutUserHttpSession(db gorm.DB, router *gin.Engine) {
	// PUT /user_http_session
	// Update user_http_session data by id
	router.PUT("/user_http_session/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var user_http_sessionData model.UserHttpSessionData
			if err := c.BindJSON(&user_http_sessionData); err == nil {
				user_http_session := &model.UserHttpSession{
					UserHttpSessionData: user_http_sessionData,
					UserHttpSessionId:   model.UserHttpSessionId{Id: id},
				}
				if err := checkDataUserHttpSession(user_http_session.UserHttpSessionData); err {
					checkUserHttpSession := &model.UserHttpSession{
						UserHttpSessionData: user_http_sessionData,
						UserHttpSessionId:   model.UserHttpSessionId{Id: id},
					}
					if err := db.First(checkUserHttpSession).Error; err == nil {
						db.Save(&user_http_session)
						c.JSON(http.StatusOK, user_http_session)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #3
0
func PutActivity(db gorm.DB, router *gin.Engine) {
	// PUT /activity
	// Update activity data by id
	router.PUT("/activity/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var activityData model.ActivityData
			if err := c.BindJSON(&activityData); err == nil {
				activity := &model.Activity{
					ActivityData: activityData,
					ActivityId:   model.ActivityId{Id: id},
				}
				if err := checkDataActivity(activity.ActivityData); err {
					checkActivity := &model.Activity{
						ActivityData: activityData,
						ActivityId:   model.ActivityId{Id: id},
					}
					if err := db.First(checkActivity).Error; err == nil {
						db.Save(&activity)
						c.JSON(http.StatusOK, activity)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #4
0
func PutGroupAdmin(db gorm.DB, router *gin.Engine) {
	// PUT /group_admin
	// Update group_admin data by id
	router.PUT("/group_admin/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var group_adminData model.GroupAdminData
			if err := c.BindJSON(&group_adminData); err == nil {
				group_admin := &model.GroupAdmin{
					GroupAdminData: group_adminData,
					GroupAdminId:   model.GroupAdminId{Id: id},
				}
				if err := checkDataGroupAdmin(group_admin.GroupAdminData); err {
					checkGroupAdmin := &model.GroupAdmin{
						GroupAdminData: group_adminData,
						GroupAdminId:   model.GroupAdminId{Id: id},
					}
					if err := db.First(checkGroupAdmin).Error; err == nil {
						db.Save(&group_admin)
						c.JSON(http.StatusOK, group_admin)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #5
0
func PutNotification(db gorm.DB, router *gin.Engine) {
	// PUT /notification
	// Update notification data by id
	router.PUT("/notification/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var notificationData model.NotificationData
			if err := c.BindJSON(&notificationData); err == nil {
				notification := &model.Notification{
					NotificationData: notificationData,
					NotificationId:   model.NotificationId{Id: id},
				}
				if err := checkDataNotification(notification.NotificationData); err {
					checkNotification := &model.Notification{
						NotificationData: notificationData,
						NotificationId:   model.NotificationId{Id: id},
					}
					if err := db.First(checkNotification).Error; err == nil {
						db.Save(&notification)
						c.JSON(http.StatusOK, notification)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #6
0
func PutFile(db gorm.DB, router *gin.Engine) {
	// PUT /file
	// Update file data by id
	router.PUT("/file/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var fileData model.FileData
			if err := c.BindJSON(&fileData); err == nil {
				file := &model.File{
					FileData: fileData,
					FileId:   model.FileId{Id: id},
				}
				if err := checkDataFile(file.FileData); err {
					checkFile := &model.File{
						FileData: fileData,
						FileId:   model.FileId{Id: id},
					}
					if err := db.First(checkFile).Error; err == nil {
						db.Save(&file)
						c.JSON(http.StatusOK, file)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #7
0
func PutUrlOembed(db gorm.DB, router *gin.Engine) {
	// PUT /url_oembed
	// Update url_oembed data by id
	router.PUT("/url_oembed/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var url_oembedData model.UrlOembedData
			if err := c.BindJSON(&url_oembedData); err == nil {
				url_oembed := &model.UrlOembed{
					UrlOembedData: url_oembedData,
					UrlOembedId:   model.UrlOembedId{Id: id},
				}
				if err := checkDataUrlOembed(url_oembed.UrlOembedData); err {
					checkUrlOembed := &model.UrlOembed{
						UrlOembedData: url_oembedData,
						UrlOembedId:   model.UrlOembedId{Id: id},
					}
					if err := db.First(checkUrlOembed).Error; err == nil {
						db.Save(&url_oembed)
						c.JSON(http.StatusOK, url_oembed)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #8
0
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")
}
Beispiel #9
0
func PutContent(db gorm.DB, router *gin.Engine) {
	// PUT /content
	// Update content data by id
	router.PUT("/content/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var contentData model.ContentData
			if err := c.BindJSON(&contentData); err == nil {
				content := &model.Content{
					ContentData: contentData,
					ContentId:   model.ContentId{Id: id},
				}
				if err := checkDataContent(content.ContentData); err {
					checkContent := &model.Content{
						ContentData: contentData,
						ContentId:   model.ContentId{Id: id},
					}
					if err := db.First(checkContent).Error; err == nil {
						db.Save(&content)
						c.JSON(http.StatusOK, content)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #10
0
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 PutModuleEnabled(db gorm.DB, router *gin.Engine) {
	// PUT /module_enabled
	// Update module_enabled data by id
	router.PUT("/module_enabled/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var module_enabledData model.ModuleEnabledData
			if err := c.BindJSON(&module_enabledData); err == nil {
				module_enabled := &model.ModuleEnabled{
					ModuleEnabledData: module_enabledData,
					ModuleEnabledId:   model.ModuleEnabledId{Id: id},
				}
				if err := checkDataModuleEnabled(module_enabled.ModuleEnabledData); err {
					checkModuleEnabled := &model.ModuleEnabled{
						ModuleEnabledData: module_enabledData,
						ModuleEnabledId:   model.ModuleEnabledId{Id: id},
					}
					if err := db.First(checkModuleEnabled).Error; err == nil {
						db.Save(&module_enabled)
						c.JSON(http.StatusOK, module_enabled)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #12
0
func PutLike(db gorm.DB, router *gin.Engine) {
	// PUT /like
	// Update like data by id
	router.PUT("/like/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var likeData model.LikeData
			if err := c.BindJSON(&likeData); err == nil {
				like := &model.Like{
					LikeData: likeData,
					LikeId:   model.LikeId{Id: id},
				}
				if err := checkDataLike(like.LikeData); err {
					checkLike := &model.Like{
						LikeData: likeData,
						LikeId:   model.LikeId{Id: id},
					}
					if err := db.First(checkLike).Error; err == nil {
						db.Save(&like)
						c.JSON(http.StatusOK, like)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
func PutProfileFieldCategory(db gorm.DB, router *gin.Engine) {
	// PUT /profile_field_category
	// Update profile_field_category data by id
	router.PUT("/profile_field_category/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var profile_field_categoryData model.ProfileFieldCategoryData
			if err := c.BindJSON(&profile_field_categoryData); err == nil {
				profile_field_category := &model.ProfileFieldCategory{
					ProfileFieldCategoryData: profile_field_categoryData,
					ProfileFieldCategoryId:   model.ProfileFieldCategoryId{Id: id},
				}
				if err := checkDataProfileFieldCategory(profile_field_category.ProfileFieldCategoryData); err {
					checkProfileFieldCategory := &model.ProfileFieldCategory{
						ProfileFieldCategoryData: profile_field_categoryData,
						ProfileFieldCategoryId:   model.ProfileFieldCategoryId{Id: id},
					}
					if err := db.First(checkProfileFieldCategory).Error; err == nil {
						db.Save(&profile_field_category)
						c.JSON(http.StatusOK, profile_field_category)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #14
0
func PutWallEntry(db gorm.DB, router *gin.Engine) {
	// PUT /wall_entry
	// Update wall_entry data by id
	router.PUT("/wall_entry/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var wall_entryData model.WallEntryData
			if err := c.BindJSON(&wall_entryData); err == nil {
				wall_entry := &model.WallEntry{
					WallEntryData: wall_entryData,
					WallEntryId:   model.WallEntryId{Id: id},
				}
				if err := checkDataWallEntry(wall_entry.WallEntryData); err {
					checkWallEntry := &model.WallEntry{
						WallEntryData: wall_entryData,
						WallEntryId:   model.WallEntryId{Id: id},
					}
					if err := db.First(checkWallEntry).Error; err == nil {
						db.Save(&wall_entry)
						c.JSON(http.StatusOK, wall_entry)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
Beispiel #15
0
func PutPost(db gorm.DB, router *gin.Engine) {
	// PUT /post
	// Update post data by id
	router.PUT("/post/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			var postData model.PostData
			if err := c.BindJSON(&postData); err == nil {
				post := &model.Post{
					PostData: postData,
					PostId:   model.PostId{Id: id},
				}
				if err := checkDataPost(post.PostData); err {
					checkPost := &model.Post{
						PostData: postData,
						PostId:   model.PostId{Id: id},
					}
					if err := db.First(checkPost).Error; err == nil {
						db.Save(&post)
						c.JSON(http.StatusOK, post)
					} else {
						c.AbortWithStatus(http.StatusNotFound)
					}
				} else {
					c.AbortWithStatus(http.StatusBadRequest)
				}
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
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)
}
Beispiel #17
0
// 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, "")
	})
}
Beispiel #18
0
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)
}
Beispiel #19
0
func Use(router *gin.Engine) {
	// pets
	router.GET("/pets", pets.Index)
	router.GET("/pets/:id", pets.Show)
	router.POST("/pets", pets.Create)
	router.PUT("/pets/:id", pets.Update)

	// owners
	router.GET("/owners", owners.Index)
	router.POST("/owners", owners.Create)

	// tasks
	router.GET("/tasks", tasks.Index)
	router.GET("/tasks/:id", tasks.Show)
	router.POST("/tasks", tasks.Create)
	router.PUT("/tasks/:id", tasks.Update)
}
Beispiel #20
0
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)
}
Beispiel #21
0
func BindPlayerRoutes(router *gin.Engine) {
	router.GET("/api/v1/players", GetPlayers)
	router.POST("/api/v1/players", CreatePlayer)
	router.PUT("/api/v1/players/:id", UpdatePlayer)
}