Language:EN
Pages: 17
Words: 1268
Rating : ⭐⭐⭐⭐⭐
Price: $10.99
Page 1 Preview
run and deploy build and run your spring boot appl

Create Stock Trades API Assignment Answers

Your question:

GET request to / trades/ ⟨id⟩ : - returns a trade with the given id - if the matching trade exists, the response code is 200 and the response body is the matching trade object - If there is no trade with the given id in the collection, the response code is 404 DELETE, PUT, PATCH request to / trades/> : - the response code is 405 because the API does not allow deleting or modifying trades for any id value You should complete the given project so that it passes all the test cases rienrunning the provided unit tests. The project by default supports the use of the H2 database. GET request to / trades The response code is 200, and when converted to JSON, the response body (assuming that the below objects are all objects in the collection) is as follows: [ "id": 1, "type": "buy", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 159151426400⊙ \}, \{ "id": 2, "type": "sell", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 1591514264000 [ \{ "id": 1, "type": "buy", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 1591514264000 \}, \{ "id": 2, "type": "sell", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 1591514264000 - creates a new trade - expects a JSON trade object without an id property as a body payload. You can assume that the given object is always valid. - adds the given trade object to the collection of trades and assigns a unique integer id to it. The first created trade must have id 1, the second one 2 , and so on. - the response code is 201, and the response body is the created trade object GET request to / trades: - return a collection of all trades - the response code is 200 , and the response body is an array of all trade objects ordered by their ids in increasing order GET request to / trades/〈id ⟩ : thintis a trade with the given id - If the matching trade exists, the response code is 200 and the The question(s) requires Java Development Kit 17. - Install JDK 17 on Macos - Install JDK 17 on Windows - Install JDK 17 on Linux - Install Maven Git Instructions Use the following commands to work with this project Run Copy mvn clean spring- boot:run Example requests and responses POST request to / trades Request body: \{ "type": "buy", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 1591514264000 The response code is 201, and when converted to JSON, the response body is: f "id": 1, "type": "buy", "userId": 1, "symbol": "AC", "shares": 28 , "price": 162 . "timestamp" 1591514264000 GET request to / trades /1 Assuming that the object with id 1 exists, then the response code is 200 and the response body, when converted to JSON, is as follows: \{ "id": 1, "type": "buy", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 1591514264000 \} If an object with id 1 doesn't exist, then the response code is 404 and there are no particular requirements for the response body. DELETE request to / trades/1 The response rode is 405 Here is an example of a trade JSON obiect: \{ "id":1, "type": "buy", "userId": 23, "symbol": "ABX", "shares": 30 , "price": 134, "timestamp": 1531522701000 \} You are provided with the implementation of the Trade model. The task is to implement the REST service that exposes the / trades endpoint, which allows for managing the collection of trade records in the following way: POST request to / trades: 1. Spring Boot: Stock Trades API In this challenge, your task is to implement a simple REST API to manage a collection of stock trades. Each trade is a JSON entry with the following keys: - id: The unique trade ID. (Integer) - type: The trade type, either 'buy' or 'sell'. (String) - userId: The unique user ID. (Integer): - symbol: The stock symbol. (String) - shares: The total number of shares traded. The traded shares value is between 10 and 30 shares, inclusive. (integer) - price: The price of one share of stock at the time of the trade. (t) timestam: The epoch time of the stock trade in milliseconds. (Long) DELETE request to Itrades/1 The response code is 405 and there are no particular requirements for the response body. Software Instructions The question(s) requires Java Development Kit 17. - Install JDK 17 on Macos - Install JDK 17 on Windows - Install JDK 17 on Linux - Install Maven Example requests and responses POST request to / trades Request body: \{ "type": "buy", "userId": 1, "symbol": "AC", "shares": 28, "price": 162, "timestamp" : 1591514264000 \} The response code is 201, and when converted to JSON, the response body is: f "id": 1 , "type": "buy", "userId": 1 , "symbol": "AC", "shares": 28, "price": 162, "timestamp" 1591514264000

student submitted image, transcription available below

student submitted image, transcription available below

student submitted image, transcription available below

Assignment Help Answers with Step-by-Step Explanation:

It seems like you have provided a description of the requirements for a simple REST API for managing stock trades. To implement this REST API, you would typically use a Java framework like Spring Boot and a database for storing trade records. Here is a high-level overview of how you can implement this API:

1. Setup Your Development Environment:

3. Define the Trade Model:

- Create a `Trade` class that represents the trade object. It should have fields for `id`, `type`, `userId`, `symbol`, `shares`, `price`, and `timestamp`.

- `POST /trades`: Create a new trade.

- `DELETE /trades/{id}`: Delete a trade (return 405 if not allowed).

6. Database Integration (Optional):

- If needed, you can integrate a database like H2 to store and retrieve trade records. This will require creating a database entity, repository, and configuring the data source.

9. Run and Deploy:

- Build and run your Spring Boot application. You can run it locally or deploy it to a server, depending on your needs.

You are viewing 1/3rd of the document.Purchase the document to get full access instantly

Immediately available after payment
Both online and downloadable
No strings attached
How It Works
Login account
Login Your Account
Place in cart
Add to Cart
send in the money
Make payment
Document download
Download File
img

Uploaded by : Hector Lee

PageId: DOC356A633