diff --git a/express_backend/database.db b/express_backend/database.db
index 9e04cfc..7b07dff 100644
Binary files a/express_backend/database.db and b/express_backend/database.db differ
diff --git a/express_backend/server.js b/express_backend/server.js
index 7a37905..e665aff 100644
--- a/express_backend/server.js
+++ b/express_backend/server.js
@@ -22,7 +22,7 @@ app.use(function(req, res, next) {
app.listen(port, () => console.log(`Listening on port ${port}`));
-app.get('/idea/:id', (req, res) => {
+app.get('/idea/get/:id', (req, res) => {
db.all(`SELECT * FROM ideas WHERE id = ${req.params.id}`, (err, rows) => {
if (err) {
@@ -42,7 +42,7 @@ app.get('/idea/:id', (req, res) => {
});
app.get('/ideas', (req, res) => {
- db.all(`SELECT * FROM ideas`, (err, rows) => {
+ db.all(`SELECT * FROM ideas ORDER BY id DESC`, (err, rows) => {
if (err) {
res.send({title: "Error", content: "Error fetching ideas"});
}else{
@@ -94,4 +94,23 @@ app.post('/idea/update/:id', (req, res) => {
res.send({title: "Success", type:"saving", message: "Idea updated"});
}
});
+});
+
+app.get('/idea/create', (req, res) => {
+ console.log("CREATE")
+ // Create new idea
+ db.run(`INSERT INTO ideas (title, content) VALUES ('New Idea', 'New Content')`, (err) => {
+ if (err) {
+ res.send({title: "Error", type:"create", message: "Error creating new idea"});
+ }else{
+ // SELECT id from last idea
+ db.all(`SELECT * FROM ideas ORDER BY id DESC LIMIT 1`, (err, rows) => {
+ if (err) {
+ res.send({title: "Error", type:"create", message: "Error fetching new idea id"});
+ }else{
+ res.send({title: "Success", type:"create", id:rows[0].id, message: "New idea created"});
+ }
+ });
+ }
+ });
});
\ No newline at end of file
diff --git a/react_frontend/src/Idea.js b/react_frontend/src/Idea.js
index 42114cf..e89f262 100644
--- a/react_frontend/src/Idea.js
+++ b/react_frontend/src/Idea.js
@@ -9,7 +9,7 @@ function Idea({ideaId, title, description, timestamp}){
const fetchIdea = async () => {
const data = await fetch(
- 'http://localhost:5000/idea/' + params.ideaId
+ 'http://localhost:5000/idea/get/' + params.ideaId
);
const idea = await data.json();
diff --git a/react_frontend/src/IdeaContent.js b/react_frontend/src/IdeaContent.js
index 005d836..c1f3519 100644
--- a/react_frontend/src/IdeaContent.js
+++ b/react_frontend/src/IdeaContent.js
@@ -66,7 +66,7 @@ function IdeaContent(){
const fetchIdea = async () => {
// fetch and check for error
const data = await fetch(
- 'http://localhost:5000/idea/' + params.ideaId
+ 'http://localhost:5000/idea/get/' + params.ideaId
);
const idea = await data.json();
diff --git a/react_frontend/src/IdeaList.js b/react_frontend/src/IdeaList.js
index 1488a9e..6b19433 100644
--- a/react_frontend/src/IdeaList.js
+++ b/react_frontend/src/IdeaList.js
@@ -9,6 +9,20 @@ function IdeaList() {
let selectedIdeaId = params.ideaId;
let [ideas, setIdeas] = useState([]);
+ const createIdea = async() => {
+ console.log('createIdea');
+
+ const data = await fetch(
+ 'http://localhost:5000/idea/create'
+ );
+
+ const result = await data.json();
+ console.log(result)
+ if(result.title === "Success"){
+ window.location = '/idea/' + result.id;
+ }
+
+ }
const fetchIdeas = async () => {
const data = await fetch(
'http://localhost:5000/ideas/'
@@ -32,7 +46,7 @@ function IdeaList() {
+
++