diff --git a/pom.xml b/pom.xml
index 082be39..09730ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -57,6 +57,11 @@
graphiql-spring-boot-starter
5.0.2
+
+ com.graphql-java
+ graphql-java-extended-scalars
+ 1.0
+
diff --git a/src/main/java/cryptosky/me/graphql/jpa/entity/BtcPrice.java b/src/main/java/cryptosky/me/graphql/jpa/entity/BtcPrice.java
deleted file mode 100644
index 0476e26..0000000
--- a/src/main/java/cryptosky/me/graphql/jpa/entity/BtcPrice.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package cryptosky.me.graphql.jpa.entity;
-
-import lombok.*;
-import javax.persistence.*;
-
-@EqualsAndHashCode(callSuper = true)
-@NoArgsConstructor
-@ToString
-@Data
-@Table(name="btc_usd")
-public class BtcPrice extends CryptoPrice {
-}
diff --git a/src/main/java/cryptosky/me/graphql/jpa/entity/BtcPriceModel.java b/src/main/java/cryptosky/me/graphql/jpa/entity/BtcPriceModel.java
new file mode 100644
index 0000000..abb1e27
--- /dev/null
+++ b/src/main/java/cryptosky/me/graphql/jpa/entity/BtcPriceModel.java
@@ -0,0 +1,15 @@
+package cryptosky.me.graphql.jpa.entity;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Entity
+@Table(name = "btc_price")
+public class BtcPriceModel extends CryptoPriceModel {
+
+}
diff --git a/src/main/java/cryptosky/me/graphql/jpa/entity/CryptoPrice.java b/src/main/java/cryptosky/me/graphql/jpa/entity/CryptoPriceModel.java
similarity index 82%
rename from src/main/java/cryptosky/me/graphql/jpa/entity/CryptoPrice.java
rename to src/main/java/cryptosky/me/graphql/jpa/entity/CryptoPriceModel.java
index f8d8ba5..f843111 100644
--- a/src/main/java/cryptosky/me/graphql/jpa/entity/CryptoPrice.java
+++ b/src/main/java/cryptosky/me/graphql/jpa/entity/CryptoPriceModel.java
@@ -7,24 +7,24 @@ import java.time.LocalDate;
@AllArgsConstructor
@NoArgsConstructor
-@ToString
@Data
-@EqualsAndHashCode
-@Entity
-@Table(name = "crypto_price")
-public class CryptoPrice {
+@MappedSuperclass
+public class CryptoPriceModel {
@Id
@Column(name = "ID", nullable = false)
- @GeneratedValue(strategy = GenerationType.AUTO)
+ @GeneratedValue(strategy = GenerationType.TABLE)
private int id;
+ @NonNull
@Column(name = "timestamp", nullable = false)
- private LocalDate timestamp;
+ private String timestamp;
+ @NonNull
@Column(name = "symbol", nullable = false)
private String type;
+ @NonNull
@Column(name = "av_price", nullable = false)
private float average_price;
diff --git a/src/main/java/cryptosky/me/graphql/jpa/repository/CryptoPriceRepository.java b/src/main/java/cryptosky/me/graphql/jpa/repository/BtcPriceRepository.java
similarity index 55%
rename from src/main/java/cryptosky/me/graphql/jpa/repository/CryptoPriceRepository.java
rename to src/main/java/cryptosky/me/graphql/jpa/repository/BtcPriceRepository.java
index c68db51..fbd1092 100644
--- a/src/main/java/cryptosky/me/graphql/jpa/repository/CryptoPriceRepository.java
+++ b/src/main/java/cryptosky/me/graphql/jpa/repository/BtcPriceRepository.java
@@ -1,9 +1,9 @@
package cryptosky.me.graphql.jpa.repository;
-import cryptosky.me.graphql.jpa.entity.CryptoPrice;
+import cryptosky.me.graphql.jpa.entity.BtcPriceModel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
-public interface CryptoPriceRepository extends JpaRepository {
+public interface BtcPriceRepository extends JpaRepository {
}
diff --git a/src/main/java/cryptosky/me/graphql/mutation/BtcPriceMutation.java b/src/main/java/cryptosky/me/graphql/mutation/BtcPriceMutation.java
new file mode 100644
index 0000000..811f670
--- /dev/null
+++ b/src/main/java/cryptosky/me/graphql/mutation/BtcPriceMutation.java
@@ -0,0 +1,21 @@
+package cryptosky.me.graphql.mutation;
+
+import com.coxautodev.graphql.tools.GraphQLMutationResolver;
+import cryptosky.me.graphql.jpa.entity.BtcPriceModel;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import cryptosky.me.graphql.service.BtcPriceService;
+
+@Component
+public class BtcPriceMutation implements GraphQLMutationResolver {
+
+ @Autowired
+ private BtcPriceService btcPriceService;
+
+ public BtcPriceModel createBtc(final String createdDate, final String type, final float av_price,
+ final float h_price, final float l_price, final float c_price, final float volume ) {
+ return this.btcPriceService.createBtc(createdDate, type, av_price, h_price, l_price, c_price, volume);
+ }
+
+}
diff --git a/src/main/java/cryptosky/me/graphql/mutation/CryptoPriceMutation.java b/src/main/java/cryptosky/me/graphql/mutation/CryptoPriceMutation.java
deleted file mode 100644
index 2a76ab5..0000000
--- a/src/main/java/cryptosky/me/graphql/mutation/CryptoPriceMutation.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package cryptosky.me.graphql.mutation;
-
-import com.coxautodev.graphql.tools.GraphQLMutationResolver;
-import cryptosky.me.graphql.jpa.entity.BtcPrice;
-import cryptosky.me.graphql.jpa.entity.CryptoPrice;
-import cryptosky.me.graphql.service.CryptoPriceService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-@Component
-public class CryptoPriceMutation implements GraphQLMutationResolver {
-
- @Autowired
- private CryptoPriceService cryptoPriceService;
-
-// public CryptoPrice createPrice(final String createdDate, final String type, final float av_price,
-// final float h_price, final float l_price, final float c_price, final float volume ) {
-// return this.cryptoPriceService.createPrice(createdDate, type, av_price, h_price, l_price, c_price, volume);
-// }
-
- public BtcPrice createBtc(final String createdDate, final String type, final float av_price,
- final float h_price, final float l_price, final float c_price, final float volume ) {
- return this.cryptoPriceService.createBtc(createdDate, type, av_price, h_price, l_price, c_price, volume);
- }
-}
diff --git a/src/main/java/cryptosky/me/graphql/query/BtcPriceQuery.java b/src/main/java/cryptosky/me/graphql/query/BtcPriceQuery.java
new file mode 100644
index 0000000..972d852
--- /dev/null
+++ b/src/main/java/cryptosky/me/graphql/query/BtcPriceQuery.java
@@ -0,0 +1,39 @@
+package cryptosky.me.graphql.query;
+
+import com.coxautodev.graphql.tools.GraphQLQueryResolver;
+import cryptosky.me.graphql.jpa.entity.BtcPriceModel;
+import cryptosky.me.graphql.jpa.entity.CryptoPriceModel;
+import cryptosky.me.graphql.service.BtcPriceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.time.OffsetDateTime;
+import java.util.List;
+import java.util.Optional;
+
+@Component
+public class BtcPriceQuery implements GraphQLQueryResolver {
+
+ @Autowired
+ private BtcPriceService btcPriceService;
+
+ public List getAllPrices( final int count ) {
+ return this.btcPriceService.getAllPrices(count);
+ }
+
+ public List getPricesBetweenCounts( final int startCount, final int endCount ) {
+ return this.btcPriceService.getPricesBetweenCounts(startCount, endCount);
+ }
+
+ public Optional getLatest() {
+ return this.btcPriceService.getLatest();
+ }
+
+ public Optional getPriceForCreatedDate( final String createdDate ) {
+ return this.btcPriceService.getPriceForCreatedDate(createdDate);
+ }
+
+ public List getPriceBetweenDates(final String startDate, final String endDate ) {
+ return this.btcPriceService.getPriceBetweenDates(startDate, endDate);
+ }
+}
diff --git a/src/main/java/cryptosky/me/graphql/query/CryptoPriceQuery.java b/src/main/java/cryptosky/me/graphql/query/CryptoPriceQuery.java
deleted file mode 100644
index d26be42..0000000
--- a/src/main/java/cryptosky/me/graphql/query/CryptoPriceQuery.java
+++ /dev/null
@@ -1,46 +0,0 @@
-package cryptosky.me.graphql.query;
-
-import com.coxautodev.graphql.tools.GraphQLQueryResolver;
-import cryptosky.me.graphql.jpa.entity.CryptoPrice;
-import cryptosky.me.graphql.service.CryptoPriceService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-import java.util.Optional;
-
-@Component
-public class CryptoPriceQuery implements GraphQLQueryResolver {
-
- @Autowired
- private CryptoPriceService cryptoPriceService;
-
- public List getAllPrices(final int count) {
- return this.cryptoPriceService.getAllPrices(count);
- }
-
- public List getLimitPricesByType( final int count, final String type ) {
- return this.cryptoPriceService.getLimitPricesByType(count, type);
- }
-
- public List getAllByType( final String type ) {
- return this.cryptoPriceService.getAllByType(type);
- }
-
- public Optional getLatestByType( final String type ) {
- return this.cryptoPriceService.getLatestByType(type);
- }
-
- public List getAllLatest() {
- return this.cryptoPriceService.getAllLatest();
- }
-
- public Optional getPriceByCreatedDateForType( final String type, final String createdDate ) {
- return this.cryptoPriceService.getPriceByCreatedDateForType(type, createdDate);
- }
-
- public Optional getPriceBetweenCreatedDatesForType( final String type, final String startDate, final String endDate ) {
- return this.cryptoPriceService.getPriceBetweenCreatedDatesForType(type, startDate, endDate);
- }
-
-}
diff --git a/src/main/java/cryptosky/me/graphql/service/BtcPriceService.java b/src/main/java/cryptosky/me/graphql/service/BtcPriceService.java
new file mode 100644
index 0000000..2027def
--- /dev/null
+++ b/src/main/java/cryptosky/me/graphql/service/BtcPriceService.java
@@ -0,0 +1,125 @@
+package cryptosky.me.graphql.service;
+
+import cryptosky.me.graphql.jpa.entity.BtcPriceModel;
+import cryptosky.me.graphql.jpa.repository.BtcPriceRepository;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static cryptosky.me.helpers.Utils.distinctByKey;
+
+@Service
+public class BtcPriceService {
+
+ private final BtcPriceRepository btcPriceRepository;
+
+ DateTimeFormatter format = DateTimeFormatter.ISO_DATE_TIME;//ofPattern("dd-MM-yy HH:mm");
+
+ public BtcPriceService(final BtcPriceRepository btcPriceRepository) {
+ this.btcPriceRepository = btcPriceRepository;
+ }
+
+ @Transactional
+ public BtcPriceModel createBtc(final String createdDate, final String type, final float av_price,
+ final float h_price, final float l_price, final float c_price, final float volume ) {
+
+ final BtcPriceModel btcPrice = new BtcPriceModel();
+ btcPrice.setTimestamp(LocalDate.parse(createdDate, format).toString());
+ btcPrice.setType(type);
+ btcPrice.setAverage_price(av_price);
+ btcPrice.setHigh_price(h_price);
+ btcPrice.setLow_price(l_price);
+ btcPrice.setClose_price(c_price);
+ btcPrice.setVolume(volume);
+
+
+ return this.btcPriceRepository.save(btcPrice);
+ }
+
+ @Transactional(readOnly = true)
+ public List getAllPrices( final int count ) {
+ return this.btcPriceRepository.findAll().stream()
+ .limit(count)
+ .collect(Collectors.toList());
+ }
+
+ @Transactional(readOnly = true)
+ public List getPricesBetweenCounts( final int startCount, final int endCount ) {
+ return this.btcPriceRepository.findAll().stream()
+ .skip(startCount)
+ .limit(endCount - startCount)
+ .collect(Collectors.toList());
+ }
+
+ @Transactional(readOnly = true)
+ public Optional getLatest() {
+ return this.btcPriceRepository.findAll().stream().findFirst();
+ }
+
+ @Transactional(readOnly = true)
+ public Optional getPriceForCreatedDate( final String createdDate ) {
+ return this.btcPriceRepository.findAll().stream()
+ .filter(createdDateList -> createdDateList.getTimestamp().equals(LocalDate.parse(createdDate, format)))
+ .findFirst();
+ }
+
+ @Transactional(readOnly = true)
+ public List getPriceBetweenDates( final String startDate, final String endDate ) {
+ return this.btcPriceRepository.findAll().stream()
+ .filter(createdDateList -> LocalDate.parse(createdDateList.getTimestamp(), format).isBefore(LocalDate.parse(endDate, format)))
+ .filter(createdDateList -> LocalDate.parse(createdDateList.getTimestamp(), format).isAfter(LocalDate.parse(startDate, format)))
+ .collect(Collectors.toList());
+ }
+
+// @Transactional(readOnly = true)
+// public List getAllLatest() {
+// return this.btcPriceRepository.findAll().stream()
+// .filter(distinctByKey(CryptoPriceModel::getType))
+// .collect(Collectors.toList());
+// }
+
+// @Transactional(readOnly = true)
+// public List getLimitPricesByType(final int count, final String type ) {
+// return this.btcPriceRepository.findAll().stream()
+// .filter(typeList -> typeList.getType().equals(type))
+// .limit(count)
+// .collect(Collectors.toList());
+// }
+
+// @Transactional(readOnly = true)
+// public List getAllByType(final String type ) {
+// return this.btcPriceRepository.findAll().stream()
+// .filter(typeList -> typeList.getType().equals(type))
+// .collect(Collectors.toList());
+// }
+
+// @Transactional(readOnly = true)
+// public Optional getLatestByType(final String type ) {
+// return this.cryptoPriceRepository.findAll().stream()
+// .filter(typeList -> typeList.getType().equals(type))
+// .limit(1)
+// .findFirst();
+// }
+
+// @Transactional(readOnly = true)
+// public Optional getPriceByCreatedDateForType( final String type, final String createdDate ) {
+// return this.cryptoPriceRepository.findAll().stream()
+// .filter(typeList -> typeList.getType().equals(type))
+// .filter(createdDateList -> createdDateList.getTimestamp().equals(LocalDate.parse(createdDate)))
+// .findFirst();
+// }
+//
+// @Transactional(readOnly = true)
+// public Optional getPriceBetweenCreatedDatesForType( final String type, final String startDate, final String endDate ) {
+// return this.cryptoPriceRepository.findAll().stream()
+// .filter(typeList -> typeList.getType().equals(type))
+// .filter(createdDateList -> createdDateList.getTimestamp().isBefore(LocalDate.parse(endDate)))
+// .filter(createdDateList -> createdDateList.getTimestamp().isAfter(LocalDate.parse(startDate)))
+// .findFirst();
+// }
+}
diff --git a/src/main/java/cryptosky/me/graphql/service/CryptoPriceService.java b/src/main/java/cryptosky/me/graphql/service/CryptoPriceService.java
deleted file mode 100644
index 9eccff0..0000000
--- a/src/main/java/cryptosky/me/graphql/service/CryptoPriceService.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package cryptosky.me.graphql.service;
-
-import cryptosky.me.graphql.jpa.entity.BtcPrice;
-import cryptosky.me.graphql.jpa.entity.CryptoPrice;
-import cryptosky.me.graphql.jpa.repository.CryptoPriceRepository;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.time.LocalDate;
-import java.time.format.DateTimeFormatter;
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import static cryptosky.me.helpers.functionalMapping.distinctByKey;
-
-@Service
-public class CryptoPriceService {
-
- private final CryptoPriceRepository cryptoPriceRepository;
-
- DateTimeFormatter format = DateTimeFormatter.ofPattern("dd-MM-yy");
-
- public CryptoPriceService( final CryptoPriceRepository cryptoPriceRepository ) {
- this.cryptoPriceRepository = cryptoPriceRepository;
- }
-
- @Transactional
- public BtcPrice createBtc(final String createdDate, final String type, final float av_price,
- final float h_price, final float l_price, final float c_price, final float volume ) {
-
- final BtcPrice btcPrice = new BtcPrice();
- btcPrice.setTimestamp(LocalDate.parse(createdDate, format));
- btcPrice.setAverage_price(av_price);
- btcPrice.setType(type);
- btcPrice.setHigh_price(h_price);
- btcPrice.setLow_price(l_price);
- btcPrice.setClose_price(c_price);
- btcPrice.setVolume(volume);
-
- return this.cryptoPriceRepository.save(btcPrice);
- }
-
-// @Transactional
-// public CryptoPrice createPrice(final String createdDate, final String type, final float av_price,
-// final float h_price, final float l_price, final float c_price, final float volume ) {
-//
-// final CryptoPrice cryptoPrice = CryptoPrice.builder()
-// .timestamp(LocalDate.parse(createdDate, format))
-// .type(type)
-// .average_price(av_price)
-// .high_price(h_price)
-// .low_price(l_price)
-// .close_price(c_price)
-// .volume(volume)
-// .build();
-//
-// return this.cryptoPriceRepository.save(cryptoPrice);
-// }
-
- @Transactional(readOnly = true)
- public List getAllPrices( final int count ) {
- return this.cryptoPriceRepository.findAll().stream()
- .limit(count)
- .collect(Collectors.toList());
- }
-
- @Transactional(readOnly = true)
- public List getLimitPricesByType( final int count, final String type ) {
- return this.cryptoPriceRepository.findAll().stream()
- .filter(typeList -> typeList.getType().equals(type))
- .limit(count)
- .collect(Collectors.toList());
- }
-
- @Transactional(readOnly = true)
- public List getAllByType( final String type ) {
- return this.cryptoPriceRepository.findAll().stream()
- .filter(typeList -> typeList.getType().equals(type))
- .collect(Collectors.toList());
- }
-
- @Transactional(readOnly = true)
- public Optional getLatestByType( final String type ) {
- return this.cryptoPriceRepository.findAll().stream()
- .filter(typeList -> typeList.getType().equals(type))
- .limit(1)
- .findFirst();
- }
-
- @Transactional(readOnly = true)
- public List getAllLatest() {
- return this.cryptoPriceRepository.findAll().stream()
- .filter(distinctByKey(CryptoPrice::getType))
- .collect(Collectors.toList());
- }
-
- @Transactional(readOnly = true)
- public Optional getPriceByCreatedDateForType( final String type, final String createdDate ) {
- return this.cryptoPriceRepository.findAll().stream()
- .filter(typeList -> typeList.getType().equals(type))
- .filter(createdDateList -> createdDateList.getTimestamp().equals(LocalDate.parse(createdDate)))
- .findFirst();
- }
-
- @Transactional(readOnly = true)
- public Optional getPriceBetweenCreatedDatesForType( final String type, final String startDate, final String endDate ) {
- return this.cryptoPriceRepository.findAll().stream()
- .filter(typeList -> typeList.getType().equals(type))
- .filter(createdDateList -> createdDateList.getTimestamp().isBefore(LocalDate.parse(endDate)))
- .filter(createdDateList -> createdDateList.getTimestamp().isAfter(LocalDate.parse(startDate)))
- .findFirst();
- }
-}
diff --git a/src/main/java/cryptosky/me/helpers/functionalMapping.java b/src/main/java/cryptosky/me/helpers/Utils.java
similarity index 84%
rename from src/main/java/cryptosky/me/helpers/functionalMapping.java
rename to src/main/java/cryptosky/me/helpers/Utils.java
index d4162e5..5341c4e 100644
--- a/src/main/java/cryptosky/me/helpers/functionalMapping.java
+++ b/src/main/java/cryptosky/me/helpers/Utils.java
@@ -5,8 +5,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
-public class functionalMapping {
+public class Utils {
+ // Utility Function to be able to get one of all types
public static Predicate distinctByKey(Function super T, Object> keyExtractor) {
Map