// GetByUser returns all user posts.
GetByUser returns all user posts.
// GetByUser returns all user posts .
func (pr *PostRepository) GetByUser(ctx context.Context, userID uint) ([]post.Post, error) {
	q := `
	SELECT id, body, user_id, created_at, updated_at
		FROM posts
		WHERE user_id = $1;
	`
	rows, err := pr.Data.DB.QueryContext(ctx, q, userID)
	if err != nil {
		return nil, err
	}
	defer rows.Close()
	var posts []post.Post
	for rows.Next() {
		var p post.Post
		rows.Scan(&p.ID, &p.Body, &p.UserID, &p.CreatedAt, &p.UpdatedAt)
		posts = append(posts, p)
	}
	return posts, nil
}
func ( pr * PostRepository ) GetByUser ( ctx context . Context , userID uint ) ( [ ] post . Post , error ) { q := `
	SELECT id, body, user_id, created_at, updated_at
		FROM posts
		WHERE user_id = $1;
	` rows , err := pr . Data . DB . QueryContext ( ctx , q , userID ) if err != nil { return nil , err } defer rows . Close ( ) var posts [ ] post . Post for rows . Next ( ) { var p post . Post rows . Scan ( & p . ID , & p . Body , & p . UserID , & p . CreatedAt , & p . UpdatedAt ) posts = append ( posts , p ) } return posts , nil }
GetByUser returns all user posts.
GetByUser returns all user posts .