Votes

Now that we have modeled questions and answers in our application, it's time to think about how voting might work.

Let's design it a little:

  • Users vote answers up and down based on their opinion of them
  • Answers are ordered by their score so the best ones appear first
  • Each person is allowed one vote per answer
  • If a user votes again, they should replace their previous vote

We will make use of a few things we have learned so far in this chapter; transactions will help us ensure the correct score is calculated for answers, and we'll use predictable keys again to ensure that each person gets only one vote per answer.

We will first build a structure to represent each vote and use field tags to be a little more specific about how we want the data store ...

Get Go Programming Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.