Please try to work through Tasks 0 and 1 ahead of your lab time on Monday. Your team and TA can help you during the lab if you had any trouble, so don't worry if you don't get through Task 1 before lab. There will also be some time to do this as your TA helps everyone get into teams.
- As with the previous lab activities, start by making a fork of this repo and cloning it.
In order to use the Grade API, you will need to sign up a new username, and obtain an API token.
To sign up a username, we are going to make a simple request to the Grade API.
- Go to https://hoppscotch.io. This is a tool like Postman, which can be used to quickly interact with APIs.
- Beside the word GET, replace
https://echo.hoppscotch.io/withhttp://vm003.teach.cs.toronto.edu:20112/signUp.
Next, we need to specify the username which we want to use. To do this, we add a parameter.
- In the Parameters tab, choose
+ Add newand set the parameter name tousername. - For its value, choose whatever username you want to use. Make note of the name you choose, as you'll use it during the lab. (Don't worry, you can repeat this process with a new username if you need to later!)
- Press the
Sendbutton to make the request. You may receive an error that the request didn't go through. Scroll down and selectproxyas the middleware and pressSendagain. You should now see the result of the request. - If the username had been used before, you will see a response indicating that. Choose a new username and send the request again.
- If the request is successfully sent, you will see a response that contains a
status_codeof value200. In this response, you will get two important fields:tokenandenvironment_variables, whose values you will need later on in the activity.
You can also refer to the Grade API Postman Workspace for the documentation of all API requests related to the Grade API. Specifically, to learn more about the SignUp API request, refer to this section of the workspace.
Alternative to the above: Enter http://vm003.teach.cs.toronto.edu:20112/signUp?username=USERNAME in any web browser
with USERNAME replaced with the username you want to use. Note, we are introducing you to tools like hoppscotch.io
and postman above, since we'll later see API requests which can't be made through your web browser.
- Create a new file called
token.txtin the root directory of your project and copy / paste the value you found for thetokenfield in that file. This file is indicated in the.gitignorefor your project, so its name will appear yellow in IntelliJ to indicate that git will ignore the file (it won't be version controlled). This can be useful to ensure that you don't accidentally share private information (like personal API tokens) or configurations specific to your local environment when working on a team project.
Now that you have your API token, the last step is to get your program to use it. To do so, we are going to set an environment variable in the run configuration.
Note: at this point you should be able to run the program, but it is possible that the Maven
project didn't automatically build. If you have errors which won't let you run the code in the
next step, you may need to reload the Maven project. You can do this by right-clicking on the
pom.xml file in your project. In the context menu, choose Maven -> reload project. This should
resolve any errors. You may also need to go to Project Structure... and select your project JDK.
Important: make sure not to commit any changes to the .idea/misc.xml file, as it will store which specific JDK
you are using, which likely isn't the same as the rest of your team when you collaborate on the coding task later
in this lab.
-
Try running the main application (
src/main/java/app/gui/Application). When you start the program, you will see that it saysyour token is null(since we didn't set it yet). Stop the program and go toRun -> Edit Configurations.... -
Open the Run Configuration for
Applicationand find theEnvironment Variables:field.- Note: If you don't see this Run Configuration listed:
- create a new Run Configuration of type
Application(use the + in the top left corner of the window). - where it says "Main class", type
app.gui.Application.
- create a new Run Configuration of type
- Note: If you don't see this Run Configuration listed:
-
In that field, paste the text you copied from
environment_variableswhen you sign up an account. Yourtokenshould also be intoken.txt. Example:token=6SgDAt8XpnQYTDPt4vHcPCCKJ2ppLg1C. -
Click
Applyand thenOK. -
Now, rerun the program and you should see your
tokendisplayed. -
Click on the
Log Gradebutton and in the next screen, enter207as the course, enter a valid grade for this course, and clickLog. You should see a popup telling you that your grade was successfully entered. You can then check your grade by using theGet Grademenu and specifying your username and207for the course.
You are now ready to use the program! The following task will be completed with your team during the lab. First, make sure everyone has successfully completed the steps above.
As a team-building exercise, you will now work together to form a team using this application. Team members in this program are able to view the grades of other team members.
-
Choose a team name. Make it something unique to your team, as other teams will also be picking team names and duplicate names aren't allowed.
-
Have one member of your team form a team with the name your team chose by clicking the
Form a teambutton, entering the team name in the text field, and pressingSubmit. -
Each other member of the team should then join the team using the
Join a teammenu. Make sure you see the popup confirming that you successfully joined the team. -
Try looking up the grade another team member entered for
207using theGet a Grademenu.
Now that you are all on the team, there are a couple coding tasks for your team to work on.
Note: If your team finds it convenient to work on parts of this lab on a common machine,
you can create different run configurations (copy an existing one) which each use a different
token environment variable. Then you can run multiple instances of the program and
enter requests as different users!
Note: Your team can choose how you want to work on the following two tasks, but below is our suggestion.
Suggested logistics: One of you should invite the others to collaborate on their fork of the
original repo on GitHub. You can do this in your repo on GitHub under Settings -> Collaborators.
This will allow you to push branches to a common repo and then use pull requests to contribute
your code and review. To prevent others from pushing directly to the main branch,
we recommend you set branch protection rules on GitHub. Below are how the settings might look if you
add branch protection rules:
We recommend splitting your team into two halves with one half working on task 3 and the other on task 4.
You can work on separate branches and merge the code together when you are done.
Note that successful completion of task 3 is a pre-requisite for task 4 as the getMyTeam() method is used in both the features,
but you can still write the code for task 4 so that it is ready to run once task 3 is complete.
While this program has some useful core functionality which is provided by the Grade API, there are certain things which the Grade API can't currently do for us.
- Go to
My Teammenu, enter the course name as207and click onGet average grade. You will notice that the functionality forGet Average Gradeisn't implemented yet — it will just displayAverage Grade: 0.0. - As a team, your goal is to work together to implement this feature and confirm that it works.
- Follow the flow from the
getAveragebutton defined in the UI layer (app/gui/Application.java) to reach until theGetAverageGradeUseCasein the usecase layer. You can do this by setting a breakpoint and running the program in debug mode. - You will need to finish implementing the logic of calculating the average grade (Task 3a in the code) in the
GetAverageGradeUseCaseclass. The logic is partly implemented, but what is written depends on thegetMyTeammethod (Task 3b in the code), which needs to be implemented. Follow the hints provided in this method to complete its implementation. Note the API response will be injsonformat which you learned how to parse last lab.
You can run the provided tests to check if your "Task 3a" GetAverageGradeUseCase logic is implemented correctly, before you finish implementing the "Task 3b" MongoGradeDataBase.getMyTeam method in Task 3.
These tests make use of the technique of mocking (or stubbing), where instead of calling the actual API we use fake data instead.
This is possible because of how the program is designed, with the GradeDataBase interface allowing us to replace any variable with reference type GradeDataBase with our own dummy implementation.
In this task, you are required to build a feature that will allow the user to get the top grade on their team for a given course.
- Similar to
Get Average Grade, you will need to implement theGet Top Gradefeature. - However, in this feature, the
Get Top Gradeusecase is already implemented in theGetTopGradeUseCaseclass. - You will need to implement the UI layer for this feature by adding a button
Get Top Gradein theMy Teammenu. You can draw inspiration from theGet Average Gradebutton.
If your team finishes the above tasks and has extra time, we encourage you to think of an additional use case that can be implemented using this Grade API. Implement this use case end-to-end, from the UI layer to the UseCase layer, and see if you can get it working. This will be good practice for when your team starts developing your own course project where you will also be using an API endpoint.
- We are using a very simple authentication method, by passing our API
tokenin the request headers. When you use other real-world APIs in the future, you will see some more sophisticated authentication techniques.
