Fill out AddToStats handler and test

This patch makes it so we can submit data scouting data to the
database. All tests are updated.

This patch also adds more error checking code to the database code to
make sure we get notified of some important edge cases.

The majority of the patch is written by Sabina. I amended the
`cli_test.py` file.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Signed-off-by: Sabina Leaver <100027607@mvla.net>
Change-Id: I9c70b8b02bbd3ff434fbbb857c2ed65f2684a50e
diff --git a/scouting/webserver/requests/requests.go b/scouting/webserver/requests/requests.go
index 93ee128..6c4bdd1 100644
--- a/scouting/webserver/requests/requests.go
+++ b/scouting/webserver/requests/requests.go
@@ -20,12 +20,13 @@
 	"github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_matches_for_team"
 	"github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/request_matches_for_team_response"
 	"github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting"
-	_ "github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting_response"
+	"github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting_response"
 	"github.com/frc971/971-Robot-Code/scouting/webserver/server"
 	flatbuffers "github.com/google/flatbuffers/go"
 )
 
 type SubmitDataScouting = submit_data_scouting.SubmitDataScouting
+type SubmitDataScoutingResponseT = submit_data_scouting_response.SubmitDataScoutingResponseT
 type RequestAllMatches = request_all_matches.RequestAllMatches
 type RequestAllMatchesResponseT = request_all_matches_response.RequestAllMatchesResponseT
 type RequestMatchesForTeam = request_matches_for_team.RequestMatchesForTeam
@@ -91,16 +92,32 @@
 		return
 	}
 
-	_, success := parseSubmitDataScouting(w, requestBytes)
+	request, success := parseSubmitDataScouting(w, requestBytes)
 	if !success {
 		return
 	}
 
-	// TODO(phil): Actually handle the request.
-	// We have access to the database via "handler.db" here. For example:
-	// stats := handler.db.ReturnStats()
+	stats := db.Stats{
+		TeamNumber:      request.Team(),
+		MatchNumber:     request.Match(),
+		ShotsMissedAuto: request.MissedShotsAuto(),
+		UpperGoalAuto:   request.UpperGoalAuto(),
+		LowerGoalAuto:   request.LowerGoalAuto(),
+		ShotsMissed:     request.MissedShotsTele(),
+		UpperGoalShots:  request.UpperGoalTele(),
+		LowerGoalShots:  request.LowerGoalTele(),
+		PlayedDefense:   request.DefenseRating(),
+		Climbing:        request.Climbing(),
+	}
 
-	respondNotImplemented(w)
+	err = handler.db.AddToStats(stats)
+	if err != nil {
+		respondWithError(w, http.StatusInternalServerError, fmt.Sprint("Failed to submit datascouting data: ", err))
+	}
+
+	builder := flatbuffers.NewBuilder(50 * 1024)
+	builder.Finish((&SubmitDataScoutingResponseT{}).Pack(builder))
+	w.Write(builder.FinishedBytes())
 }
 
 // TODO(phil): Can we turn this into a generic?