Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

REST Assignment 2 ITEC 4860 Spring 2023 In this assignment, you will build on your code for REST Assignment 1 and add four new methods

image text in transcribed

REST Assignment 2 ITEC 4860 Spring 2023 In this assignment, you will build on your code for REST Assignment 1 and add four new methods that handle POST, PUT and DELETE requests. Implement the following four methods in the Controller class: - A createUser method that takes a single User object as input and adds the object to the hash map which stores all the User objects, only if the input is valid. Unlike what we did in class, here we allow the user to choose the ID, but must check whether the ID chosen by the user already exists. If the ID in the input object already exists, the createUser method must throw a ResponseStatusException with a BAD_REQUEST HTTP status and a proper error message; otherwise, the method should add the input User object to the hash map and return a message indicating that the User object was successfully created. Be sure to specify POST as the request method for createUser. - A createUsers method that takes a list of User objects as input and adds to the hash map only those whose ID has not been chosen. If the ID of any User object in the input list already exists, the createUsers method must throw a ResponseStatusException with a BAD_REQUEST HTTP status and a proper error message including the information of all the requested objects that could not be created; otherwise, after adding all the User objects in the input list to the hash map, the method should return a message indicating that all User objects in the request were successfully created. Be sure to specify POST as the request method for createUsers. - An updateUser method that takes a User object as input. If the user exists in the hash map which stores all the User objects, the method should update the user's name with the name field of the input User object and return a proper message; otherwise, the method should throw a ResponseStatusException with a NOT_FOUND HTTP status and a proper error message. Be sure to specify PUT as the request method for updateUser. - A deleteUser method that takes an ID as input and deletes the User object with the given ID from the hash map, if the user exists. If the user does not exist, the method should throw a ResponseStatusException with a NOT_FOUND HTTP status and a proper error message; otherwise, the method should return a proper message after deleting the User object. Be sure to specify DELETE as the request method for deleteUser

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

what are resourceful websites about cuba and cuban cusisne

Answered: 1 week ago