renamed folder
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import io.pratik.dynamodbspring.models.Customer;
|
||||
import io.pratik.dynamodbspring.repositories.CustomerRepository;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class CustomerService {
|
||||
|
||||
@Autowired
|
||||
private CustomerRepository customerRepository;
|
||||
|
||||
public void createCustomer(final Customer customer) {
|
||||
customerRepository.save(customer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.pratik.dynamodbspring;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DynamodbspringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DynamodbspringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import io.pratik.dynamodbspring.models.Order;
|
||||
import io.pratik.dynamodbspring.repositories.OrderRepository;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class OrderService {
|
||||
|
||||
@Autowired
|
||||
private OrderRepository orderRepository;
|
||||
|
||||
public void createOrder(final Order order) {
|
||||
orderRepository.save(order);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.config;
|
||||
|
||||
import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.amazonaws.auth.AWSCredentialsProvider;
|
||||
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
|
||||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
|
||||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@EnableDynamoDBRepositories
|
||||
(basePackages = "io.pratik.dynamodbspring.repositories")
|
||||
public class AppConfig {
|
||||
|
||||
@Bean
|
||||
public AmazonDynamoDB amazonDynamoDB() {
|
||||
AWSCredentialsProvider credentials = new ProfileCredentialsProvider("pratikpoc");
|
||||
AmazonDynamoDB amazonDynamoDB
|
||||
= AmazonDynamoDBClientBuilder.standard().withCredentials(credentials).build();
|
||||
|
||||
return amazonDynamoDB;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.models;
|
||||
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@DynamoDBTable(tableName = "Customer")
|
||||
public class Customer {
|
||||
|
||||
private String customerID;
|
||||
|
||||
private String name;
|
||||
|
||||
private String email;
|
||||
|
||||
// Partition key
|
||||
@DynamoDBHashKey(attributeName = "CustomerID")
|
||||
public String getCustomerID() {
|
||||
return customerID;
|
||||
}
|
||||
|
||||
public void setCustomerID(String customerID) {
|
||||
this.customerID = customerID;
|
||||
}
|
||||
|
||||
@DynamoDBAttribute(attributeName = "Name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@DynamoDBAttribute(attributeName = "Email")
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.models;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@DynamoDBTable(tableName = "Order")
|
||||
public class Order {
|
||||
private String customerID;
|
||||
private String orderSerial;
|
||||
private double orderValue;
|
||||
private Instant createdDate;
|
||||
|
||||
@Id
|
||||
private OrderID orderID;
|
||||
|
||||
|
||||
|
||||
public Order() {
|
||||
super();
|
||||
}
|
||||
// private List<Product> products;
|
||||
|
||||
public Order(OrderID orderID) {
|
||||
super();
|
||||
this.orderID = orderID;
|
||||
}
|
||||
/*
|
||||
* public OrderID getOrderID() { return orderID; } public void
|
||||
* setOrderID(OrderID orderID) { this.orderID = orderID; }
|
||||
*/
|
||||
@DynamoDBHashKey(attributeName = "customerID")
|
||||
public String getCustomerID() {
|
||||
return customerID;
|
||||
}
|
||||
public void setCustomerID(String customerID) {
|
||||
this.customerID = customerID;
|
||||
}
|
||||
|
||||
@DynamoDBRangeKey(attributeName = "orderID")
|
||||
public String getOrderSerial() {
|
||||
return orderSerial;
|
||||
}
|
||||
public void setOrderSerial(String orderSerial) {
|
||||
this.orderSerial = orderSerial;
|
||||
}
|
||||
|
||||
@DynamoDBAttribute
|
||||
public Instant getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
public void setCreatedDate(Instant createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
@DynamoDBAttribute
|
||||
public double getOrderValue() {
|
||||
return orderValue;
|
||||
}
|
||||
public void setOrderValue(double orderValue) {
|
||||
this.orderValue = orderValue;
|
||||
}
|
||||
|
||||
/*@DynamoDBAttribute
|
||||
public List<Product> getProducts() {
|
||||
return products;
|
||||
}
|
||||
public void setProducts(List<Product> products) {
|
||||
this.products = products;
|
||||
}*/
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.models;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
|
||||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
public class OrderID implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String customerID;
|
||||
private String orderSerial;
|
||||
|
||||
public OrderID() {
|
||||
super();
|
||||
this.customerID = null;
|
||||
this.orderSerial = null;
|
||||
}
|
||||
|
||||
public OrderID(String customerID, String orderSerial) {
|
||||
super();
|
||||
this.customerID = customerID;
|
||||
this.orderSerial = orderSerial;
|
||||
}
|
||||
|
||||
@DynamoDBHashKey
|
||||
public String getCustomerID() {
|
||||
return customerID;
|
||||
}
|
||||
public void setCustomerID(String customerID) {
|
||||
this.customerID = customerID;
|
||||
}
|
||||
|
||||
@DynamoDBRangeKey
|
||||
public String getOrderSerial() {
|
||||
return orderSerial;
|
||||
}
|
||||
public void setOrderSerial(String orderSerial) {
|
||||
this.orderSerial = orderSerial;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.models;
|
||||
|
||||
//import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.DynamoDbBean;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
//@DynamoDbBean
|
||||
public class Product {
|
||||
private String name;
|
||||
private String brand;
|
||||
private double price;
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getBrand() {
|
||||
return brand;
|
||||
}
|
||||
public void setBrand(String brand) {
|
||||
this.brand = brand;
|
||||
}
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.repositories;
|
||||
|
||||
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import io.pratik.dynamodbspring.models.Customer;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@EnableScan
|
||||
public interface CustomerRepository extends
|
||||
CrudRepository<Customer, String> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring.repositories;
|
||||
|
||||
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import io.pratik.dynamodbspring.models.Order;
|
||||
import io.pratik.dynamodbspring.models.OrderID;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@EnableScan
|
||||
public interface OrderRepository extends
|
||||
CrudRepository<Order, OrderID> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package io.pratik.dynamodbspring;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import io.pratik.dynamodbspring.models.Customer;
|
||||
|
||||
/**
|
||||
* @author pratikdas
|
||||
*
|
||||
*/
|
||||
@SpringBootTest
|
||||
class CustomerServiceTest {
|
||||
|
||||
@Autowired
|
||||
private CustomerService customerService;
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
@AfterEach
|
||||
void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateCustomer() {
|
||||
Customer customer = new Customer();
|
||||
customer.setCustomerID("CUST-001");
|
||||
customer.setName("pratik");
|
||||
customer.setEmail("hgjgjh");
|
||||
customerService.createCustomer(customer);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package io.pratik.dynamodbspring;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DynamodbspringApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user