Exemplo n.º 1
0
func main() {
	db, err := sql.Open("postgres", os.Getenv("DATABASE_URL"))
	if err != nil {
		log.Fatal(err)
	}

	dbmap := &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}
	dbmap.TraceOn("[gorp]", log.New(os.Stdout, "[DATABASE] ", log.Lmicroseconds))

	dbmap.AddTableWithName(models.Team{}, "teams").SetKeys(true, "id")

	team := &models.Team{
		CreatedAt:         time.Now(),
		UpdatedAt:         time.Now(),
		Email:             "*****@*****.**",
		EncryptedPassword: "******",
		SSOUrl:            "http://localhost:8989/sso",
		SSOSecret:         "41fe7589256fd058b3f56bc71a56ebad3b1d6b86e027a73a02db0e3a0524f9d4",
		Slug:              "test-dev",
	}

	err = dbmap.Insert(team)

	if err != nil {
		log.Fatal(err)
	}

	var t models.Team
	err = dbmap.SelectOne(&t, "select * from teams where slug=$1", team.Slug)

	if err != nil {
		log.Fatal(err)
	}

	_, err = models.FindOrCreateRoom(&models.Room{
		TeamId: team.Id,
		Slug:   "general",
		Topic:  "general",
	})

	_, err = models.FindOrCreateRoom(&models.Room{
		TeamId: team.Id,
		Slug:   "random",
		Topic:  "random",
	})

	if err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 2
0
func RoomsCreate(c *gin.Context) {
	teamID := models.FindTeamBySlug(c.Params.ByName("slug")).Id
	var json RoomJSON
	c.Bind(&json)

	r := &models.Room{
		TeamId: teamID,
		Slug:   json.Slug,
		Topic:  json.Topic,
	}

	room, err := models.FindOrCreateRoom(r)
	if err != nil {
		c.Fail(500, err)
	}

	c.JSON(201, gin.H{"room": room})
}
Exemplo n.º 3
0
func RoomsShow(c *gin.Context) {
	user, err := GetUserFromContext(c)
	if err != nil {
		c.Fail(500, err)
	}

	roomSlugAndTopic := c.Params.ByName("room")

	r := &models.Room{
		TeamId: user.TeamId,
		Slug:   roomSlugAndTopic,
		Topic:  roomSlugAndTopic,
	}

	room, err := models.FindOrCreateRoom(r)
	if err != nil {
		c.Fail(500, err)
	}

	pixel := createPixel(room.Id, user.Id)

	c.JSON(200, gin.H{"room": room, "pixel": pixel})
}