Commit c4eb8a00 authored by Sebastian Trebunak's avatar Sebastian Trebunak
Browse files

Merge branch 'master' of git.kpi.fei.tuke.sk:patrik.sakac/atvi2

parents 0b1ab12f 8167ae5b
......@@ -18,11 +18,12 @@ public class BankBranchEndpoint {
public BankBranch get(@PathVariable Long id) { return repository.getBankBranch(id); }
@GetMapping(value = "/")
public List<BankBranch> get() { return repository.getAllBankBranchs(); }
public List<BankBranch> getAll() { return repository.getAllBankBranchs(); }
@PostMapping(value = "/create")
public void create(@RequestBody BankBranch bankBranch) {
repository.createBankBranch(bankBranch); }
repository.createBankBranch(bankBranch);
}
@DeleteMapping(value = "/delete/{id}")
public boolean delete(@PathVariable Long id) { return repository.deleteBankBranch(id); }
......
package com.tuke.fei.atvi2.api.endpoint;
import com.tuke.fei.atvi2.api.entity.RobberyEvent;
import com.tuke.fei.atvi2.api.repository.RobberyEventRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("robbery-event")
public class RobberyEventEndpoint {
@Autowired
RobberyEventRepository repository;
@GetMapping("/all/{limit}")
public List<RobberyEvent> getAll(@PathVariable Integer limit) {
return repository.getAll(limit);
}
@GetMapping("/{branchId}/{limit}")
public List<RobberyEvent> getAllByBranchId(@PathVariable Long branchId, @PathVariable Integer limit) {
return repository.getAllByBranchId(branchId, limit);
}
@PostMapping(value = "/create")
public boolean create(@RequestBody RobberyEvent robberyEvent) {
return repository.create(robberyEvent);
}
}
......@@ -11,6 +11,9 @@ public class BankBranch {
private String city;
private String lat;
private String lon;
public Long getId() {
return id;
......@@ -43,4 +46,20 @@ public class BankBranch {
public void setCity(String city) {
this.city = city;
}
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLon() {
return lon;
}
public void setLon(String lon) {
this.lon = lon;
}
}
package com.tuke.fei.atvi2.api.entity;
import java.sql.Timestamp;
public class RobberyEvent {
private Long id;
private BankBranch bankBranch;
private Timestamp timestamp;
private Integer rate;
private Integer audioMatch;
private Integer videoMatch;
private String audioUri;
private String videoUri;
private String keywords;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public BankBranch getBankBranch() {
return bankBranch;
}
public void setBankBranch(BankBranch bankBranch) {
this.bankBranch = bankBranch;
}
public Timestamp getTimestamp() {
return timestamp;
}
public void setTimestamp(Timestamp timestamp) {
this.timestamp = timestamp;
}
public Integer getRate() {
return rate;
}
public void setRate(Integer rate) {
this.rate = rate;
}
public Integer getAudioMatch() {
return audioMatch;
}
public void setAudioMatch(Integer audioMatch) {
this.audioMatch = audioMatch;
}
public Integer getVideoMatch() {
return videoMatch;
}
public void setVideoMatch(Integer videoMatch) {
this.videoMatch = videoMatch;
}
public String getAudioUri() {
return audioUri;
}
public void setAudioUri(String audioUri) {
this.audioUri = audioUri;
}
public String getVideoUri() {
return videoUri;
}
public void setVideoUri(String videoUri) {
this.videoUri = videoUri;
}
public String getKeywords() {
return keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
}
package com.tuke.fei.atvi2.api.repository;
import com.tuke.fei.atvi2.api.entity.BankBranch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class BankBranchRepository {
@Autowired
JdbcTemplate jdbcTemplate;
public interface BankBranchRepository {
public BankBranch getBankBranch(Long id) {
final String sql = "SELECT * FROM [bank_branch] WHERE id = ?";
try{
return (BankBranch) jdbcTemplate.queryForObject(sql, new Object[] {id}, new BeanPropertyRowMapper(BankBranch.class));
} catch (EmptyResultDataAccessException e) {
return null;
}
}
BankBranch getBankBranch(Long id);
public List<BankBranch> getAllBankBranchs() {
final String sql = "SELECT * FROM [bank_branch]";
return jdbcTemplate.query(sql, new BeanPropertyRowMapper(BankBranch.class));
}
List<BankBranch> getAllBankBranchs();
public void createBankBranch(BankBranch bankBranch) {
final String sql = "INSERT INTO [bank_branch] (address, zip, city) VALUES (?, ?, ?)";
jdbcTemplate.update(sql, bankBranch.getAddress(), bankBranch.getZip(), bankBranch.getCity());
}
void createBankBranch(BankBranch bankBranch);
public boolean deleteBankBranch(Long id) {
final String sql = "DELETE FROM [bank_branch] WHERE id = ?";
return jdbcTemplate.update(sql, id) == 1;
}
boolean deleteBankBranch(Long id);
}
package com.tuke.fei.atvi2.api.repository;
import com.tuke.fei.atvi2.api.entity.RobberyEvent;
import java.util.List;
public interface RobberyEventRepository {
List<RobberyEvent> getAll(Integer limit);
List<RobberyEvent> getAllByBranchId(Long branchId, Integer limit);
boolean create(RobberyEvent robberyEvent);
}
package com.tuke.fei.atvi2.api.repository.impl.sql;
import com.tuke.fei.atvi2.api.entity.BankBranch;
import com.tuke.fei.atvi2.api.repository.BankBranchRepository;
import com.tuke.fei.atvi2.api.repository.impl.sql.rowmapper.BankBranchRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class SQLBankBranchRepository implements BankBranchRepository {
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public BankBranch getBankBranch(Long id) {
final String sql = "SELECT " +
"[bank_branch].[id] AS [id_bb], " +
"[bank_branch].[address] AS [address_bb], " +
"[bank_branch].[city] AS [city_bb], " +
"[bank_branch].[zip] AS [zip_bb], " +
"[bank_branch].[lat] AS [lat_bb], " +
"[bank_branch].[lon] AS [lon_bb] " +
"FROM [bank_branch] WHERE id = ?";
try{
return jdbcTemplate.queryForObject(sql, new Object[] {id}, new BankBranchRowMapper());
} catch (EmptyResultDataAccessException e) {
return null;
}
}
@Override
public List<BankBranch> getAllBankBranchs() {
final String sql = "SELECT " +
"[bank_branch].[id] AS [id_bb], " +
"[bank_branch].[address] AS [address_bb], " +
"[bank_branch].[city] AS [city_bb], " +
"[bank_branch].[zip] AS [zip_bb], " +
"[bank_branch].[lat] AS [lat_bb], " +
"[bank_branch].[lon] AS [lon_bb] " +
"FROM [bank_branch]";
return jdbcTemplate.query(sql, new BankBranchRowMapper());
}
@Override
public void createBankBranch(BankBranch bankBranch) {
final String sql = "INSERT INTO [bank_branch] (address, zip, city, lat, lon) VALUES (?, ?, ?, ?, ?)";
jdbcTemplate.update(sql, bankBranch.getAddress(), bankBranch.getZip(), bankBranch.getCity(),
bankBranch.getLat(), bankBranch.getLon());
}
@Override
public boolean deleteBankBranch(Long id) {
final String sql = "DELETE FROM [bank_branch] WHERE id = ?";
return jdbcTemplate.update(sql, id) == 1;
}
}
\ No newline at end of file
package com.tuke.fei.atvi2.api.repository.impl.sql;
import com.tuke.fei.atvi2.api.entity.RobberyEvent;
import com.tuke.fei.atvi2.api.repository.RobberyEventRepository;
import com.tuke.fei.atvi2.api.repository.impl.sql.rowmapper.RobberyEventRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class SQLRobberyEventRepository implements RobberyEventRepository {
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public List<RobberyEvent> getAll(Integer limit) {
final String sql = "SELECT TOP (?) " +
"[robbery_event].[id] AS [id_re], " +
"[robbery_event].[id_bank_branch] AS [id_bank_branch_re], " +
"[robbery_event].[timestamp] AS [timestamp_re], " +
"[robbery_event].[rate] AS [rate_re], " +
"[robbery_event].[audio_match] AS [audio_match_re], " +
"[robbery_event].[video_match] AS [video_match_re], " +
"[robbery_event].[audio_uri] AS [audio_uri_re], " +
"[robbery_event].[video_uri] AS [video_uri_re], " +
"[robbery_event].[keywords] AS [keywords_re], " +
"[bank_branch].[id] AS [id_bb], " +
"[bank_branch].[address] AS [address_bb], " +
"[bank_branch].[city] AS [city_bb], " +
"[bank_branch].[zip] AS [zip_bb], " +
"[bank_branch].[lat] AS [lat_bb], " +
"[bank_branch].[lon] AS [lon_bb] " +
"FROM [robbery_event] " +
"INNER JOIN [bank_branch] ON [robbery_event].[id_bank_branch] = [bank_branch].[id] " +
"ORDER BY [robbery_event].[timestamp]";
return jdbcTemplate.query(sql, new Object[] {limit}, new RobberyEventRowMapper());
}
@Override
public List<RobberyEvent> getAllByBranchId(Long branchId, Integer limit) {
final String sql = "SELECT TOP (?) " +
"[robbery_event].[id] AS [id_re], " +
"[robbery_event].[id_bank_branch] AS [id_bank_branch_re], " +
"[robbery_event].[timestamp] AS [timestamp_re], " +
"[robbery_event].[rate] AS [rate_re], " +
"[robbery_event].[audio_match] AS [audio_match_re], " +
"[robbery_event].[video_match] AS [video_match_re], " +
"[robbery_event].[audio_uri] AS [audio_uri_re], " +
"[robbery_event].[video_uri] AS [video_uri_re], " +
"[robbery_event].[keywords] AS [keywords_re], " +
"[bank_branch].[id] AS [id_bb], " +
"[bank_branch].[address] AS [address_bb], " +
"[bank_branch].[city] AS [city_bb], " +
"[bank_branch].[zip] AS [zip_bb], " +
"[bank_branch].[lat] AS [lat_bb], " +
"[bank_branch].[lon] AS [lon_bb] " +
"FROM [robbery_event] " +
"INNER JOIN [bank_branch] ON [robbery_event].[id_bank_branch] = [bank_branch].[id] " +
"WHERE [robbery_event].[id_bank_branch] = ? " +
"ORDER BY [robbery_event].[timestamp]";
return jdbcTemplate.query(sql, new Object[] {limit, branchId}, new RobberyEventRowMapper());
}
@Override
public boolean create(RobberyEvent robberyEvent) {
final String sql = "INSERT INTO [robbery_event] (id_bank_branch, rate, audio_match, video_match, " +
"audio_uri, video_uri, keywords) VALUES (?, ?, ?, ?, ?, ?, ?)";
return jdbcTemplate.update(sql, robberyEvent.getBankBranch().getId(),
robberyEvent.getRate(), robberyEvent.getAudioMatch(), robberyEvent.getVideoMatch(),
robberyEvent.getAudioUri(), robberyEvent.getVideoUri(), robberyEvent.getKeywords()) == 1;
}
}
package com.tuke.fei.atvi2.api.repository.impl.sql.rowmapper;
import com.tuke.fei.atvi2.api.entity.BankBranch;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
public class BankBranchRowMapper implements RowMapper<BankBranch> {
@Override
public BankBranch mapRow(ResultSet rs, int i) throws SQLException {
BankBranch bankBranch = new BankBranch();
bankBranch.setId(rs.getLong("id_bb"));
bankBranch.setAddress(rs.getString("address_bb"));
bankBranch.setCity(rs.getString("city_bb"));
bankBranch.setZip(rs.getString("zip_bb"));
bankBranch.setLat(rs.getString("lat_bb"));
bankBranch.setLon(rs.getString("lon_bb"));
return bankBranch;
}
}
package com.tuke.fei.atvi2.api.repository.impl.sql.rowmapper;
import com.tuke.fei.atvi2.api.entity.RobberyEvent;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
public class RobberyEventRowMapper implements RowMapper<RobberyEvent> {
@Override
public RobberyEvent mapRow(ResultSet rs, int i) throws SQLException {
RobberyEvent robberyEvent = new RobberyEvent();
robberyEvent.setId(rs.getLong("id_re"));
robberyEvent.setAudioMatch(rs.getInt("audio_match_re"));
robberyEvent.setAudioUri(rs.getString("audio_uri_re"));
robberyEvent.setBankBranch(new BankBranchRowMapper().mapRow(rs, i));
robberyEvent.setKeywords(rs.getString("keywords_re"));
robberyEvent.setRate(rs.getInt("rate_re"));
robberyEvent.setTimestamp(rs.getTimestamp("timestamp_re"));
robberyEvent.setVideoMatch(rs.getInt("video_match_re"));
robberyEvent.setVideoUri(rs.getString("video_uri_re"));
return robberyEvent;
}
}
import React, { PureComponent } from "react";
import { StyleSheet, Text } from "react-native";
import { withNavigation } from "react-navigation";
import MapView, { Marker } from "react-native-maps";
class BranchesMap extends PureComponent {
_onPress = () => {
this.props.navigation.navigate("BranchInfo", {
branch: this.state.selectedMarker
});
};
state = {
region: this.getInitialState(),
markers: this.getMarkersFromBranches(this.props.data),
selectedMarker: null
};
getInitialState() {
return {
latitude: 48.723221,
longitude: 21.256716,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
};
}
getMarkersFromBranches(branches) {
markers = [];
branches.map(b => {
markers.push({
title: `${b.address}, ${b.zip} ${b.city}`,
latlng: { latitude: parseFloat(b.lat), longitude: parseFloat(b.long) },
description: "Tatra banka",
key: `${b.lat},${b.long}`
});
});
return markers;
}
render() {
return (
<MapView style={styles.map} region={this.state.region}>
{this.state.markers.map(marker => (
<Marker
key={marker.key}
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
/>
))}
</MapView>
);
}
}
const styles = StyleSheet.create({
map: {
flex: 1
}
});
export default BranchesMap;
export const BRANCHES = [
{ address: "OC Aupark", zip: "040 01", city: "Košice", id: 1 },
{ address: "Autobusova 71", zip: "040 01", city: "Košice", id: 2 },
{ address: "OC Galeria", zip: "040 01", city: "Košice", id: 3 },
{ address: "OC Optima", zip: "040 01", city: "Košice", id: 4 }
{
address: "OC Aupark",
zip: "040 01",
city: "Košice",
id: 1,
lat: "48.717727",
long: "21.262987"
},
{
address: "Hlavná 81",
zip: "040 01",
city: "Košice",
id: 2,
lat: "48.723221",
long: "21.256716"
},
{
address: "OC Galeria",
zip: "040 01",
city: "Košice",
id: 3,
lat: "48.715233",
long: "21.238327"
},
{
address: "OC Optima",
zip: "040 01",
city: "Košice",
id: 4,
lat: "48.695508",
long: "21.237335"
}
];
export const NOTIFICATIONS = [
......
import React, { Component } from "react";
import { StyleSheet, FlatList, View } from "react-native";
import BranchListItem from "../components/branches/BranchListItem";
import BranchesMap from "../components/branches/BranchesMap";
import { BRANCHES } from "../constants/Data";
export default class BranchesScreen extends Component {
......@@ -9,7 +10,8 @@ export default class BranchesScreen extends Component {
};
state = {
data: BRANCHES
data: BRANCHES,
mapView: true
};
_keyExtractor = item => `branch-${item.id}`;
......@@ -19,13 +21,17 @@ export default class BranchesScreen extends Component {
render() {
return (
<View style={styles.container}>
<FlatList
contentContainerStyle={styles.listContainer}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem}
ItemSeparatorComponent={BranchListItem.Divider}
data={this.state.data}
/>
{this.state.mapView ? (
<BranchesMap data={this.state.data} />
) : (
<FlatList
contentContainerStyle={styles.listContainer}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem}
ItemSeparatorComponent={BranchListItem.Divider}
data={this.state.data}
/>
)}
</View>
);
}
......
......@@ -4,3 +4,26 @@ CREATE TABLE [data] (
phrase VARCHAR(64) NOT NULL,
bank_robbery DECIMAL(5,2) NULL,