Getting it done

Exercise

Use the skills that you have learned so far in this workshop to fulfill the web services requirements.

  1. HTTP POST to create a vote submission
  2. HTTP GET to retrieve voting results

Using the same model of a Vote, your web service should:

  • receive a Vote in the body of an HTTP POST request and persist it to the DynamoDB votes table
  • retrieve all Votes in a specific Poll from th DynamoDB votes table and return a sum aggregated by the Choice
// Vote represents one voter casting one vote in one poll.
// A single voter can only vote once for any given poll.
type Vote struct {
    Voter  string `json:"voter"`
    Poll   string `json:"topic"`
    Choice string `json:"choice"`
}

For example, given the following votes:

Voter Poll Choice
Alice 1 For
Bob 1 For
Carol 1 Against
Alice 2 Against
Eve 2 For

A request to your web service for poll 1 could return:

{
    "results": [
        {
            "poll": "1",
            "votes": [
                {"choice": "For", "votes": 2},
                {"choice": "Against", "votes": 1}
            ]
        }
    ]
}

Do not get stuck on the particular shape of the JSON, ordering, etc. - the goal is to fulfill the requirement of returning a sum of the votes for each choice in a given poll.