[07.02.20] Tweet extension to BTC
This commit is contained in:
parent
b0cf186f61
commit
1fa031cb73
@ -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;
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
}
|
||||
@ -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<TweetModel, Integer> {
|
||||
public interface BtcTweetRepository extends JpaRepository<BtcTweetModel, Integer> {
|
||||
}
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
@ -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<BtcTweetModel> getCurrentTweet() {
|
||||
return this.btcTweetService.getCurrentTweet();
|
||||
}
|
||||
|
||||
public List<BtcTweetModel> getAllTweets( final int count ) {
|
||||
return this.btcTweetService.getAllTweets(count);
|
||||
}
|
||||
|
||||
public List<BtcTweetModel> getTweetsForDay( final String startDate, final String endDate ) {
|
||||
return this.btcTweetService.getTweetsForDay(startDate, endDate);
|
||||
}
|
||||
|
||||
public List<BtcTweetModel> getTweetsForPeriod( final String startDate, final String endDate ) {
|
||||
return this.btcTweetService.getTweetsForPeriod( startDate, endDate );
|
||||
}
|
||||
}
|
||||
@ -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<TweetModel> getCurrentTweet() {
|
||||
return this.tweetService.getCurrentTweet();
|
||||
}
|
||||
|
||||
public List<TweetModel> getAllTweets( final int count ) {
|
||||
return this.tweetService.getAllTweets(count);
|
||||
}
|
||||
|
||||
public List<TweetModel> getTweetsForDay( final String startDate, final String endDate ) {
|
||||
return this.tweetService.getTweetsForDay(startDate, endDate);
|
||||
}
|
||||
|
||||
public List<TweetModel> getTweetsForPeriod( final String startDate, final String endDate ) {
|
||||
return this.tweetService.getTweetsForPeriod( startDate, endDate );
|
||||
}
|
||||
}
|
||||
@ -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<TweetModel> getCurrentTweet() {
|
||||
return this.tweetRepository.findAll().stream().findFirst();
|
||||
public Optional<BtcTweetModel> getCurrentTweet() {
|
||||
return this.btcTweetRepository.findAll().stream().findFirst();
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<TweetModel> getAllTweets( final int count ) {
|
||||
return this.tweetRepository.findAll().stream()
|
||||
public List<BtcTweetModel> getAllTweets( final int count ) {
|
||||
return this.btcTweetRepository.findAll().stream()
|
||||
.limit(count)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
public List<TweetModel> getTweetsForDay( final String startDate, final String endDate ) {
|
||||
public List<BtcTweetModel> 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<TweetModel> getTweetsForPeriod( final String startDate, final String endDate ) {
|
||||
public List<BtcTweetModel> 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());
|
||||
Loading…
x
Reference in New Issue
Block a user