const postHeader = { 'Authorization': 'whatever-you-want', 'Content-Type': 'application/json' };
export function fetchCategories () {
  return fetch('http://localhost:5001/categories',{ headers: { 'Authorization': 'whatever-you-want' }})
    .then(res => res.json())
}

export function fetchAllPosts () {
  return fetch('http://localhost:5001/posts',{ headers: { 'Authorization': 'whatever-you-want' }})
    .then(res => res.json())
}

export function fetchCatPosts (cate) {
  return fetch(`http://localhost:5001/${cate}/posts`, { headers: { 'Authorization': 'whatever-you-want' }})
    .then(res => res.json())
}

export function fetchPost (id) {
  return fetch(`http://localhost:5001/posts/${id}`, { headers: { 'Authorization': 'whatever-you-want' }})
    .then(res => res.json())
}

export function voteUp (id) {
  const payload = {option: 'upVote'};
  return fetch(`http://localhost:5001/posts/${id}`,
    { headers: postHeader,
      method: 'POST',
      body: JSON.stringify(payload)
    }
  ).then(res => res.json())
    .catch( (error) => console.log(error))
}

export function voteDown (id) {
  return fetch(`http://localhost:5001/posts/${id}`,
    { 
      method: "POST",
      headers: postHeader,
      body: JSON.stringify({option: "downVote"})
    }
  ).then(res => res.json())
    .catch( (error) => console.log(error))
}

export function fetchPostComments (id) {
  return fetch (`http://localhost:5001/posts/${id}/comments`,
    {
      headers: postHeader
    }
  ).then(res => res.json())
}

export function voteCommentUp (id) {
  return fetch(`http://localhost:5001/comments/${id}`,
    { 
      method: "POST",
      headers: postHeader,
      body: JSON.stringify({option: "upVote"})
    }
  ).then(res => res.json())
    .catch( (error) => console.log(error))
}

export function voteCommentDown (id) {
  return fetch(`http://localhost:5001/comments/${id}`,
    { 
      method: "POST",
      headers: postHeader,
      body: JSON.stringify({option: "downVote"})
    }
  ).then(res => res.json())
    .catch( (error) => console.log(error))
}
@@ -2037,28 +2037,295 @@
 or) =%3E console.log(error))%0A%7D
+%0A%0Aexport function postComment (newComment) %7B%0A  return fetch(%60http://localhost:5001/comments%60,%0A    %7B %0A      method: %22POST%22,%0A      headers: postHeader,%0A      body: JSON.stringify(newComment)%0A    %7D%0A  ).then(res =%3E res.json())%0A    .catch( (error) =%3E console.log(error))%0A%7D

add post comment api