Skip to content

Commit

Permalink
fetch harbours
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelpucat committed Oct 21, 2018
1 parent 7d8db17 commit c03eec6
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 32 deletions.
9 changes: 9 additions & 0 deletions pdt-marinehelper-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pdt-marinehelper-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"mapbox-gl": "^0.50.0",
"mdbreact": "^4.8.1",
"react": "^16.5.2",
Expand Down
11 changes: 11 additions & 0 deletions pdt-marinehelper-client/src/app/components/Harbours.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import React from "react";
import axios from "axios";

export class Harbours extends React.Component {
componentDidMount() {
axios.get("http://localhost:3001/harbours/getHarbour?id=244608718")
.then(res => {
console.log(res.data);
})
.catch(err=>{
console.log(err);
})
}

render() {
return (
<div>
Expand Down
58 changes: 33 additions & 25 deletions pdt-marinehelper-client/src/app/components/Header.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
import React from "react";
import { Navbar, Nav, NavItem } from "react-bootstrap";
import { Link } from "react-router-dom";
import { Link, withRouter } from "react-router-dom";

export const Header = props => {
const Navigation = withRouter(({ history }) => (
<Navbar.Collapse>
<Nav>
{/*harbours*/}
<NavItem eventKey={1} onClick={() => history.push("/harbours")}>
Harbours
</NavItem>

{/*dangers*/}
<NavItem eventKey={2} onClick={() => history.push("/dangers")}>
Dangers
</NavItem>

<NavItem eventKey={3} onClick={() => history.push("/anchorages")}>
Anchorages
</NavItem>
</Nav>

<Nav pullRight>
<NavItem eventKey={2} onClick={() => history.push("/about")}>
About
</NavItem>
</Nav>
</Navbar.Collapse>
));

return (
<header>
<Navbar inverse collapseOnSelect={true} style={{marginBottom: "0", borderRadius: "0"}}>
<Navbar
inverse
collapseOnSelect={true}
style={{ marginBottom: "0", borderRadius: "0" }}
>
<Navbar.Header>
<Navbar.Brand>
<Link to="/map">Marine helper</Link>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>

<Navbar.Collapse>
<Nav>
{/*harbours*/}
<NavItem eventKey={1}>
<Link to="/harbours">Harbours</Link>
</NavItem>

{/*dangers*/}
<NavItem eventKey={2}>
<Link to="/dangers">Dangers</Link>
</NavItem>

<NavItem eventKey={3}>
<Link to="/anchorages">Anchorages</Link>
</NavItem>
</Nav>

<Nav pullRight>
<NavItem eventKey={2}>
<Link to="/about">{"About"}</Link>
</NavItem>
</Nav>
</Navbar.Collapse>
<Navigation />
</Navbar>
</header>
);
Expand Down
10 changes: 6 additions & 4 deletions pdt-marinehelper-server/api/controllers/harboursController.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const db = require("../../db");

exports.getOne = (req, res, next) => {
const id = req.params.id;
const { id } = req.query;
const SELECT_HARBOUR_QUERY = 'select "seamark:type", "seamark:harbour:category", ST_AsGeoJSON(way) as way ' +
"from planet_osm_polygon " +
"where \"seamark:type\" = 'harbour' and osm_id = $1";

db.query(
'select "seamark:type", "seamark:harbour:category", ST_AsGeoJSON(way) as way ' +
"from planet_osm_polygon " +
"where \"seamark:type\" = 'harbour' and osm_id = $1",
SELECT_HARBOUR_QUERY,
[id],
(err, res1) => {
if (err) {
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions pdt-marinehelper-server/api/routes/harbours.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const express = require("express");
const router = express.Router();
const harboursController = require("../controllers/harboursController");

router.route("/:id").get(harboursController.getOne);
router.route("/getHarbour").get(harboursController.getOne);

router.route("/").get(harboursController.getAll);
router.route("/getAllHarbours").get(harboursController.getAll);

module.exports = router;
2 changes: 1 addition & 1 deletion pdt-marinehelper-server/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const http = require('http');
const app = require('./app');

const port = process.env.PORT || 3000;
const port = process.env.PORT || 3001;
const server = http.createServer(app);
server.listen(port);

0 comments on commit c03eec6

Please sign in to comment.