From 1fa031cb7382431b2a878672d1c6079677119499 Mon Sep 17 00:00:00 2001 From: andyjk15 Date: Fri, 7 Feb 2020 22:59:21 +0000 Subject: [PATCH] [07.02.20] Tweet extension to BTC --- .../repositories/BtcPriceRepository.java | 1 + .../tweets/models/entities/BtcTweetModel.java | 15 ++++++ ...epository.java => BtcTweetRepository.java} | 4 +- .../tweets/mutations/BtcTweetMutation.java | 22 ++++++++ .../tweets/mutations/TweetMutation.java | 22 -------- .../graphql/tweets/queries/BtcTweetQuery.java | 33 ++++++++++++ .../me/graphql/tweets/queries/TweetQuery.java | 33 ------------ ...TweetService.java => BtcTweetService.java} | 52 +++++++++---------- 8 files changed, 99 insertions(+), 83 deletions(-) create mode 100644 src/main/java/cryptosky/me/graphql/tweets/models/entities/BtcTweetModel.java rename src/main/java/cryptosky/me/graphql/tweets/models/repositories/{TweetRepository.java => BtcTweetRepository.java} (55%) create mode 100644 src/main/java/cryptosky/me/graphql/tweets/mutations/BtcTweetMutation.java delete mode 100644 src/main/java/cryptosky/me/graphql/tweets/mutations/TweetMutation.java create mode 100644 src/main/java/cryptosky/me/graphql/tweets/queries/BtcTweetQuery.java delete mode 100644 src/main/java/cryptosky/me/graphql/tweets/queries/TweetQuery.java rename src/main/java/cryptosky/me/graphql/tweets/service/{TweetService.java => BtcTweetService.java} (60%) diff --git a/src/main/java/cryptosky/me/graphql/pricing/models/repositories/BtcPriceRepository.java b/src/main/java/cryptosky/me/graphql/pricing/models/repositories/BtcPriceRepository.java index 7f6d05d..8aec689 100644 --- a/src/main/java/cryptosky/me/graphql/pricing/models/repositories/BtcPriceRepository.java +++ b/src/main/java/cryptosky/me/graphql/pricing/models/repositories/BtcPriceRepository.java @@ -1,6 +1,7 @@ package cryptosky.me.graphql.pricing.models.repositories; import cryptosky.me.graphql.pricing.models.entities.BtcPriceModel; +import org.springframework.context.annotation.PropertySource; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/cryptosky/me/graphql/tweets/models/entities/BtcTweetModel.java b/src/main/java/cryptosky/me/graphql/tweets/models/entities/BtcTweetModel.java new file mode 100644 index 0000000..747a37d --- /dev/null +++ b/src/main/java/cryptosky/me/graphql/tweets/models/entities/BtcTweetModel.java @@ -0,0 +1,15 @@ +package cryptosky.me.graphql.tweets.models.entities; + +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 BtcTweetModel extends TweetModel { + +} diff --git a/src/main/java/cryptosky/me/graphql/tweets/models/repositories/TweetRepository.java b/src/main/java/cryptosky/me/graphql/tweets/models/repositories/BtcTweetRepository.java similarity index 55% rename from src/main/java/cryptosky/me/graphql/tweets/models/repositories/TweetRepository.java rename to src/main/java/cryptosky/me/graphql/tweets/models/repositories/BtcTweetRepository.java index d15f861..6e4c074 100644 --- a/src/main/java/cryptosky/me/graphql/tweets/models/repositories/TweetRepository.java +++ b/src/main/java/cryptosky/me/graphql/tweets/models/repositories/BtcTweetRepository.java @@ -1,9 +1,9 @@ package cryptosky.me.graphql.tweets.models.repositories; -import cryptosky.me.graphql.tweets.models.entities.TweetModel; +import cryptosky.me.graphql.tweets.models.entities.BtcTweetModel; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository -public interface TweetRepository extends JpaRepository { +public interface BtcTweetRepository extends JpaRepository { } diff --git a/src/main/java/cryptosky/me/graphql/tweets/mutations/BtcTweetMutation.java b/src/main/java/cryptosky/me/graphql/tweets/mutations/BtcTweetMutation.java new file mode 100644 index 0000000..7dbb6d3 --- /dev/null +++ b/src/main/java/cryptosky/me/graphql/tweets/mutations/BtcTweetMutation.java @@ -0,0 +1,22 @@ +package cryptosky.me.graphql.tweets.mutations; + +import com.coxautodev.graphql.tools.GraphQLMutationResolver; +import cryptosky.me.graphql.tweets.models.entities.BtcTweetModel; +import cryptosky.me.graphql.tweets.service.BtcTweetService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class BtcTweetMutation implements GraphQLMutationResolver { + + @Autowired + BtcTweetService btcTweetService; + + public BtcTweetModel createTweet(final String createdDate, final String rawTweet, final float sentimentScore, + final float positiveScore, final float neutralScore, final float negativeScore, + final float compoundScore ) { + return this.btcTweetService.createTweet( createdDate, rawTweet, sentimentScore, positiveScore, neutralScore, + negativeScore,compoundScore ); + } + +} diff --git a/src/main/java/cryptosky/me/graphql/tweets/mutations/TweetMutation.java b/src/main/java/cryptosky/me/graphql/tweets/mutations/TweetMutation.java deleted file mode 100644 index 1cde3d3..0000000 --- a/src/main/java/cryptosky/me/graphql/tweets/mutations/TweetMutation.java +++ /dev/null @@ -1,22 +0,0 @@ -package cryptosky.me.graphql.tweets.mutations; - -import com.coxautodev.graphql.tools.GraphQLMutationResolver; -import cryptosky.me.graphql.tweets.models.entities.TweetModel; -import cryptosky.me.graphql.tweets.service.TweetService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class TweetMutation implements GraphQLMutationResolver { - - @Autowired - TweetService tweetService; - - public TweetModel createTweet( final String createdDate, final String rawTweet, final float sentimentScore, - final float positiveScore, final float neutralScore, final float negativeScore, - final float compoundScore ) { - return this.tweetService.createTweet( createdDate, rawTweet, sentimentScore, positiveScore, neutralScore, - negativeScore,compoundScore ); - } - -} diff --git a/src/main/java/cryptosky/me/graphql/tweets/queries/BtcTweetQuery.java b/src/main/java/cryptosky/me/graphql/tweets/queries/BtcTweetQuery.java new file mode 100644 index 0000000..013634c --- /dev/null +++ b/src/main/java/cryptosky/me/graphql/tweets/queries/BtcTweetQuery.java @@ -0,0 +1,33 @@ +package cryptosky.me.graphql.tweets.queries; + +import com.coxautodev.graphql.tools.GraphQLQueryResolver; +import cryptosky.me.graphql.tweets.models.entities.BtcTweetModel; +import cryptosky.me.graphql.tweets.service.BtcTweetService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class BtcTweetQuery implements GraphQLQueryResolver { + + @Autowired + private BtcTweetService btcTweetService; + + public Optional getCurrentTweet() { + return this.btcTweetService.getCurrentTweet(); + } + + public List getAllTweets( final int count ) { + return this.btcTweetService.getAllTweets(count); + } + + public List getTweetsForDay( final String startDate, final String endDate ) { + return this.btcTweetService.getTweetsForDay(startDate, endDate); + } + + public List getTweetsForPeriod( final String startDate, final String endDate ) { + return this.btcTweetService.getTweetsForPeriod( startDate, endDate ); + } +} diff --git a/src/main/java/cryptosky/me/graphql/tweets/queries/TweetQuery.java b/src/main/java/cryptosky/me/graphql/tweets/queries/TweetQuery.java deleted file mode 100644 index 1152fdb..0000000 --- a/src/main/java/cryptosky/me/graphql/tweets/queries/TweetQuery.java +++ /dev/null @@ -1,33 +0,0 @@ -package cryptosky.me.graphql.tweets.queries; - -import com.coxautodev.graphql.tools.GraphQLQueryResolver; -import cryptosky.me.graphql.tweets.models.entities.TweetModel; -import cryptosky.me.graphql.tweets.service.TweetService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import java.util.List; -import java.util.Optional; - -@Component -public class TweetQuery implements GraphQLQueryResolver { - - @Autowired - private TweetService tweetService; - - public Optional getCurrentTweet() { - return this.tweetService.getCurrentTweet(); - } - - public List getAllTweets( final int count ) { - return this.tweetService.getAllTweets(count); - } - - public List getTweetsForDay( final String startDate, final String endDate ) { - return this.tweetService.getTweetsForDay(startDate, endDate); - } - - public List getTweetsForPeriod( final String startDate, final String endDate ) { - return this.tweetService.getTweetsForPeriod( startDate, endDate ); - } -} diff --git a/src/main/java/cryptosky/me/graphql/tweets/service/TweetService.java b/src/main/java/cryptosky/me/graphql/tweets/service/BtcTweetService.java similarity index 60% rename from src/main/java/cryptosky/me/graphql/tweets/service/TweetService.java rename to src/main/java/cryptosky/me/graphql/tweets/service/BtcTweetService.java index b2b6de0..6533bcf 100644 --- a/src/main/java/cryptosky/me/graphql/tweets/service/TweetService.java +++ b/src/main/java/cryptosky/me/graphql/tweets/service/BtcTweetService.java @@ -1,7 +1,8 @@ package cryptosky.me.graphql.tweets.service; +import cryptosky.me.graphql.tweets.models.entities.BtcTweetModel; import cryptosky.me.graphql.tweets.models.entities.TweetModel; -import cryptosky.me.graphql.tweets.models.repositories.TweetRepository; +import cryptosky.me.graphql.tweets.models.repositories.BtcTweetRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,46 +16,45 @@ import java.util.stream.Collectors; import static cryptosky.me.helpers.Utils.format; @Service -public class TweetService { +public class BtcTweetService { - private final TweetRepository tweetRepository; + private final BtcTweetRepository btcTweetRepository; - public TweetService( final TweetRepository tweetRepository ) { - this.tweetRepository = tweetRepository; + public BtcTweetService(final BtcTweetRepository btcTweetRepository) { + this.btcTweetRepository = btcTweetRepository; } @Transactional - public TweetModel createTweet( final String createdDate, final String rawTweet, final float sentimentScore, - final float positiveScore, final float neutralScore, final float negativeScore, - final float compoundScore ) { + public BtcTweetModel createTweet(final String createdDate, final String rawTweet, final float sentimentScore, + final float positiveScore, final float neutralScore, final float negativeScore, + final float compoundScore ) { - final TweetModel tweetModel = TweetModel.builder() - .timestamp(format(createdDate).toString()) - .rawTweet(rawTweet) - .sentimentScore(sentimentScore) - .positiveScore(positiveScore) - .negativeScore(negativeScore) - .neutralScore(neutralScore) - .compoundScore(compoundScore) - .build(); + final BtcTweetModel tweetModel = new BtcTweetModel(); + tweetModel.setTimestamp(format(createdDate).toString()); + tweetModel.setRawTweet(rawTweet); + tweetModel.setSentimentScore(sentimentScore); + tweetModel.setPositiveScore(positiveScore); + tweetModel.setNegativeScore(negativeScore); + tweetModel.setNeutralScore(neutralScore); + tweetModel.setCompoundScore(compoundScore); - return this.tweetRepository.save(tweetModel); + return this.btcTweetRepository.save(tweetModel); } @Transactional(readOnly = true) - public Optional getCurrentTweet() { - return this.tweetRepository.findAll().stream().findFirst(); + public Optional getCurrentTweet() { + return this.btcTweetRepository.findAll().stream().findFirst(); } @Transactional(readOnly = true) - public List getAllTweets( final int count ) { - return this.tweetRepository.findAll().stream() + public List getAllTweets( final int count ) { + return this.btcTweetRepository.findAll().stream() .limit(count) .collect(Collectors.toList()); } @Transactional(readOnly = true) - public List getTweetsForDay( final String startDate, final String endDate ) { + public List getTweetsForDay( final String startDate, final String endDate ) { LocalDateTime r_start = format(startDate); LocalDateTime r_end = format(endDate); @@ -65,7 +65,7 @@ public class TweetService { if ( r_end.equals(r_start.toLocalDate().atTime(LocalTime.MAX))) { LocalDateTime finalR_end = r_end; LocalDateTime finalR_start = r_start; - return this.tweetRepository.findAll().stream() + return this.btcTweetRepository.findAll().stream() .filter(createdDateList -> format(createdDateList.getTimestamp()).isBefore(finalR_end)) .filter(createdDateList -> format(createdDateList.getTimestamp()).isAfter(finalR_start)) .collect(Collectors.toList()); @@ -80,7 +80,7 @@ public class TweetService { } @Transactional(readOnly = true) - public List getTweetsForPeriod( final String startDate, final String endDate ) { + public List getTweetsForPeriod( final String startDate, final String endDate ) { LocalDateTime r_start = format(startDate); LocalDateTime r_end = format(endDate); @@ -90,7 +90,7 @@ public class TweetService { if ( r_end.isAfter(r_start) ) { LocalDateTime finalR_end = r_end; LocalDateTime finalR_start = r_start; - return this.tweetRepository.findAll().stream() + return this.btcTweetRepository.findAll().stream() .filter(createdDateList -> format(createdDateList.getTimestamp()).isBefore(finalR_end)) .filter(createdDateList -> format(createdDateList.getTimestamp()).isAfter(finalR_start)) .collect(Collectors.toList());