Exemplo n.º 1
0
func (a *ApplicationController) CreateApplicationHandler(c *gin.Context) {
	body := &ApplicationModel{}

	if err := c.Bind(body); err != nil {
		log.Error(RestError(c, err))
		return
	}

	if body.Name == "" {
		log.Error(RestErrorInvalidBody(c))
		return
	}

	email := ApiUser(c).Email
	app := models.JSON{
		db.ID_FIELD:         body.Id,
		db.NAME_FIELD:       body.Name,
		db.OWNER_FIELD:      email,
		db.MASTER_KEY_FIELD: strings.ToUpper(utils.GetCleanUUID()),
	}

	appId, err := a.DbService.CreateApp(email, app)
	if err != nil {
		log.Error(RestError(c, err))
		return
	}

	RespondId(appId, c)
}
Exemplo n.º 2
0
func (d *dbService) setId(item models.JSON) string {
	if item[ID_FIELD] == nil || item[ID_FIELD] == "" {
		item[ID_FIELD] = utils.GetCleanUUID()
	}

	return item[ID_FIELD].(string)
}
Exemplo n.º 3
0
func init() {
	c = client.NewApiClientClean()

	email := utils.GetCleanUUID()
	password := utils.GetCleanUUID()

	err := c.Register(email, password)
	if err != nil {
		panic(err)
		return
	}

	token, err := c.Login(email, password)
	if err != nil {
		panic(err)
		return
	}

	c.Token = token

	appId, err := c.CreateApp(utils.GetCleanUUID())
	if err != nil {
		panic(err)
		return
	}

	c.AppId = appId
	err = c.AppRegister(email, password)
	if err != nil {
		panic(err)
		return
	}

	appToken, err := c.AppLogin(email, password)
	if err != nil {
		panic(err)
		return
	}

	c.Token = appToken
}