updates
This commit is contained in:
@@ -36,11 +36,16 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.17'
|
||||
implementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.17'
|
||||
|
||||
implementation 'io.netty:netty-common:4.2.8.Final'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-webflux:4.0.0'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webflux-api:3.0.0'
|
||||
implementation 'org.springdoc:springdoc-openapi-starter-webflux-ui:3.0.0'
|
||||
implementation 'jakarta.json.bind:jakarta.json.bind-api:3.0.1'
|
||||
implementation 'jakarta.json.bind:jakarta.json.bind-api:3.0.1'
|
||||
|
||||
implementation project(':Model')
|
||||
}
|
||||
|
||||
|
||||
181
Ui/src/main/java/edu/inventorym/ApiController.java
Normal file
181
Ui/src/main/java/edu/inventorym/ApiController.java
Normal file
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* license: GPLv3
|
||||
edu.inventorym
|
||||
*/
|
||||
package edu.inventorym;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import edu.inventorym.model.Customer;
|
||||
import edu.inventorym.model.CustomerManager;
|
||||
import edu.inventorym.model.Drawing;
|
||||
import edu.inventorym.model.InventoryList;
|
||||
import edu.inventorym.model.InventoryManager;
|
||||
import edu.inventorym.model.InventoryPiece;
|
||||
import edu.inventorym.model.Painting;
|
||||
import edu.inventorym.model.Print;
|
||||
import edu.inventorym.model.Sculpture;
|
||||
import edu.inventorym.model.Transaction;
|
||||
import edu.inventorym.model.TransactionList;
|
||||
import edu.inventorym.model.TransactionManager;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public interface ApiController { // SINGLETON
|
||||
|
||||
@Operation(summary = "Get status Inventory Loaded", description = "Returns status Inventory Loaded.")
|
||||
@ApiResponse(responseCode = "200", description = "loaded")
|
||||
@GetMapping
|
||||
public static ResponseEntity<String> getInventory() {
|
||||
/* Inventory pieces */
|
||||
InventoryManager.getInstance().load();
|
||||
if (InventoryManager.getInstance().INVENTORY.isEmpty()) {
|
||||
/* Add Inventory */
|
||||
InventoryManager.getInstance().add(make(new Drawing()));
|
||||
InventoryManager.getInstance().add(make(new Print()));
|
||||
InventoryManager.getInstance().add(make(new Painting()));
|
||||
InventoryManager.getInstance().add(make(new Sculpture()));
|
||||
InventoryManager.getInstance().add(make(new Sculpture()));
|
||||
InventoryManager.getInstance().add(make(new Sculpture()));
|
||||
}
|
||||
return new ResponseEntity<>("Resource loaded!", HttpStatus.OK);
|
||||
}
|
||||
|
||||
static void callerInterface() {
|
||||
// @Comment
|
||||
/*
|
||||
* 1. Add new art object to the inventory. Your manager must check that the art
|
||||
* is not already in the inventory before adding
|
||||
*/
|
||||
|
||||
/* Customers */
|
||||
CustomerManager.getInstance().load();
|
||||
if (CustomerManager.getInstance().CUSTOMERS.isEmpty()) {
|
||||
/* Add Customer */
|
||||
CustomerManager.getInstance().add(new Customer("Kate", "Demsey", "310-676-4844", "kate@museum.com"));
|
||||
CustomerManager.getInstance().add(new Customer("Jim", "Gumbly", "203-676-4844", "jim@homedeco.com"));
|
||||
CustomerManager.getInstance().add(new Customer("Evan", "Hao", "203-676-8943", "evan@homedeco.com"));
|
||||
|
||||
/* Update Customer List */
|
||||
CustomerManager.getInstance().save();
|
||||
}
|
||||
|
||||
/*
|
||||
* 2. Remove art object from the inventory
|
||||
*/
|
||||
InventoryManager imgr = InventoryManager.getInstance();
|
||||
System.out.println(String.format("Art Pieces in INVENTORY: count %d", imgr.INVENTORY.size()));
|
||||
InventoryPiece art = imgr.INVENTORY.getLast();
|
||||
InventoryPiece piece = imgr.find(art.getId());
|
||||
imgr.Remove(piece);
|
||||
imgr.save();
|
||||
System.out.println(String.format("Removed 1 Art Pieces from INVENTORY: count %d", imgr.INVENTORY.size()));
|
||||
/*
|
||||
* 3. Return a list of all art objects from inventory
|
||||
*/
|
||||
System.out.println("============= Inventory List ===============");
|
||||
imgr.INVENTORY.forEach(System.out::println);
|
||||
System.out.println("\n");
|
||||
|
||||
if (imgr.INVENTORY.isEmpty()) {
|
||||
System.out.println(String.format("%s: No Inventoried Art Piecies Available !!!. ", ApiController.class));
|
||||
return;
|
||||
}
|
||||
|
||||
CustomerManager cmgr = CustomerManager.getInstance();
|
||||
Customer customer = cmgr.findByEmail("kate@museum.com");
|
||||
InventoryList customerCart = new InventoryList();
|
||||
customerCart.add(imgr.INVENTORY.getFirst());
|
||||
customerCart.add(imgr.INVENTORY.getLast());
|
||||
|
||||
TransactionManager tmgr = TransactionManager.getInstance();
|
||||
tmgr.load();
|
||||
/*
|
||||
* 3. Add a new transaction object to the list manager is handling
|
||||
*/
|
||||
Transaction tran = tmgr.TransactRequest(customer, customerCart);
|
||||
/*
|
||||
* 4. Calculate and return transaction price
|
||||
* 5. Complete transaction
|
||||
* 6. Remove transaction object
|
||||
*/
|
||||
tmgr.compute(tran);
|
||||
tmgr.complete(tran);
|
||||
// tmgr.remove(tran);
|
||||
/*
|
||||
* 7. Format and return transaction data in print format
|
||||
*/
|
||||
System.out.println(tran);
|
||||
/*
|
||||
* 8. Retrieve and return transactions based on:
|
||||
* customer email
|
||||
*/
|
||||
TransactionList foundTrans = tmgr.findByCustomerEmail(customer.getEmail());
|
||||
/*
|
||||
* transaction date
|
||||
*/
|
||||
foundTrans = tmgr.findByTransactionDate(tran.getCompleted());
|
||||
/*
|
||||
* transaction id
|
||||
*/
|
||||
foundTrans = tmgr.findByTransactionId(tran.getId());
|
||||
/*
|
||||
* art id
|
||||
*/
|
||||
foundTrans = tmgr.findByTransactionId(tran.getId());
|
||||
|
||||
/*
|
||||
* 9. Update inventory file(s) on local system
|
||||
*/
|
||||
InventoryManager.getInstance().save();
|
||||
/*
|
||||
* 10. Update transaction file(s) on local system
|
||||
*/
|
||||
TransactionManager.getInstance().save();
|
||||
}
|
||||
|
||||
static Drawing make(Drawing o) {
|
||||
o.setTitle("Windy Rowing");
|
||||
o.setDescription("East Market Square find. Local Author.");
|
||||
o.setAuthor("Dave Janson");
|
||||
o.setPrice(92.0f);
|
||||
o.setCreated(ZonedDateTime.now());
|
||||
return o;
|
||||
}
|
||||
|
||||
static Painting make(Painting o) {
|
||||
o.setTitle("Walking by the beach.");
|
||||
o.setDescription("East Market Square find. Local Author.");
|
||||
o.setAuthor("Dave Janson");
|
||||
o.setPrice(51.0f);
|
||||
o.setCreated(ZonedDateTime.now());
|
||||
return o;
|
||||
}
|
||||
|
||||
static Print make(Print o) {
|
||||
o.setTitle("Different day same thing");
|
||||
o.setDescription("East Market Square find. Local Author.");
|
||||
o.setAuthor("Dave Janson");
|
||||
o.setPrice(102.0f);
|
||||
o.setCreated(ZonedDateTime.now());
|
||||
return o;
|
||||
}
|
||||
|
||||
static Sculpture make(Sculpture o) {
|
||||
o.setTitle("Jolly Romp");
|
||||
o.setDescription("East Market Square find. Local Author.");
|
||||
o.setAuthor("Dave Janson");
|
||||
o.setPrice(32.0f);
|
||||
o.setWeight(4.0F);
|
||||
o.setCreated(ZonedDateTime.now());
|
||||
return o;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@
|
||||
*/
|
||||
package edu.inventorym;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
@@ -17,18 +19,21 @@ import io.swagger.v3.oas.annotations.info.Info;
|
||||
@EnableWebFlux
|
||||
@SpringBootApplication
|
||||
@OpenAPIDefinition(info = @Info(title = "Model API", version = "3.0.0", description = "Documentation Model API v1.0"))
|
||||
public class Application {
|
||||
public class BackendService {
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder()
|
||||
public static final void BackendServiceStart(String[] args){
|
||||
CompletableFuture.runAsync(() -> {
|
||||
// Long-running background operation
|
||||
new SpringApplicationBuilder()
|
||||
.profiles("dev")
|
||||
.web(WebApplicationType.REACTIVE)
|
||||
.sources(Application.class, Controller.class)
|
||||
.sources(BackendService.class, Controller.class, ApiController.class)
|
||||
.run(args);
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
public NettyReactiveWebServerFactory nettyServerFactory() {
|
||||
public static final NettyReactiveWebServerFactory nettyServerFactory() {
|
||||
NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
|
||||
return factory;
|
||||
}
|
||||
Reference in New Issue
Block a user