Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
fix: Updated starter app to be compatible with 1.0.0-alpha17 client v…
Browse files Browse the repository at this point in the history
…ersion
  • Loading branch information
JigarJoshi committed Jun 11, 2022
1 parent 9708713 commit 0286800
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 100 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tigrisdata</groupId>
<artifactId>tigris-example-java</artifactId>
<version>1.0.0-alpha.16</version>
<version>1.0.0-alpha.17</version>

<dependencies>
<dependency>
Expand All @@ -26,7 +26,7 @@
</dependencies>
<properties>
<!-- we are still pre-release -->
<tigris.client.java.version>1.0.0-alpha.16</tigris.client.java.version>
<tigris.client.java.version>1.0.0-alpha.17</tigris.client.java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
104 changes: 53 additions & 51 deletions src/main/java/com/tigrisdata/starter/collections/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Order implements TigrisCollectionType {

@TigrisField(description = "A unique identifier for the order")
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private Integer id;
private int id;

@TigrisField(description = "The identifier of the user that placed the order")
private int userId;
Expand All @@ -43,6 +43,54 @@ public Order(int userId, double orderTotal, List<ProductItem> productItems) {
this.productItems = productItems;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public double getOrderTotal() {
return orderTotal;
}

public void setOrderTotal(double orderTotal) {
this.orderTotal = orderTotal;
}

public List<ProductItem> getProductItems() {
return productItems;
}

public void setProductItems(List<ProductItem> productItems) {
this.productItems = productItems;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Order order = (Order) o;
return userId == order.userId
&& Double.compare(order.orderTotal, orderTotal) == 0
&& Objects.equals(id, order.id)
&& Objects.equals(productItems, order.productItems);
}

@Override
public int hashCode() {
return Objects.hash(id, userId, orderTotal, productItems);
}

public static class ProductItem {
@TigrisField(description = "The product identifier")
private int productId;
Expand All @@ -61,14 +109,14 @@ public int getProductId() {
return productId;
}

public int getQuantity() {
return quantity;
}

public void setProductId(int productId) {
this.productId = productId;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}
Expand All @@ -91,50 +139,4 @@ public int hashCode() {
return result;
}
}

public Integer getId() {
return id;
}

public int getUserId() {
return userId;
}

public double getOrderTotal() {
return orderTotal;
}

public List<ProductItem> getProductItems() {
return productItems;
}

public void setId(Integer id) {
this.id = id;
}

public void setUserId(int userId) {
this.userId = userId;
}

public void setOrderTotal(double orderTotal) {
this.orderTotal = orderTotal;
}

public void setProductItems(List<ProductItem> productItems) {
this.productItems = productItems;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Order order = (Order) o;
return userId == order.userId && Double.compare(order.orderTotal, orderTotal) == 0 && Objects.equals(id,
order.id) && Objects.equals(productItems, order.productItems);
}

@Override
public int hashCode() {
return Objects.hash(id, userId, orderTotal, productItems);
}
}
36 changes: 19 additions & 17 deletions src/main/java/com/tigrisdata/starter/collections/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Product implements TigrisCollectionType {

@TigrisField(description = "A unique identifier for the product")
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private Integer id;
private int id;

@TigrisField(description = "Name of the product")
private String name;
Expand All @@ -38,41 +38,41 @@ public class Product implements TigrisCollectionType {

public Product() {}

public Product(Integer id, String name, int quantity, double price) {
public Product(int id, String name, int quantity, double price) {
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
}

public Integer getId() {
public int getId() {
return id;
}

public String getName() {
return name;
}

public int getQuantity() {
return quantity;
}

public double getPrice() {
return price;
public void setId(int id) {
this.id = id;
}

public void setId(Integer id) {
this.id = id;
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}
Expand All @@ -82,8 +82,10 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return quantity == product.quantity && Double.compare(product.price, price) == 0 && Objects.equals(id,
product.id) && Objects.equals(name, product.name);
return quantity == product.quantity
&& Double.compare(product.price, price) == 0
&& Objects.equals(id, product.id)
&& Objects.equals(name, product.name);
}

@Override
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/com/tigrisdata/starter/collections/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public class User implements TigrisCollectionType {
@TigrisField(description = "A unique identifier for the user")
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private Integer id;
private int id;

@TigrisField(description = "Name of the user")
private String name;
Expand All @@ -32,26 +32,26 @@ public class User implements TigrisCollectionType {

public User() {}

public Integer getId() {
public int getId() {
return id;
}

public String getName() {
return name;
}

public double getBalance() {
return balance;
public void setId(int id) {
this.id = id;
}

public void setId(Integer id) {
this.id = id;
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getBalance() {
return balance;
}

public void setBalance(double balance) {
this.balance = balance;
}
Expand All @@ -61,7 +61,9 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return Double.compare(user.balance, balance) == 0 && Objects.equals(id, user.id) && Objects.equals(name, user.name);
return Double.compare(user.balance, balance) == 0
&& Objects.equals(id, user.id)
&& Objects.equals(name, user.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ public OrderController(TigrisDatabase tigrisStarterDatabase) {
public ResponseEntity<Order> read(@PathVariable("id") int id) throws TigrisException {
Optional<Order> order =
tigrisStarterDatabase.getCollection(Order.class).readOne(Filters.eq("id", id));
if (order.isPresent()) {
return ResponseEntity.ok(order.get());
}
return ResponseEntity.notFound().build();
return order.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package com.tigrisdata.starter.controller;

import com.tigrisdata.db.client.Filters;
import com.tigrisdata.db.client.InsertResponse;
import com.tigrisdata.db.client.TigrisCollection;
import com.tigrisdata.db.client.TigrisDatabase;
import com.tigrisdata.db.client.error.TigrisException;
Expand Down Expand Up @@ -43,17 +42,15 @@ public ProductController(TigrisDatabase tigrisDatabase) {

@PostMapping("/create")
public ResponseEntity<String> create(@RequestBody Product product) throws TigrisException {
InsertResponse insertResponse = productTigrisCollection.insert(product);
return ResponseEntity.status(HttpStatus.CREATED).body("product created with id = "+insertResponse.getGeneratedKeys()[0].get("id"));
productTigrisCollection.insert(product);
return ResponseEntity.status(HttpStatus.CREATED)
.body("product created with id = " + product.getId());
}

@GetMapping("/{id}")
public ResponseEntity<Product> read(@PathVariable("id") int id) throws TigrisException {
Optional<Product> product = productTigrisCollection.readOne(Filters.eq("id", id));
if (product.isPresent()) {
return ResponseEntity.ok(product.get());
}
return ResponseEntity.notFound().build();
return product.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,13 @@ public UserController(TigrisDatabase tigrisDatabase) {
@PostMapping("/create")
public ResponseEntity<String> create(@RequestBody User user) throws TigrisException {
InsertResponse<User> insertResponse = userTigrisCollection.insert(user);
return ResponseEntity.status(HttpStatus.CREATED).body("User created with id = "+insertResponse.getGeneratedKeys()[0].get("id"));
return ResponseEntity.status(HttpStatus.CREATED).body("User created with id = " + user.getId());
}

@GetMapping("/{id}")
public ResponseEntity<User> read(@PathVariable("id") int id) throws TigrisException {
Optional<User> user = userTigrisCollection.readOne(Filters.eq("id", id));
if (user.isPresent()) {
return ResponseEntity.ok(user.get());
}
return ResponseEntity.notFound().build();
return user.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@

public class TigrisInitializer implements CommandLineRunner {

private static final Logger log = LoggerFactory.getLogger(TigrisInitializer.class);
private final TigrisClient tigrisClient;
private final String dbName;

private static final Logger log = LoggerFactory.getLogger(TigrisInitializer.class);

public TigrisInitializer(TigrisClient tigrisClient, String dbName) {
this.tigrisClient = tigrisClient;
this.dbName = dbName;
Expand Down

0 comments on commit 0286800

Please sign in to comment.