You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs-source/cloudbank/content/account/cr-accounts.md
+17-11Lines changed: 17 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,7 +111,7 @@ weight = 7
111
111
112
112
Now we want to create an endpoint to create a new account. Open `AccountController.java` and add a new `createAccount` method. This method should return `ResponseEntity<Account>` this will allow you to return the account object, but also gives you access to set headers, status code and so on. The method needs to take an `Account` as an argument. Add the `RequestBody` annotation to the argument to tell Spring Boot that the input data will be in the HTTP request's body.
113
113
114
-
Inside the method, you should use the `saveAndFlush` method on the JPARepository to save a new instance of `Account` in the database. The `saveAndFlush` method returns the created object. If the save was successful, return the created object and set the HTTPStatusCode to 201 (Created).If there is an error, set the HTTPStatusCode to 500 (InternalServerError).
114
+
Inside the method, you should use the `saveAndFlush` method on the JPARepository to save a new instance of `Account` in the database. The `saveAndFlush` method returns the created object. If the save was successful, return the URI to the created object and set the HTTPStatusCode to 201 (Created).If the object already exists set the HTTPStatus code to 409 (Conflict).If there is an error, set the HTTPStatusCode to 500 (InternalServerError).
115
115
116
116
Here's what the new method (and imports) should look like:
117
117
@@ -130,16 +130,22 @@ weight = 7
130
130
131
131
@PostMapping("/account")
132
132
public ResponseEntity<Account> createAccount(@RequestBody Account account) {
0 commit comments