ucsb-cs156-s24 / team02-s24-5pm-3

https://ucsb-cs156-s24.github.io/team02-s24-5pm-3/
0 stars 0 forks source link

Create `MenuItemReviewController`, add `GET` (index) and `POST` (create) #27

Closed github-actions[bot] closed 6 months ago

github-actions[bot] commented 6 months ago

Dependencies

This issue should be completed after the issue with the title "Create database table for MenuItemReview"

Overview

In this issue, you'll create a Controller. In the Spring web framework, a Controller is a file that maps request URLs (e.g. /api/MenuItemReview/all to some code that runs to produces the response to that request.

(1) First locate the directory where the Java source code files for controllers can be found:

(2) Then, determine which example file you are going to use as a basis for your controller by reading the team02 instructions about the @Id field here: https://ucsb-cs156.github.io/s24/lab/team02.html#two-types-of-id-values-for-an-entity-class

The two candidates are:

Keep this file open in one window; you'll need this as source material for the file you are about to create.

(3) In a separate window, create a new file called MenuItemReviewController.java in the src/main/java/edu/ucsb/cs156/example/controllers directory.

From the example file, copy over:

(4) Don't copy over all of the methods yet; just copy over these two methods with these annotations:

Annotation Purpose
@GetMapping("/all") Get all records in the table and return as a JSON array
@PostMapping("/post") Use the data in the input parameters to create a new row in the table and return the data as JSON

(5) Edit the names of the fields, etc. to match your database table.

(6) Next, use Swagger to see if your methods work. Debug until you get correct results using Swagger.

(7) When your interactive testing works, we'll move on to creating automated tests. Locate the directory for controller tests:

Find the file with tests for the controller you used as a basis for your controller file, i.e.

Keep this file open in one window; you'll need this as source material for the file you are about to create.

(8) In a separate window, create a new file called MenuItemReviewControllerTests.java in the src/test/java/edu/ucsb/cs156/example/controllers directory.

(9) From the source file you identified in step (7) above, copy over:

Be sure to change the name of the controller class to match the one for your database table.

(10) Next, copy over just the tests that pertain to the methods you defined in your controller so far, i.e. the ones under the comments:

You'll see additional tests for another GET method, as well as DELETE and PUT; we don't want those tests yet (that's a later issue).

(11) Check test coverage with mvn test jacoco:report; to read the report, open target/site/jacoco/index.html in a web browser. Iterate until you have 100% line/branch coverage.

(12) Check test coverage with mvn test pitest:mutationCoverage; to read the report, open target/pit-reports/index.html in a web browser. Iterate until there are no surviving mutations (e.g. >> Generated 61 mutations Killed 61 (100%)). You may ignore line coverage of less than 100% reported by pitest (e.g. this is fine: >> Line Coverage: 171/175 (98%)).

Acceptance Criteria:

Next issue

What to do next

When you've met all of the acceptance criteria:

Make a PR: Do a PR for this branch, being sure to enter a reasonable title and description.

In the description, include the text "Closes #n" where n is the number of this issue.

Then ask for a team member to review your PR.

Finally: drag this issue from "In Progress" to "In Review".

Review Others' PRs: Next, see if there are any PRs that need to be code reviewed and merged. Unless you are the first person on your team to complete a PR, there likely is at least one. See:

Start your next issue :

Now you can complete these in any order:

Find the issue you are going to work on next on the Kanban board.