Exemplo n.º 1
1
// GetBoardPostsByID returns the filtered posts for a board by the ID of the board
func (ps *PostService) GetBoardPostsByID(boardID, page int) (posts []*model.Post, err error) {
	var rows *sqlx.Rows
	rows, err = ps.db.Queryx(queries.Get("get_board_posts_by_id"), boardID, page*50)
	if err != nil {
		return
	}

	for rows.Next() {
		var post model.Post
		err = rows.StructScan(&post)
		if err != nil {
			return
		}

		posts = append(posts, &post)
	}
	return
}
Exemplo n.º 2
0
// GetComment returns a comment along with its full tree
func (cs *CommentService) GetComment(commentID int) (c *model.Comment, err error) {
	row := cs.db.QueryRowx(queries.Get("get_comment_by_id"), commentID)

	var scanC model.Comment
	err = row.StructScan(&scanC)
	if err != nil {
		return
	}
	c = &scanC

	return
}
Exemplo n.º 3
0
// GetUserByUsername returns a user by their username
func (us *UserService) GetUserByUsername(username string) (u *model.User, err error) {
	row := us.db.QueryRowx(queries.Get("get_user_by_username"), username)

	var scanUser model.User
	err = row.StructScan(&scanUser)
	if err != nil {
		return
	}
	u = &scanUser

	return
}
Exemplo n.º 4
0
// GetUserByID returns a user by their id
func (us *UserService) GetUserByID(id int) (u *model.User, err error) {
	row := us.db.QueryRowx(queries.Get("get_user_by_id"), id)

	var scanUser model.User
	err = row.StructScan(&scanUser)
	if err != nil {
		return
	}
	u = &scanUser

	return
}
Exemplo n.º 5
0
// GetPost returns a single post, without comments, by ID
func (ps *PostService) GetPost(postID int) (post *model.Post, err error) {
	row := ps.db.QueryRowx(queries.Get("get_post_by_id"), postID)

	var scanPost model.Post
	err = row.StructScan(&scanPost)
	if err != nil {
		return
	}
	post = &scanPost

	return
}
Exemplo n.º 6
0
// GetUserPosts returns all posts owned by a certain user
func (ps *PostService) GetUserPosts(userID, page int) (posts []*model.Post, err error) {
	var rows *sqlx.Rows
	rows, err = ps.db.Queryx(queries.Get("get_user_posts"), userID, page*50)
	if err != nil {
		return
	}

	for rows.Next() {
		var post model.Post
		err = rows.StructScan(&post)
		if err != nil {
			return
		}

		posts = append(posts, &post)
	}
	return
}
Exemplo n.º 7
0
// GetPostComments returns all root level comments along with their children for a Post`
func (cs *CommentService) GetPostComments(postID int) (comments []*model.Comment, err error) {
	var rows *sqlx.Rows
	rows, err = cs.db.Queryx(queries.Get("get_post_comments"), postID)
	if err != nil {
		return
	}

	var pgcr []types.PGComment
	for rows.Next() {
		var pgc types.PGComment
		err = rows.StructScan(&pgc)
		if err != nil {
			return
		}
		pgcr = append(pgcr, pgc)
	}

	comments = types.AssembleCommentTree(pgcr)

	return
}
Exemplo n.º 8
0
// GetUserComments returns all of a users past comments
func (cs *CommentService) GetUserComments(userID int) (comments []*model.Comment, err error) {
	var rows *sqlx.Rows
	rows, err = cs.db.Queryx(queries.Get("get_user_comments"), userID)
	if err != nil {
		return
	}

	var pgcr []types.PGComment
	for rows.Next() {
		var pgc types.PGComment
		err = rows.StructScan(&pgc)
		if err != nil {
			return
		}
		log.Printf("%+v", pgc)
		pgcr = append(pgcr, pgc)
	}

	comments = types.AssembleCommentTree(pgcr)

	return
}
Exemplo n.º 9
0
// CreateComment creates a comment on another comment
func (cs *CommentService) CreateComment(c *model.Comment) (err error) {
	_, err = cs.db.NamedQuery(queries.Get("insert_comment"), c)
	return
}
Exemplo n.º 10
0
// UpdateUser updates a database user by ID
func (us *UserService) UpdateUser(u *model.User) (err error) {
	_, err = us.db.NamedQuery(queries.Get("update_user"), u)
	return
}
Exemplo n.º 11
0
// CreatePost adds a new post to the database
func (ps *PostService) CreatePost(p *model.Post) (err error) {
	_, err = ps.db.NamedQuery(queries.Get("insert_post"), p)
	return
}