Image Infection - Week #2: Voting and Query Implementation

Due Date: Completed and turned in via git before December 6, 2023 at 11:59pm
Points: Week 2 is worth 40 points

Overview

In Week #1, you setup your service to manage your interests. Now time to vote and talk with each other.

Part I: Answer Questions

The first thing we need to do is implement routes that provide access to all the information you are managing in your tile server. To do this you need to implement the following routes on your tile server.

  • GET /image provide your full image in the specified size
  • GET /tile provide the image of your tile
  • GET /votes provide how may votes you have

GET /image

This route will return the full image you are supporting in the specified resolution. If you do not have an approved image you should return 404.

GET /tile

This route will return the section of the full image that represents your tile as a PNG or tilesize by tilesize. If you do not have an approved image you should return 404.

GET /votes

This route returns a json containing one entry votes with an integer containing the current number of votes you have.

Part II: Voting

In order to support voting you will need two things.

  • PUT /votes a route where an authorized server can update your votes
  • an interface to allow you to vote by calling a route on the canvas server

PUT /votes

This route allows an authorized server to change your vote totals. To make sure that only authorized use can happen this will use the token you provided to the canvas server at registration. It also uses a counter to make sure that any total you are getting is newer than any total you have. When called you will receive a json with authToken, votes and seq.

{
  "authToken": "a5630ec7-165f-4d0a-9f17-7da3cb5fcc50",
  "votes": 5,
  "seq": 123
}
  • The authToken must be the token you provided when you registered your service.

  • The votes is the count of votes that are voting for your tile

  • The seq is a sequence number that will start with 0 and increase each time your vote total is changed

There are two specific error conditions. The first is if authToken does not match your token you should respond with HTTP/401 “Unauthorized”. The second is if the sequence number is not larger than the last sequence number you received, in which case you should respond HTTP/409 “Conflict”. In either of these cases you make no change to your stored vote totals.

If neither of the error conditions are true you should respond HTTP/200 and update your stored votes to the amount provided in votes and the stored sequence number to the number in seq.

Casting Votes

To cast votes you will need some way to tell your tile server to cast the vote on your behalf. How you write this interface is up to you. To execute the vote your tile server will need to contact the canvas server on the route PUT /vote/<clientID> with the tile you are voting for.

The PUT /vote/<clientID> Route

This route will be implemented on the canvas server to allow you to vote. You will send it a json with the fields voteToken, xloc, and yloc.

{
  "voteToken": "45046605-4ef3-4dfc-84ed-cfafade8a2db",
  "xloc": 3,
  "yloc": 2
}
  • The voteToken is the token the canvas sever provided you to allow you to vote

  • The xloc and yloc provide the location on the canvas that is tile you want to put your vote on.

Grading

You will be able to earn 40 points for completing all of this week’s deliverables (there will be no partial credit for this week, this is already partial credit as part of the final project). This week comprises only a portion of the 220 total points for the final project, since this project builds on itself each week. Failure to complete this week will make it more difficult to earn points in future weeks since you will need to complete this work to complete the next week’s work.

Much like happened in week 1 a grading server will be released and you will need to complete a task using your tile server. The specific details will be released when the grading server is released and you will have until the end of the day on December 6th to complete the task.

Submission on Git

git add -A
git commit -m "MP submission"
git push