Commit 0c445d9c by jhrabal

WIP

parent aad7e508
package com.jh.rateit.api;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
@Controller
@RequestMapping("/api")
public class RatingApiController {
@RequestMapping(path = "ratings", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public void bulkRating() {
}
}
......@@ -2,19 +2,62 @@ package com.jh.rateit.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.jh.common.jpa.AbstractIdEntity;
@Entity
@Table(name = "RATING")
public class Rating extends AbstractIdEntity {
@Column(name = "DEVICE_ID")
private String deviceId;
@Column(name = "CREATED")
private Date created;
@Column(name = "RATING")
private Integer rating;
@Transient
private Section section;
public Rating() {
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Integer getRating() {
return rating;
}
public void setRating(Integer rating) {
this.rating = rating;
}
public Section getSection() {
return section;
}
public void setSection(Section section) {
this.section = section;
}
}
package com.jh.rateit.rating;
import java.util.Collection;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;
import com.jh.common.jpa.AbstractHibernateRepository;
import com.jh.rateit.model.Rating;
@Repository
public class RatingRepository extends AbstractHibernateRepository {
public void saveBulk(Collection<Rating> ratings) {
Session session = getSession();
//TODO implement properly
}
}
......@@ -17,7 +17,7 @@ public class RatingService {
@Transactional
public void saveBulk(Collection<Rating> ratings) {
repo.saveBulk(ratings);
}
}
#Generated by Maven Integration for Eclipse
#Sat Jun 29 08:55:48 CEST 2019
#Mon Jul 08 09:32:30 CEST 2019
version=0.0.1
groupId=com.jh
m2e.projectName=radegast
......
......@@ -2,24 +2,10 @@ import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, AsyncStorage, Alert, StatusBar } from 'react-native';
const sendData = async () => {
try {
let response = await fetch('https://radegast.janhrabal.com', {
method: "POST"
});
let responseJson = await response.json();
return responseJson.movies;
} catch (error) {
console.error(error);
}
}
const SEND_DATA_TIMER = 10000;
const INFO_TIMER = 1500;
const storeRating = async (rating) => {
let key = new Date().getTime();
await AsyncStorage.setItem(JSON.stringify(key), JSON.stringify({
rating
}));
}
class App extends React.PureComponent {
......@@ -29,16 +15,54 @@ class App extends React.PureComponent {
this.state = {
mode: 'rating',
stats: {},
statsLoading: false
statsLoading: false,
buffer: []
};
this.sendData = this.sendData.bind(this);
this.onPress = this.onPress.bind(this);
}
componentDidMount() {
//this.timer = setInterval(sendData, 10000);
this.timer = setTimeout(this.sendData, SEND_DATA_TIMER);
}
componentWillUnmount() {
//clearInterval(this.timer);
if (this.timer) {
clearTimeout(this.timer);
}
}
async sendData() {
let { buffer } = this.state;
let body = [];
//prepare body
while (buffer.length) {
body.push(buffer.shift());
}
try {
let response = await fetch('https://radegast.janhrabal.com/api/ratings/bulk', {
method: "POST",
body: JSON.stringify(body)
});
let responseJson = await response.json();
return responseJson.movies;
} catch (error) {
//console.error(error);
// return to buffer
while (body.length) {
buffer.push(body.shift());
}
}
//set other timeout
this.timer = setTimeout(this.sendData, SEND_DATA_TIMER);
}
......@@ -64,18 +88,20 @@ class App extends React.PureComponent {
}
onPress(rating) {
onPress(r) {
return async () => {
let { buffer } = this.state;
let key = new Date().getTime();
let rating = { rating: r, key };
try {
this.setState({ mode: "info" });
await storeRating(rating);
setTimeout(() => this.setState({ mode: "rating" }), 2000);
await AsyncStorage.setItem(JSON.stringify(key), JSON.stringify(rating));
// TODO
let keys = await AsyncStorage.getAllKeys();
let s = keys.join(",\n");
//add to buffer
buffer.push(rating);
Alert.alert("stats", s);
setTimeout(() => this.setState({ mode: "rating" }), INFO_TIMER);
} catch (e) {
console.error(e);
......@@ -86,12 +112,12 @@ class App extends React.PureComponent {
renderResults() {
return null;
return <View></View>
}
renderInfo() {
return <Text>XXX</Text>;
return <View><Text>Děkujeme za hodnocení</Text></View>
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment