MP2: Server Add Place

Created By: Geoffrey Challen
/ Updated: 2022-11-03

Let's continue our work on the machine project! Next we'll begin the next project checkpoint, MP2. We'll install the test suites and begin work on our first test case.

MP2 represents a step up from MP1. Rather than making small changes, we'll be writing larger chunks of code. However! The code we ask you to write will be similar to the code that we've given you. So you can use our starter code as a guide and inspiration.

Getting Started

For MP2 we'll be continuing on with the project that you started working on for MP0 and MP1. You'll need the environment that you set up during that checkpoint to proceed.

Before you can get to work on MP2 in earnest, we need to install the MP2 test suites. Before we continue, please commit your work.

You should have received the MP2 test suites via email. Move the file to the app/src/test/kotlin/edu/illinois/cs/cs124/ay2022/mp/ directory in your machine project, and make sure it's named MP2Test.kt. You'll also want to reconfigure grade.yaml in the root directory of your project to request that we grade Checkpoint 2. We've completed this steps before, so if you need to review please examine the lessons for MP1.

Stubbing Out MP2

Like MP1, when we add MP2Test.kt to our project our code will no longer compile. This is because the test suite expects us to have created some new methods and classes that don't exist yet. The task here isn't too involved, but let's go through it together.

Show how to stub out the code so that the test suites compile.

Note that you should also make sure to update grade.yaml before you push changes for MP2, to ensure that MP2 is what is graded. The walkthrough above may be missing that step.

Server Add Place

With the test suites in place, let's get started on our first test case: test0_ServerFavoritePlacePost. We're going to approach this in two steps, each accompanied by a walkthrough.

Adding the Server Route

First, we'll examine the test suite carefully and gain an understanding of what we need to do. We'll create our own test case to allow us to experiment with the different requests that the test suite is expecting the server to handle. We'll also discuss the basics of how HTTP POST requests allow clients to send data to the server.

Start with the test suites, and use them to help students understand what they are expected to do. End up with the server route in place, a simplified test case, and describing how POST requests allow a body to accompany the request.

Implementing the Server Route

Next, we'll work through an outline of what our server code needs to do to handle requests to add a new place to the map. You will have code left to write to complete this test case! And this is one of the more difficult test cases to pass for MP2. However, you should have a strong idea of what you need to do after watching the walkthrough below.

Pick up where the last walkthrough left off, and begin developing an outline of what the server code needs to do. Discuss deserialization, validating the resulting place, and adding it to the list of current places.

Server Route Specification

As outlined above, here's a specification for how your /favoriteplace route should work. It should accept POST requests. If the body is not valid JSON, or does not contain a valid Place object, you should return a response with the HTTP error code 400: Bad Request.

A Place object is valid if:

  • The id, name, and description are present and non-empty
  • The latitude and longitude are present and within valid ranges
  • The id contains a valid UUID

Given a valid Place object, a POST to /favoriteplace should add it to the list of places returned by a GET request to /places. If the id in the new Place matches an existing Place in the list, replace that Place with the new Place. Otherwise add the new Place to the list.

Learn More About the Internet

The Internet is probably the most important piece of technology that computer scientists have ever created. Without the ability to communicate across the globe, computers would really be nothing more than glorified typewriters or calculators.

There are a lot of ways to find out more about the internet. But I'll take the liberty of pointing you at some videos that I've created on the topic that you might enjoy. Note that this is completely optional content! The playlist above focuses on internet concepts related to the world wide web, including the HTTP protocol. But there is a much longer playlist here that covers everything from physical infrastructure all the way up to Internet policy.

No Homework for This Lesson

As a reminder, on lessons where we focus on the machine project we will not assign a homework problem! However, the lesson will usually focus on helping you complete a particular part of the MP test suite, and so we encourage you to spend time on that in lieu of a homework problem.

Right now your goal should be to

  1. install the MP2 test suites
  2. get your code to compile, and
  3. complete the test0_ServerFavoritePlacePost test case.

If you get stuck, find us for help on the help site or forum.

MP2 Scores

More Practice

Need more practice? Head over to the practice page.