Пример #1
0
func DeleteLink(linkId int64) {
	db := GetConn()
	defer db.Close()

	_, err := db.Exec("DELETE FROM link WHERE id = $1::int", linkId)
	util.HandleErrors(err)
}
Пример #2
0
func HasAccessToLink(linkId, userId int64) bool {
	db := GetConn()
	defer db.Close()

	rows, err := db.Query("SELECT * FROM link l, link_group lg WHERE l.id = $1::int AND l.link_group_id = lg.id AND lg.user_account_id = $2::int", linkId, userId)
	util.HandleErrors(err)

	return rows.Next()
}
Пример #3
0
func HasAccessToGroup(userId, groupId int64) bool {
	db := GetConn()
	defer db.Close()

	rows, err := db.Query("SELECT * FROM link_group WHERE id = $1::int AND user_account_id = $2::int", groupId, userId)
	util.HandleErrors(err)

	return rows.Next()
}
Пример #4
0
func SaveLink(link *model.Link) *model.Link {
	db := GetConn()
	defer db.Close()

	res, err := db.Exec("INSERT INTO link (link_group_id, title, href, description) VALUES ($1::int, $2::text, $3::text, $4::text)", link.Group.Id, link.Title, link.Href, link.Description)
	link.Id, _ = res.LastInsertId() // TODO: Investigate the error that LastInsertId() throws

	util.HandleErrors(err)

	return link
}
Пример #5
0
func SaveLinkGroup(group *model.LinkGroup) *model.LinkGroup {
	db := GetConn()
	defer db.Close()

	res, err := db.Exec("INSERT INTO link_group (user_account_id, title, description) VALUES ($1::int, $2::text, $3::text)", group.User.Id, group.Title, group.Description)
	group.Id, _ = res.LastInsertId() // TODO: Investigate the error that LastInsertId() throws

	util.HandleErrors(err)

	return group
}
Пример #6
0
func SaveUser(user *model.User) *model.User {
	db := GetConn()
	defer db.Close()

	res, err_1 := db.Exec("INSERT INTO user_account (username, password, email, first_name, last_name) VALUES ($1::text, $2::text, $3::text, $4::text, $5::text)", user.Username, user.Password, user.Email, user.FirstName, user.LastName)
	user.Id, _ = res.LastInsertId() // TODO: Investigate the error that LastInsertId() throws

	util.HandleErrors(err_1)

	return user
}
Пример #7
0
func FindLinksForGroup(groupId int64) *[]model.Link {
	var result []model.Link
	db := GetConn()
	defer db.Close()

	rows, err := db.Query("SELECT * FROM link WHERE link_group_id = $1::int", groupId)
	util.HandleErrors(err)

	for rows.Next() {
		var link model.Link
		var groupId_notUsed int64

		err := rows.Scan(&link.Id, &groupId_notUsed, &link.Title, &link.Href, &link.Description)
		util.HandleErrors(err)

		result = append(result, link)
	}

	util.HandleErrors(rows.Err())

	return &result
}
Пример #8
0
func FindLinkGroupsForUser(user *model.User) *[]model.LinkGroup {
	var result []model.LinkGroup

	db := GetConn()
	defer db.Close()

	rows, err := db.Query("SELECT * FROM link_group WHERE user_account_id = $1::int", user.Id)
	util.HandleErrors(err)

	for rows.Next() {
		var group model.LinkGroup
		var userId_notUsed int64

		err := rows.Scan(&group.Id, &userId_notUsed, &group.Title, &group.Description)
		util.HandleErrors(err)

		result = append(result, group)
	}

	util.HandleErrors(rows.Err())

	return &result
}