Skip to content

Commit

Permalink
Update README and CB updates (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
andytael committed Sep 4, 2024
1 parent 6cd38c2 commit 4e687a6
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 64 deletions.
17 changes: 16 additions & 1 deletion cloudbank-v4/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ This is an example of the `customer32` application:
1. Test `customer` service
1. REST endpoint
1. GET REST endpoint.
```shell
curl -s http://$IP/api/v1/customer | jq
Expand All @@ -272,6 +272,21 @@ This is an example of the `customer32` application:
]
```
1. POST endpoint to create a customer.
```shell
curl -i -X POST 'http://$IP/api/v1/customer' -H 'Content-Type: application/json' -d '{"customerId": "bobsmith", "customerName": "Bob Smith", "customerEmail": "[email protected]"}'
```
Should return the URI of the created object:
```text
HTTP/1.1 201
Location: http://localhost:8080/api/v1/customer/bobsmith
Content-Length: 0
Date: Tue, 03 Sep 2024 21:01:25 GMT
```
1. Test `creditscore` service
1. REST endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public AccountController(AccountRepository accountRepository, JournalRepository

/**
* Get all Accounts.
*
* @return List off accounts
*/
@GetMapping("/accounts")
Expand All @@ -46,26 +47,34 @@ public List<Account> getAllAccounts() {

/**
* Create an account.
* @param account Account object
* @return Http Status Code
*
* @param account Account object.
* @return Returns HTTP Status code or the URI of the created object.
*/
@PostMapping("/account")
public ResponseEntity<Account> createAccount(@RequestBody Account account) {
try {
Account newAccount = accountRepository.saveAndFlush(account);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(newAccount.getAccountId())
.toUri();
return ResponseEntity.created(location).build();
} catch (Exception e) {
return new ResponseEntity<>(account, HttpStatus.INTERNAL_SERVER_ERROR);
boolean exists = accountRepository.existsById(account.getAccountId());

if (!exists) {
try {
Account newAccount = accountRepository.saveAndFlush(account);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(newAccount.getAccountId())
.toUri();
return ResponseEntity.created(location).build();
} catch (Exception e) {
return new ResponseEntity<>(account, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
return new ResponseEntity<>(account, HttpStatus.CONFLICT);
}
}

/**
* Find an account by Account Id.
*
* @param accountId Account Id
* @return An account
*/
Expand All @@ -82,6 +91,7 @@ public ResponseEntity<Account> getAccountById(@PathVariable("accountId") long ac

/**
* Find an account by customer Id.
*
* @param customerId Customer Id
* @return A list opf Account(s)
*/
Expand All @@ -101,6 +111,7 @@ public ResponseEntity<List<Account>> getAccountsByCustomerId(@PathVariable("cust

/**
* Delete an Account with specific Id.
*
* @param accountId Account ID
* @return HTTP Status Code
*/
Expand All @@ -116,6 +127,7 @@ public ResponseEntity<HttpStatus> deleteAccount(@PathVariable("accountId") long

/**
* Get transactions (Journal) for an Account Id.
*
* @param accountId Account Id
* @return List of Journal object(s)
*/
Expand All @@ -135,21 +147,28 @@ public ResponseEntity<List<Journal>> getTransactions(@PathVariable("accountId")

/**
* Create a Journal entry.
*
* @param journalEntry Journal object
* @return HTTP Status Code
*/
@PostMapping("/account/journal")
public ResponseEntity<Journal> postSimpleJournalEntry(@RequestBody Journal journalEntry) {
try {
Journal newJournalEntry = journalRepository.saveAndFlush(journalEntry);
return new ResponseEntity<>(newJournalEntry, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
boolean exists = journalRepository.existsById(journalEntry.getJournalId());
if (!exists) {
try {
Journal newJournalEntry = journalRepository.saveAndFlush(journalEntry);
return new ResponseEntity<>(newJournalEntry, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
return new ResponseEntity<>(journalEntry, HttpStatus.CONFLICT);
}
}

/**
* Find Journal entries by Account Id.
*
* @param accountId Account Id
* @return Journal object(s)
*/
Expand All @@ -160,12 +179,14 @@ public List<Journal> getJournalEntriesForAccount(@PathVariable("accountId") long

/**
* Clears the Journal Entry.
*
* @param journalId Journal Id
* @return HTTP Status Code
*/
@PostMapping("/account/journal/{journalId}/clear")
public ResponseEntity<Journal> clearJournalEntry(@PathVariable long journalId) {
try {
boolean exists = journalRepository.existsById(journalId);
Optional<Journal> data = journalRepository.findById(journalId);
if (data.isPresent()) {
Journal newJournalEntry = data.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

package com.example.customer.controller;

import java.net.URI;
import java.util.List;
import java.util.Optional;

import com.example.customer.model.Customers;
import com.example.customer.repository.CustomersRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -19,9 +21,11 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

@RestController
@RequestMapping("/api/v1")
@Slf4j
public class CustomerController {
final CustomersRepository customersRepository;

Expand All @@ -44,6 +48,7 @@ public List<Customers> findByCustomerByName(@PathVariable String customerName) {

/**
* Get Customer with specific ID.
*
* @param id The CustomerId
* @return If the customers is found, a customer and HTTP Status code.
*/
Expand All @@ -60,6 +65,7 @@ public ResponseEntity<Customers> getCustomerById(@PathVariable("id") String id)

/**
* Get customer that contains an email.
*
* @param email of the customer
* @return Returns a customer if found
*/
Expand All @@ -70,27 +76,40 @@ public List<Customers> getCustomerByEmail(@PathVariable("email") String email) {

/**
* Create a customer.
* @param customer Customer object with the customer details
* @return Returns a HTTP Status code
*
* @param customer Customer object with the customer details.
* @return Returns HTTP Status code or the URI of the created object.
*/
@PostMapping("/customer")
public ResponseEntity<Customers> createCustomer(@RequestBody Customers customer) {
try {
Customers newCustomer = customersRepository.save(new Customers(
customer.getCustomerId(),
customer.getCustomerName(),
customer.getCustomerEmail(),
customer.getCustomerOtherDetails()));
return new ResponseEntity<>(newCustomer, HttpStatus.CREATED);
boolean exists = customersRepository.existsById(customer.getCustomerId());

} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
if (!exists) {
try {
Customers newCustomer = customersRepository.saveAndFlush(new Customers(
customer.getCustomerId(),
customer.getCustomerName(),
customer.getCustomerEmail(),
customer.getCustomerOtherDetails()));

URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(newCustomer.getCustomerId())
.toUri();
return ResponseEntity.created(location).build();
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
return new ResponseEntity<>(customer, HttpStatus.CONFLICT);
}
}

/**
* Update a specific Customer (ID).
* @param id The id of the customer
*
* @param id The id of the customer
* @param customer A customer object
* @return A Http Status code
*/
Expand All @@ -114,6 +133,7 @@ public ResponseEntity<Customers> updateCustomer(@PathVariable("id") String id, @

/**
* Delete a specific customer (ID).
*
* @param customerId the Id of the customer to be deleted
* @return A Http Status code
*/
Expand All @@ -129,11 +149,12 @@ public ResponseEntity<HttpStatus> deleteCustomer(@PathVariable("customerId") Str

/**
* Method isn't implemented.
*
* @param amount Loan amount
* @return A Http Status
*/
@PostMapping("/customer/applyLoan/{amount}")
public ResponseEntity<HttpStatus> applyForLoan(@PathVariable ("amount") long amount) {
public ResponseEntity<HttpStatus> applyForLoan(@PathVariable("amount") long amount) {
try {
// Check Credit Rating
// Amount vs Rating approval?
Expand Down
28 changes: 17 additions & 11 deletions docs-source/cloudbank/content/account/cr-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ weight = 7

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.

Inside the method, you should use the `saveAndFlush` method on the JPA Repository 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 HTTP Status Code to 201 (Created). If there is an error, set the HTTP Status Code to 500 (Internal Server Error).
Inside the method, you should use the `saveAndFlush` method on the JPA Repository 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 HTTP Status Code to 201 (Created). If the object already exists set the HTTP Status code to 409 (Conflict). If there is an error, set the HTTP Status Code to 500 (Internal Server Error).

Here's what the new method (and imports) should look like:
Expand All @@ -130,16 +130,22 @@ weight = 7
@PostMapping("/account")
public ResponseEntity<Account> createAccount(@RequestBody Account account) {
try {
Account newAccount = accountRepository.saveAndFlush(account);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(newAccount.getAccountId())
.toUri();
return ResponseEntity.created(location).build();
} catch (Exception e) {
return new ResponseEntity<>(account, HttpStatus.INTERNAL_SERVER_ERROR);
boolean exists = accountRepository.existsById(account.getAccountId());
if (!exists) {
try {
Account newAccount = accountRepository.saveAndFlush(account);
URI location = ServletUriComponentsBuilder
.fromCurrentRequest()
.path("/{id}")
.buildAndExpand(newAccount.getAccountId())
.toUri();
return ResponseEntity.created(location).build();
} catch (Exception e) {
return new ResponseEntity<>(account, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
return new ResponseEntity<>(account, HttpStatus.CONFLICT);
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs-source/cloudbank/content/account/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ weight = 9
\_/ |_) (_| (_| __) \_ |_ _|_
========================================================================================
Application Name: Oracle Backend Platform :: Command Line Interface
Application Version: (1.2.0)
:: Spring Boot (v3.3.0) ::
Application Version: (1.3.0)
:: Spring Boot (v3.3.3) ::
Ask for help:
- Slack: https://oracledevs.slack.com/archives/C03ALDSV272
Expand Down
4 changes: 2 additions & 2 deletions docs-source/cloudbank/content/check/check-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ Next, you will create the "Check Processing" microservice which you will receive
\_/ |_) (_| (_| __) \_ |_ _|_
========================================================================================
Application Name: Oracle Backend Platform :: Command Line Interface
Application Version: (1.2.0)
:: Spring Boot (v3.3.0) ::
Application Version: (1.3.0)
:: Spring Boot (v3.3.3) ::

Ask for help:
- Slack: https://oracledevs.slack.com/archives/C03ALDSV272
Expand Down
4 changes: 2 additions & 2 deletions docs-source/cloudbank/content/check/create-testrunner.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ Next, you will create the "Test Runner" microservice which you will use to simul
\_/ |_) (_| (_| __) \_ |_ _|_
========================================================================================
Application Name: Oracle Backend Platform :: Command Line Interface
Application Version: (1.2.0)
:: Spring Boot (v3.3.0) ::
Application Version: (1.3.0)
:: Spring Boot (v3.3.3) ::

Ask for help:
- Slack: https://oracledevs.slack.com/archives/C03ALDSV272
Expand Down
19 changes: 12 additions & 7 deletions docs-source/cloudbank/content/check/update-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,16 @@ Starting with the account service that you built in the previous lab, you will t

@PostMapping("/account/journal")
public ResponseEntity<Journal> postSimpleJournalEntry(@RequestBody Journal journalEntry) {
try {
Journal _journalEntry = journalRepository.saveAndFlush(journalEntry);
return new ResponseEntity<>(_journalEntry, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
boolean exists = journalRepository.existsById(journalEntry.getJournalId());
if (!exists) {
try {
Journal newJournalEntry = journalRepository.saveAndFlush(journalEntry);
return new ResponseEntity<>(newJournalEntry, HttpStatus.CREATED);
} catch (Exception e) {
return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
} else {
return new ResponseEntity<>(journalEntry, HttpStatus.CONFLICT);
}
}
```
Expand Down Expand Up @@ -195,8 +200,8 @@ Starting with the account service that you built in the previous lab, you will t
\_/ |_) (_| (_| __) \_ |_ _|_
========================================================================================
Application Name: Oracle Backend Platform :: Command Line Interface
Application Version: (1.2.0)
:: Spring Boot (v3.3.0) ::
Application Version: (1.3.0)
:: Spring Boot (v3.3.3) ::
Ask for help:
- Slack: https://oracledevs.slack.com/archives/C03ALDSV272
Expand Down
4 changes: 2 additions & 2 deletions docs-source/cloudbank/content/deploy-cli/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ weight = 4
\_/ |_) (_| (_| __) \_ |_ _|_
========================================================================================
Application Name: Oracle Backend Platform :: Command Line Interface
Application Version: (1.2.0)
:: Spring Boot (v3.3.0) ::
Application Version: (1.3.0)
:: Spring Boot (v3.3.3) ::
Ask for help:
- Slack: https://oracledevs.slack.com/archives/C03ALDSV272
Expand Down
Loading

0 comments on commit 4e687a6

Please sign in to comment.