Skip to content

Commit

Permalink
delete working
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayden Woolstenhulme authored and Hayden Woolstenhulme committed Jun 12, 2018
1 parent aa539f3 commit e016e54
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 40 deletions.
1 change: 1 addition & 0 deletions db/deleteJournalEntry.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
delete from journal where id = $1;
3 changes: 3 additions & 0 deletions db/editEntry.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE journal
SET message = $1
WHERE id = $2;
2 changes: 1 addition & 1 deletion db/findJournalEntries.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
select id, message from journal
select id, message from journal where emid = $1
35 changes: 35 additions & 0 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react": "^16.3.2",
"react-chartjs-2": "^2.7.2",
"react-dom": "^16.3.2",
"react-grid-layout": "^0.16.6",
"react-particles-js": "^2.1.3",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
Expand Down
33 changes: 28 additions & 5 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,40 @@ app.get('/auth/me', function (req, res){
}
})

app.get('/api/journal/', (req, res, next) => {
app.get('/api/journal/:emid', (req, res) => {
const emid = req.params.emid;
console.log(req.params,'sup')
const dbInstance = req.app.get('db');
dbInstance.findJournalEntries()
dbInstance.findJournalEntries([emid])
.then(journal => {res.status(200).send(journal);
console.log(journal);
}).catch(err => {
console.log(err);
res.status(500).send(err)
});
}
)
})

app.delete('/api/journal/:emid', (req, res)=> {
const emid = req.params.emid;
const dbInstance = req.app.get('db');
dbInstance.deleteJournalEntry([emid])
.then(journal=> {res.status(200).send('ok')}).catch(err=> {
console.log(err);
res.status(500).send(err)
})
})

app.put('/api/journal/:id', (req, res)=> {
const id = req.params.id;
const message = req.params.message
const dbInstance = req.app.get('db');
dbInstance.editEntry([message, id])
.then(journal=> {res.status(200).send('ok')}).catch(err=> {
console.log(err);
res.status(500).send(err)
})
})

app.post('/api/journal/', (req, res, next)=> {
let{emid, message} = req.body;
req.app.get('db').addJournalEntry([emid, message]).then(ok=>{
Expand All @@ -109,5 +132,5 @@ app.post('/api/journal/', (req, res, next)=> {


app.listen(SERVER_PORT, ()=> {
console.log(`Yo bitch stuff is happening on: ${SERVER_PORT}`)
console.log(`Things are happening on port: ${SERVER_PORT}`)
})
62 changes: 62 additions & 0 deletions src/component/Journal/Checkbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import { selectEntry } from "../../ducks/users";


class Checkbox extends Component {
constructor() {
super();

this.state = {
isChecked: false,
entryToDelete: []
};
this.toggleCheckboxChange = this.toggleCheckboxChange.bind(this);
}

toggleCheckboxChange = () => {
const { handleCheckboxChange, label } = this.props;
console.log(this.props)

this.setState({ isChecked: !this.state.isChecked, entryToDelete: label });
this.props.selectEntry(label)
console.log(this.state.entryToDelete)
};

render() {
const { label } = this.props;
const { isChecked } = this.state;

return (
<div className="checkbox">
<label>
<input
type="checkbox"
value={label}
checked={isChecked}
onChange={this.toggleCheckboxChange}
/>

{label}
</label>
</div>
);
}
}

Checkbox.PropTypes = {
label: PropTypes.string.isRequired,
handleCheckboxChange: PropTypes.func.isRequired
};

function mapStateToProps(state) {
return {
entryToDelete: state.entryToDelete
};
}

export default connect(
mapStateToProps,
{ selectEntry }
)(Checkbox);
Loading

0 comments on commit e016e54

Please sign in to comment.