A fitness/health based clone of Stack Overflow
Explore the docs »
View Demo
.
Wiki
·
Report Bug
·
Request Feature
![Product Name Screen Shot][product-screenshot]
Fitness Overflow is a fitness and health clone of Stack Overflow. Users are able to browse, ask,search, answer and vote on fitness and health related questions. The site uses User-based session authentication to interact with the website and access these features.
- Users can vote on answers which via handled by ajax
- A fetch request is made to the server which will update votes on the server and return a json object so the DOM reflects the change
- A fetch request is made using the input of our search bar to make an api request to the server using the search route to query the database and returning results that title matches the search criteria and updating the DOM using AJAX.
![Product Name Screen Shot][product-screenshot]
Fitness Overflow is a fitness and health clone of Stack Overflow. Users are able to browse, ask,search, answer and vote on fitness and health related questions. The site uses User-based session authentication to interact with the website and access these features.
window.addEventListener("load", (event)=>{
let questionId = document.getElementById('questionId').innerText
let votingContainers = document.querySelectorAll(".voting-container")
votingContainers.forEach(voteContainer =>{
let answerId = voteContainer.id
// code removed for brevity
}
// code removed for brevity
upvoteButton.addEventListener("click", async (event) =>{
let res = await fetch(`/questions/${questionId}/answer/${answerId}/upvote`, {
method: "PATCH",
headers:
{'Content': "application/json"}
})
const json = await res.json()
counter.innerHTML=json.totalVotes
})
})
router.patch('/:id(\\d+)/answer/:id2(\\d+)/downvote', asyncHandler(async (req,res)=>{
const questionId = parseInt(req.params.id, 10)
const answerId = parseInt(req.params.id2, 10)
const { userId } = req.session.auth
// // console.log(downvotes)
let existingVote = await db.Vote.findOne({where: {
userId,
answerId
}})
if(existingVote){
await existingVote.destroy()
}
const vote = await db.Vote.build({
userId,
answerId,
voteType: "upvote"
})
await vote.save()
const upvotes = await db.Vote.findAll({
where: {
answerId,
voteType: "upvote"
}
})
const downvotes = await db.Vote.findAll({
where: {
answerId,
voteType: "downvote"
}
})
let totalUpVotes= upvotes.length
let totalDownVotes= downvotes.length
let totalVotes = totalUpVotes - totalDownVotes
res.json({
title: 'Question',
totalUpVotes,
totalDownVotes,
totalVotes,
upvotes
})
}))
router.get('/', requireAuth, asyncHandler(async (req,res) =>{
const queryTerm = req.query.search
const questions = await db.Question.findAll({include: [db.User, db.Answer], order: [['createdAt', 'DESC']], where: { title: { [Op.iLike]: `%${queryTerm}%` } } })
res.json({questions})
}))
- Implementing the upvote/downvote functionality
- The challenge we encountered when implementing the upvote/down feature is getting the necessary information to make a fetch request.(the answer id and question id) We overcame this particular challenge by creating unique IDs that can be reference for each answer and using the id to pass the information.
- The git workflow
- The gitworkflow involving branching, merging branches and pull requests was diffcult at first because we werent use to this type of workflow. To overcome this challenge we took our time and consulted with each other to make sure that each movement for this workflow was correct
To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
- npm
npm install npm@latest -g
- Clone the repo
git clone https://github.com/RyanGC93/fitnessOverflow.git
- Install NPM packages
npm install
- To Start The Project Locally
npm start
The Project is served and can be seen on localhost:8080
Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
For more examples, please refer to the Documentation
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Your Name - @twitter_handle - Fitness Overflow
Project Link: https://github.com/RyanGC93/fitnessOverflow