Git Product home page Git Product logo

java_iv_lab_iii's Introduction

Java IV REST Controllers Lab

Completing this lab demonstrates your ability to code Spring REST controllers in a standards based way.

Objective

Write a fully functional REST controller for the customers API

Getting Started:

  1. Copy the starter code from here into a new, private repository in your personal GitHub account using these instructions substituting this repository URL https://github.com/jeff-anderson-cscc/java4-labs-rest-controllers for the one referenced in that document
  2. Create a new branch for your code changes as described in these instructions

Completing the Assignment

Important You may not change the code in any test cases. The only permissible difference between the base version of the JUnit test class and yours is yours will have no tests commented out and the file is otherwise identical.

  1. Open CustomerControllerTests
  2. One by one, uncomment each test, changing just enough code or configuration to make the test pass
  3. Once all tests are passing, commit your changes

Each test validates conditions detailed in the specifications below

Customer Controller

Class Diagram:

Class Diagram

  • You will be creating a CustomerController class which is shown in the class diagram above
  • Your class should have the same method names and signatures
  • The CustomerRepository interface is provided. Do not implement a concrete class for this interface or modify it's contents.
  • The Customer class is provided. Do not modify it's contents.

getAllCustomers

  • Example Request: GET localhost:8080/api/customers

getAllCustomers sequence diagram

  • Step 1.1.3 puts the map key "customers" along with the data returned in step 1.1.2
  • Example Response:
{
    "customers": [
        {
            "id": 1,
            "firstName": "jeff",
            "lastName": "Anderson"
        },
        {
            "id": 2,
            "firstName": "Jeremy",
            "lastName": "Schmersal"
        }
    ]
}

Get a Customer by ID

Get a customer by ID or return HttpStatus.NOT_FOUND if no customer exists with that ID

  • Example Request: GET localhost:8080/api/customers/1

getAllCustomers sequence diagram

  • Step 1.1.4 creates a response entity with data from step 1.1.3 and HttpStatus.OK if step 1.1.2 returns true
  • Step 1.1.5 creates a response entity with HttpStatus.NOT_FOUND if step 1.1.2 returns false
  • Example Response:
{
    "id": 1,
    "firstName": "jeff",
    "lastName": "Anderson"
}

Create a Customer

  • Example Request: POST: localhost:8080/api/customers
  • Example Request Headers: Content-Type: application/json
  • Example Request Body:
{
	"firstName": "Jeremy",
	"lastName": "Schmersal",
	"emailAddress": "[email protected]"
}

createCustomer sequence diagram

  • The code below can be used to create and return the location header as shown in steps 1.1.2 - 1.1.7:
    UriComponents uriComponents = b.path("/api/customers/{id}").buildAndExpand(newCustomer.getId());
    return ResponseEntity.created(uriComponents.toUri()).build();
  • Example Response Headers: Location: http://localhost:8080/api/customers/1
  • The response body is empty

Update an Existing Customer

Save changes to an existing customer

  • Example Request: PUT: localhost:8080/api/customers/2
  • Example Request Headers: Content-Type: application/json
  • Example Request Body:
{
	"firstName": "Rod",
	"lastName": "Johnson",
	"emailAddress": "[email protected]"
}

saveCustomer sequence diagram

  • Step 1.1.4 creates a response entity with the return data and HttpStatus.NO_CONTENT if step 1.1.1 returns true
  • Step 1.1.5 creates a response entity with HttpStatus.NOT_FOUND if step 1.1.1 returns false
  • The response body is empty

Delete a Customer

  • Example Request: DELETE: localhost:8080/api/customers/2 deleteCustomer sequence diagram
  • Step 1.1.5 creates a response entity with the return data and HttpStatus.NO_CONTENT if step 1.1.2 returns true
  • Step 1.1.6 creates a response entity with HttpStatus.NOT_FOUND if step 1.1.2 returns false
  • The response body is empty

Helpful Documentation

OPTIONAL

This won't be graded but will demonstrate your understanding of Java Bean validation in REST controllers

  1. Open CustomerControllerValidationTests
  2. One by one, uncomment each test, changing just enough code or configuration to make the test pass
  3. Once all tests are passing, commit your changes

Submitting Your Work

  1. Push your changes to GitHub
  2. Create a pull request for your branch using these instructions
  3. Submit the assignment in Blackboard as described in these instructions

NOTE: I will provide feedback via. comments in your pull request. If you need to amend your work after you issue your initial pull request:

  1. Commit your updates
  2. Push your changes to gitHub
  3. Verify the new commits were automatically added to your open pull request

java_iv_lab_iii's People

Contributors

jeff-anderson-cscc avatar jeffrey-anderson avatar synergy232 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.