Esempio n. 1
0
func ( self  * ApiServers )	Create ()		( revel.Result )	{
	var	(
		returnData	= map [ string ] string {	"result" : "ok"	}
		server	= models.NewServerFromParams ( self.Params )
	)
	if	server.Label == ""	{
		returnData [ "error" ]	= "Cannot create unLabeled server"
		delete ( returnData, "result" )
		return	self.RenderJson ( returnData )
	}

	( * ServersMap )[ server.Label ]	= server
	returnData [ "url" ]	= routes.ApiServers.Show ( server.Label )

	return	self.RenderJson ( returnData )
}
Esempio n. 2
0
func ( self  * ApiServers )	Action ( method, id  string )		( revel.Result )	{

	server, result	:= self.GetResource ( id )

	if	server == nil	{
		return	result
	}

	if	method == ""	{
		method	= self.Params.Get ( "_method" )
	}

	var returnData	= map [ string ] string {
		"result" : "ok",
	}

	switch	strings.ToLower ( method )	{
		case "delete"	:
			returnData [ "result" ]	= fmt.Sprintf ( "%s was deleted", server.Label )
			delete ( * ServersMap, server.Label )
			server.Delete ()

		case "update"	:	fallthrough
		default	:
			var updatedServer	= models.NewServerFromParams ( self.Params )
			if	updatedServer.Label == ""	{
				returnData [ "error" ]	= "Cannot create unLabeled server"
				delete ( returnData, "result" )
				return	self.RenderJson ( returnData )
			}
			var	oldLabel	= server.Label
			server.Delete ()
			if	oldLabel != updatedServer.Label	{
				delete ( * ServersMap, oldLabel )
			}
			server	= updatedServer
			( * ServersMap )[ server.Label ]	= server

			returnData [ "result" ]	= fmt.Sprintf ( "%s was updated", oldLabel )
			returnData [ "url" ]	= routes.ApiServers.Show ( server.Label )
	}

	return	self.RenderJson ( returnData )
}