From 69b5992450e85edf387a608ffeb1ba553a164b66 Mon Sep 17 00:00:00 2001 From: akhilalekha Date: Wed, 5 May 2021 17:56:14 +0530 Subject: [PATCH] Feat: Create a method to send the courses to db create addCourses in meta.js move meta.js from libs to courses install axios imported in index for testing purposes --- website/courses/meta.js | 48 +++++++++++++++++++++++++++++++++++++++ website/lib/meta.js | 34 --------------------------- website/package-lock.json | 41 +++++++++++++++++++++++++++++++++ website/package.json | 1 + website/pages/index.js | 2 ++ 5 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 website/courses/meta.js delete mode 100644 website/lib/meta.js diff --git a/website/courses/meta.js b/website/courses/meta.js new file mode 100644 index 00000000..f5203b49 --- /dev/null +++ b/website/courses/meta.js @@ -0,0 +1,48 @@ +import axios from "axios"; +let courses = [ + { + courseId: 1, + courseName: "javascript", + chapters: [ + { + chapterId: 1, + chapterUrl: "introduction", + chapterName: "Introduction" + }, + { + chapterId: 2, + chapterUrl: "hello-world", + chapterName: "Hello World" + }, + { + chapterId: 3, + chapterUrl: "variables", + chapterName: "Variables" + }, + { + chapterId: 4, + chapterUrl: "datatypes", + chapterName: "Datatypes" + }, + { + chapterId: 5, + chapterUrl: "logical-operators", + chapterName: "Logical Operators" + }, + { + chapterId: 6, + chapterUrl: "if-condition", + chapterName: "If Condition" + } + ] + } +]; + +async function addCourses() { + // console.log("in add courses"); + axios + .post("http://localhost:8080", courses) + .then((res) => console.log("sent courses", res.data)) + .catch((err) => console.log(err)); +} +export { courses, addCourses }; diff --git a/website/lib/meta.js b/website/lib/meta.js deleted file mode 100644 index fd5e22f7..00000000 --- a/website/lib/meta.js +++ /dev/null @@ -1,34 +0,0 @@ -const titles = [ - { - id: 1, - url: "introduction", - linkTitle: "Introduction" - }, - { - id: 2, - url: "hello-world", - linkTitle: "Hello World" - }, - { - id: 3, - url: "variables", - linkTitle: "Variables" - }, - { - id: 4, - url: "datatypes", - linkTitle: "Datatypes" - }, - { - id: 5, - url: "logical-operators", - linkTitle: "Logical Operators" - }, - { - id: 6, - url: "if-condition", - linkTitle: "If Condition" - } -]; - -export default titles; diff --git a/website/package-lock.json b/website/package-lock.json index 7a5797d7..da8f1e3c 100644 --- a/website/package-lock.json +++ b/website/package-lock.json @@ -15,6 +15,7 @@ "@codemirror/theme-one-dark": "^0.18.0", "@codemirror/view": "^0.18.7", "@heroicons/react": "^1.0.1", + "axios": "^0.21.1", "fs": "0.0.1-security", "gray-matter": "^4.0.2", "highlight.js": "^10.7.2", @@ -1015,6 +1016,14 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "dependencies": { + "follow-redirects": "^1.10.0" + } + }, "node_modules/babel-plugin-syntax-jsx": { "version": "6.18.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", @@ -2027,6 +2036,25 @@ "node": ">=8" } }, + "node_modules/follow-redirects": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz", + "integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, "node_modules/foreach": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", @@ -6083,6 +6111,14 @@ "array-filter": "^1.0.0" } }, + "axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, "babel-plugin-syntax-jsx": { "version": "6.18.0", "resolved": "https://registry.npmjs.org/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz", @@ -6919,6 +6955,11 @@ "path-exists": "^4.0.0" } }, + "follow-redirects": { + "version": "1.14.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.0.tgz", + "integrity": "sha512-0vRwd7RKQBTt+mgu87mtYeofLFZpTas2S9zY+jIeuLJMNvudIgF52nr19q40HOwH5RrhWIPuj9puybzSJiRrVg==" + }, "foreach": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/foreach/-/foreach-2.0.5.tgz", diff --git a/website/package.json b/website/package.json index eb21c424..cc747a47 100644 --- a/website/package.json +++ b/website/package.json @@ -15,6 +15,7 @@ "@codemirror/theme-one-dark": "^0.18.0", "@codemirror/view": "^0.18.7", "@heroicons/react": "^1.0.1", + "axios": "^0.21.1", "fs": "0.0.1-security", "gray-matter": "^4.0.2", "highlight.js": "^10.7.2", diff --git a/website/pages/index.js b/website/pages/index.js index a60e8b32..55814d52 100644 --- a/website/pages/index.js +++ b/website/pages/index.js @@ -1,5 +1,7 @@ import Layout from "../component/layout/Layout.jsx"; +import { addCourses } from "../courses/meta"; export default function Home() { + // addCourses(); return ; }