In this assignment you are going to add some features to a simple Spring Boot application that I have started for you.
The application is a simple clone of the Task Rabbit service, which is a service that users can use to hire people, called Taskers, to do small jobs for them such as help with moving or assembling Ikea furniture.
The application we are going to write for our clone system is an application that allows customers to post jobs. The application will be a web application that uses an HTML page as its user interface and a Spring Boot web application server as its back end.
Start by clicking the 'Project Folder' button above to download an archive containing all the files you will need. In the project folder you will find two special folders. The 'database' folder contains database files for you to use. The 'web' folder contains the HTML and JavaScript code for the user interface of the application we are going to build. Once you have finished building the Spring Boot part of the project you will be able to open the HTML file in a browser and run the application.
1. Start by installing the tasker database. In the MySQL workbench, right-click in the Schema area and select the Create Schema... command. Name the new database 'tasker' and then use the Data Import command in the Administrative tab to import the tasker database for use with this assignment. The database I have provided already contains some data for customers, so you will be working with those existing customers.
2. Open the TaskerWeb project in Visual Studio Code. Part of the classes you will need are already there: the project includes Person, PersonDAO, PersonRowMapper, and PersonController classes. In the PersonController class are a couple of methods that the HTML page needs to manage the log in process. Your job in this assignment is to add additional classes needed to manage posting jobs to the database.
3. Start by creating a new Job class. This class will have member variables that correspond to each column in the jobs table in the tasker database. Provide a default constructor for the class and get and set methods for each of the member variables.
4. Next, write a JobRowMapper class that can read Job objects from the database.
5. Add a JobDAO class and put the following methods in it:
public List<Job> findByCustomer(int customer) { }
public void save(Job job) {}
The first method should return a list of Job objects for all of the jobs that a given customer has in the jobs table. The second method will save a Job object to the database.
6. Add a JobController class. The class will need to contain code to respond to two kinds of requests. The first request is a GET request that uses a URL of
http://localhost:8085/jobs?customer=<id>
where <id> gets replaced with the id number of a customer. The method that handles that request should return a list of Job objects.
The second request is a POST request to the URL
http://localhost:8085/jobs
that contains a Job object in its body. That method should save the job in the database and return the integer 1 to confirm that the save was successful.
To see examples of how to set up a method to handle a GET request with a query parameter and how to handle a POST request, take a look at the quiz example in the lecture notes.
7. Finally, you should now be able to run your project to start the Spring Boot application and then open the tasker HTML file in the web folder in a browser window to run the application. Use the application to set up a new job for a customer and confirm that the job gets added to the jobs table in the tasker database.