최재은

Changed DB : Mysql & Add Database File

1 -PORT=4500
2 -
3 -MONGO_URI=mongodb://localhost/facebookbot
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
1 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2825"},"lecturename":"전공 기초","__v":{"$numberInt":"0"}}
2 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2826"},"lecturename":"미분적분학","__v":{"$numberInt":"0"}}
3 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2827"},"lecturename":"선형대수","__v":{"$numberInt":"0"}}
4 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2828"},"lecturename":"확률 및 랜덤변수","__v":{"$numberInt":"0"}}
5 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2829"},"lecturename":"미분방정식","__v":{"$numberInt":"0"}}
6 -{"_id":{"$oid":"5cf0da0c7c7624ccbced282a"},"lecturename":"이산구조","__v":{"$numberInt":"0"}}
7 -{"_id":{"$oid":"5cf0da0c7c7624ccbced282b"},"lecturename":"전공 필수","__v":{"$numberInt":"0"}}
8 -{"_id":{"$oid":"5cf0da0c7c7624ccbced282c"},"lecturename":"웹/파이선프로그래밍","__v":{"$numberInt":"0"}}
9 -{"_id":{"$oid":"5cf0da0c7c7624ccbced282d"},"lecturename":"객체지향프로그래밍","__v":{"$numberInt":"0"}}
10 -{"_id":{"$oid":"5cf0da0c7c7624ccbced282e"},"lecturename":"논리회로","__v":{"$numberInt":"0"}}
11 -{"_id":{"$oid":"5cf0da0c7c7624ccbced282f"},"lecturename":"컴퓨터구조","__v":{"$numberInt":"0"}}
12 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2830"},"lecturename":"자료구조","__v":{"$numberInt":"0"}}
13 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2831"},"lecturename":"운영체제","__v":{"$numberInt":"0"}}
14 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2832"},"lecturename":"컴퓨터네트워크","__v":{"$numberInt":"0"}}
15 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2833"},"lecturename":"소프트웨어공학","__v":{"$numberInt":"0"}}
16 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2834"},"lecturename":"알고리즘분석","__v":{"$numberInt":"0"}}
17 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2835"},"lecturename":"데이터베이스","__v":{"$numberInt":"0"}}
18 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2836"},"lecturename":"오픈소스SW개발","__v":{"$numberInt":"0"}}
19 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2837"},"lecturename":"IT기술영어 1","__v":{"$numberInt":"0"}}
20 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2838"},"lecturename":"IT기술영어 2","__v":{"$numberInt":"0"}}
21 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2839"},"lecturename":"IT기술영어 3","__v":{"$numberInt":"0"}}
22 -{"_id":{"$oid":"5cf0da0c7c7624ccbced283a"},"lecturename":"캡스톤디자인 1","__v":{"$numberInt":"0"}}
23 -{"_id":{"$oid":"5cf0da0c7c7624ccbced283b"},"lecturename":"캡스톤디자인 2","__v":{"$numberInt":"0"}}
24 -{"_id":{"$oid":"5cf0da0c7c7624ccbced283c"},"lecturename":"졸업논문","__v":{"$numberInt":"0"}}
25 -{"_id":{"$oid":"5cf0da0c7c7624ccbced283d"},"lecturename":"전공 선택","__v":{"$numberInt":"0"}}
26 -{"_id":{"$oid":"5cf0da0c7c7624ccbced283e"},"lecturename":"문제해결","__v":{"$numberInt":"0"}}
27 -{"_id":{"$oid":"5cf0da0c7c7624ccbced283f"},"lecturename":"형식언어 및컴파일러","__v":{"$numberInt":"0"}}
28 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2840"},"lecturename":"파일처리","__v":{"$numberInt":"0"}}
29 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2841"},"lecturename":"멀티미디어시스템","__v":{"$numberInt":"0"}}
30 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2842"},"lecturename":"시스템분석 및 설계","__v":{"$numberInt":"0"}}
31 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2843"},"lecturename":"프로그래밍언어구조론","__v":{"$numberInt":"0"}}
32 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2844"},"lecturename":"JAVA프로그래밍","__v":{"$numberInt":"0"}}
33 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2845"},"lecturename":"SW스타트업비즈니스","__v":{"$numberInt":"0"}}
34 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2846"},"lecturename":"SW스타트업프로젝트","__v":{"$numberInt":"0"}}
35 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2847"},"lecturename":"최신기술프로젝트 1","__v":{"$numberInt":"0"}}
36 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2848"},"lecturename":"최신기술프로젝트 2","__v":{"$numberInt":"0"}}
37 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2849"},"lecturename":"최신기술콜로키움 1","__v":{"$numberInt":"0"}}
38 -{"_id":{"$oid":"5cf0da0c7c7624ccbced284a"},"lecturename":"최신기술콜로키움 2","__v":{"$numberInt":"0"}}
39 -{"_id":{"$oid":"5cf0da0c7c7624ccbced284b"},"lecturename":"단기현장실습","__v":{"$numberInt":"0"}}
40 -{"_id":{"$oid":"5cf0da0c7c7624ccbced284c"},"lecturename":"장기현장실습","__v":{"$numberInt":"0"}}
41 -{"_id":{"$oid":"5cf0da0c7c7624ccbced284d"},"lecturename":"연구연수활동 1","__v":{"$numberInt":"0"}}
42 -{"_id":{"$oid":"5cf0da0c7c7624ccbced284e"},"lecturename":"연구연수활동 2","__v":{"$numberInt":"0"}}
43 -{"_id":{"$oid":"5cf0da0c7c7624ccbced284f"},"lecturename":"독립심화학습1 (컴퓨터공학과)","__v":{"$numberInt":"0"}}
44 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2850"},"lecturename":"독립심화학습2 (컴퓨터공학과)","__v":{"$numberInt":"0"}}
45 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2851"},"lecturename":"인공지능","__v":{"$numberInt":"0"}}
46 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2852"},"lecturename":"머신러닝","__v":{"$numberInt":"0"}}
47 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2853"},"lecturename":"빅데이터프로그래밍","__v":{"$numberInt":"0"}}
48 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2854"},"lecturename":"클라우드컴퓨팅","__v":{"$numberInt":"0"}}
49 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2855"},"lecturename":"데이터센터프로그래밍","__v":{"$numberInt":"0"}}
50 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2856"},"lecturename":"네트워크분석및 설계","__v":{"$numberInt":"0"}}
51 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2857"},"lecturename":"인터넷프로토콜및 프로그래밍","__v":{"$numberInt":"0"}}
52 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2858"},"lecturename":"정보보호","__v":{"$numberInt":"0"}}
53 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2859"},"lecturename":"모바일프로그래밍","__v":{"$numberInt":"0"}}
54 -{"_id":{"$oid":"5cf0da0c7c7624ccbced285a"},"lecturename":"웹서비스프로그래밍","__v":{"$numberInt":"0"}}
55 -{"_id":{"$oid":"5cf0da0c7c7624ccbced285b"},"lecturename":"리눅스시스템프로그래밍","__v":{"$numberInt":"0"}}
56 -{"_id":{"$oid":"5cf0da0c7c7624ccbced285c"},"lecturename":"IoT디지털시스템","__v":{"$numberInt":"0"}}
57 -{"_id":{"$oid":"5cf0da0c7c7624ccbced285d"},"lecturename":"IoT소프트웨어","__v":{"$numberInt":"0"}}
58 -{"_id":{"$oid":"5cf0da0c7c7624ccbced285e"},"lecturename":"로봇소프트웨어","__v":{"$numberInt":"0"}}
59 -{"_id":{"$oid":"5cf0da0c7c7624ccbced285f"},"lecturename":"영상처리","__v":{"$numberInt":"0"}}
60 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2860"},"lecturename":"컴퓨터그래픽스","__v":{"$numberInt":"0"}}
61 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2861"},"lecturename":"멀티미디어처리","__v":{"$numberInt":"0"}}
62 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2862"},"lecturename":"인간-컴퓨터상호작용","__v":{"$numberInt":"0"}}
63 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2863"},"lecturename":"UI/UX프로그래밍","__v":{"$numberInt":"0"}}
64 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2864"},"lecturename":"컴퓨터비젼","__v":{"$numberInt":"0"}}
65 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2865"},"lecturename":"디자인적사고","__v":{"$numberInt":"0"}}
66 -{"_id":{"$oid":"5cf0da0c7c7624ccbced2866"},"lecturename":"신호와시스템","__v":{"$numberInt":"0"}}
1 -const puppeteer = require('puppeteer');
2 -const request = require('request');
3 -
4 -(async () => {
5 - const browser = await puppeteer.launch();
6 - const page = await browser.newPage();
7 - await page.goto('http://ce.khu.ac.kr/index.php?hCode=UNIVERSITY_02_01_01');
8 - await page.screenshot({path: 'test.png'});
9 - var lecture = [];
10 - lecture = await page.evaluate(() => {
11 - const anchors = Array.from(document.querySelectorAll('#conTD > td > div > table > tbody > tr > td:nth-child(2)'));
12 - return anchors.map(anchor => anchor.textContent);
13 - })
14 -
15 - lecture.push("디자인적사고")
16 - lecture.push("신호와시스템")
17 - console.log(lecture)
18 - var opts
19 -
20 -
21 - var posturl = "mongodb://localhost/facebookbot" + "/lectures"
22 - for(var i=0; i<lecture.length; i++){
23 - console.log(lecture[i])
24 - request.post('http://127.0.0.1:4500/lectures', {
25 - form: {
26 - lecturename: lecture[i]
27 - }
28 - })
29 - }
30 - await browser.close();
31 -})();
...\ No newline at end of file ...\ No newline at end of file
1 const puppeteer = require('puppeteer'); 1 const puppeteer = require('puppeteer');
2 +const request = require('request');
3 +const mysql = require('mysql');
4 +const util = require('util');
5 +var emojiStrip = require('emoji-strip')
6 +
7 +var connection = mysql.createConnection({
8 + host : 'localhost',
9 + user : 'root',
10 + password : '',
11 + port : 3306,
12 + database : 'facebookbot'
13 +})
14 +const query = util.promisify(connection.query).bind(connection);
15 +
2 (async () => { 16 (async () => {
3 const browser = await puppeteer.launch(); 17 const browser = await puppeteer.launch();
4 const page = await browser.newPage(); 18 const page = await browser.newPage();
19 + await page.goto('http://ce.khu.ac.kr/index.php?hCode=UNIVERSITY_02_01_01');
20 + await page.screenshot({path: 'test.png'});
21 + var lecture = [];
22 + lecture = await page.evaluate(() => {
23 + const anchors = Array.from(document.querySelectorAll('#conTD > td > div > table > tbody > tr > td:nth-child(2)'));
24 + return anchors.map(anchor => anchor.textContent);
25 + })
26 +
27 + lecture.push("디자인적사고")
28 + lecture.push("신호와시스템")
29 +
30 +
31 +
32 + for(var i=0; i<lecture.length; i++){
33 + console.log(lecture[i])
34 + await query('INSERT INTO lectures (lecturename) VALUES (?)',lecture[i])
35 + }
36 +
37 +
38 + const browser = await puppeteer.launch();
39 + const page = await browser.newPage();
5 const et_id = ""; 40 const et_id = "";
6 const et_pw = ""; 41 const et_pw = "";
7 - const lecture = "";
8 await page.goto('https://everytime.kr/login'); 42 await page.goto('https://everytime.kr/login');
9 await page.evaluate((id, pw) => { 43 await page.evaluate((id, pw) => {
10 document.querySelector("input[name=userid]").value = id; 44 document.querySelector("input[name=userid]").value = id;
...@@ -13,52 +47,68 @@ const puppeteer = require('puppeteer'); ...@@ -13,52 +47,68 @@ const puppeteer = require('puppeteer');
13 await console.log("로그인 정보 삽입 완료") 47 await console.log("로그인 정보 삽입 완료")
14 await page.click('#container > form > p.submit > input'); 48 await page.click('#container > form > p.submit > input');
15 await page.waitFor(1000); 49 await page.waitFor(1000);
16 - await page.goto('https://everytime.kr/lecture'); 50 +
17 - await page.evaluate((lec) => {
18 - document.querySelector("input[name=keyword]").value = lec;
19 - }, lecture);
20 - await page.click('#container > form > input.submit');
21 - await page.waitFor(1000);
22 51
23 - let tempclass = await page.evaluate((sel) => { 52 + var lecary = [];
24 - return Array.from(document.getElementsByClassName(sel)).map(node => node.href); 53 + const rows = await query('SELECT * FROM lectures');
25 - }, 'lecture'); 54 + for(var i =0; i<rows.length; i++){
26 - console.log(tempclass) 55 + lecary.push(rows[i].lecturename)
56 + }
57 + console.log(lecary)
58 +
59 + for(var i=0 ; i< lecary.length; i++){
60 + var templecture = lecary[i];
61 + console.log(lecture);
62 + await page.goto('https://everytime.kr/lecture');
63 + await page.evaluate((lec) => {
64 + document.querySelector("input[name=keyword]").value = lec;
65 + }, templecture);
66 + await page.click('#container > form > input.submit');
67 + await page.waitFor(1000);
27 68
69 + let tempclass = await page.evaluate((sel) => {
70 + return Array.from(document.getElementsByClassName(sel)).map(node => node.href);
71 + }, 'lecture');
72 + console.log(tempclass)
28 73
29 - for (var i in tempclass) { 74 + for (var j = 0; j < tempclass.length; j++) {
30 - console.log(tempclass[i]); 75 + console.log(tempclass[j]);
31 - await page.goto(tempclass[i]); 76 + await page.goto(tempclass[j]);
32 - await page.waitFor(1000); 77 + await page.waitFor(1000);
33 - await page.waitForSelector('#container > div.side.head > h2'); 78 + await page.waitForSelector('#container > div.side.head > h2');
34 - const lecturename = await page.evaluate(() => { 79 + const lecturename = await page.evaluate(() => {
35 - const anchors1 = Array.from(document.querySelectorAll('#container > div.side.head > h2')); 80 + const anchors1 = Array.from(document.querySelectorAll('#container > div.side.head > h2'));
36 - return anchors1.map(anchor1 => anchor1.textContent); 81 + return anchors1.map(anchor1 => anchor1.textContent);
37 - }); 82 + });
38 - await page.waitForSelector('#container > div.side.head > p:nth-child(3) > span'); 83 + await page.waitForSelector('#container > div.side.head > p:nth-child(3) > span');
39 - const proname = await page.evaluate(() => { 84 + const proname = await page.evaluate(() => {
40 - const anchors2 = Array.from(document.querySelectorAll('#container > div.side.head > p:nth-child(3) > span')); 85 + const anchors2 = Array.from(document.querySelectorAll('#container > div.side.head > p:nth-child(3) > span'));
41 - return anchors2.map(anchor2 => anchor2.textContent); 86 + return anchors2.map(anchor2 => anchor2.textContent);
42 - });
43 - await page.waitForSelector('#container > div.side.article > div.rating > div.rate > span > span.value');
44 - const avg_rate = await page.evaluate(() => {
45 - const anchors3 = Array.from(document.querySelectorAll('#container > div.side.article > div.rating > div.rate > span > span.value'));
46 - return anchors3.map(anchor3 => anchor3.textContent);
47 - });
48 - let review = [];
49 - if (await page.$('#container > div.side.article > div.articles > article > p.text') !== null){
50 - await page.waitForSelector('#container > div.side.article > div.articles > article > p.text');
51 - review = await page.evaluate(() => {
52 - const anchors4 = Array.from(document.querySelectorAll('#container > div.side.article > div.articles > article > p.text'));
53 - return anchors4.map(anchor4 => anchor4.textContent);
54 }); 87 });
88 + await page.waitForSelector('#container > div.side.article > div.rating > div.rate > span > span.value');
89 + const avg_rate = await page.evaluate(() => {
90 + const anchors3 = Array.from(document.querySelectorAll('#container > div.side.article > div.rating > div.rate > span > span.value'));
91 + return anchors3.map(anchor3 => anchor3.textContent);
92 + });
93 + let review = [];
94 + if (await page.$('#container > div.side.article > div.articles > article > p.text') !== null){
95 + await page.waitForSelector('#container > div.side.article > div.articles > article > p.text');
96 + review = await page.evaluate(() => {
97 + const anchors4 = Array.from(document.querySelectorAll('#container > div.side.article > div.articles > article > p.text'));
98 + return anchors4.map(anchor4 => anchor4.textContent);
99 + });
100 + }
101 + console.log(lecturename.join('\n'));
102 + console.log(proname.join('\n'));
103 + console.log(avg_rate.join('\n'));
104 + console.log(review);
105 + review = review.toString()
106 + review = emojiStrip(review)
107 +
108 + await query('INSERT INTO reviews (lecturename,proname,avg_rate,review) VALUES (?,?,?,?)',[lecturename,proname,avg_rate,review])
55 } 109 }
56 - //콘솔에 출력한다.
57 - console.log(lecturename.join('\n'));
58 - console.log(proname.join('\n'));
59 - console.log(avg_rate.join('\n'));
60 - console.log(review);
61 } 110 }
62 - 111 +
63 await browser.close(); 112 await browser.close();
113 + connection.end();
64 })(); 114 })();
...\ No newline at end of file ...\ No newline at end of file
......
1 -const mongoose = require('mongoose');
2 -
3 -
4 -const LectureSchema = new mongoose.Schema({
5 - lecturename: { type: String, required: true, unique: true }
6 -});
7 -
8 -// // Create new review document
9 -LectureSchema.statics.create = function (payload) {
10 - // this === Model
11 - const review = new this(payload);
12 - // return Promise
13 - return review.save();
14 -};
15 -
16 -// Find All
17 -LectureSchema.statics.findAll = function () {
18 - // return promise
19 - // V4부터 exec() 필요없음
20 - return this.find({});
21 -};
22 -
23 -// Find One by lecturename
24 -LectureSchema.statics.findOneBylecturename = function (lecturename) {
25 - return this.findOne({ lecturename });
26 -};
27 -
28 -// Update by lecturename
29 -LectureSchema.statics.updateBylecturename = function (lecturename, payload) {
30 - // { new: true }: return the modified document rather than the original. defaults to false
31 - return this.findOneAndUpdate({ lecturename }, payload, { new: true });
32 -};
33 -
34 -// Delete by lecturename
35 -LectureSchema.statics.deleteBylecturename = function (lecturename) {
36 - return this.remove({ lecturename });
37 -};
38 -
39 -// Create Model & Export
40 -module.exports = mongoose.model('Lecture', LectureSchema);
...\ No newline at end of file ...\ No newline at end of file
1 -const mongoose = require('mongoose');
2 -
3 -// Define Schemes
4 -const reviewSchema = new mongoose.Schema({
5 - lecturename: { type: String },
6 - proname: { type: String },
7 - avg_rate: { type: Number },
8 - review: {type : String}
9 -});
10 -
11 -
12 -// // Create new lecture document
13 -reviewSchema.statics.create = function (payload) {
14 - // this === Model
15 - const lecture = new this(payload);
16 - // return Promise
17 - return lecture.save();
18 -};
19 -
20 -// Find lecturename
21 -reviewSchema.statics.findBylecturename = function (lecturename) {
22 - // return promise
23 - // V4부터 exec() 필요없음
24 - return this.find({ lecturename });
25 -};
26 -
27 -// Find by professor name
28 -reviewSchema.statics.findByproname = function (proname) {
29 - return this.find({ proname });
30 -};
31 -
32 -// Update by lecturename
33 -reviewSchema.statics.updateBylecturename = function (lecturename, payload) {
34 - // { new: true }: return the modified document rather than the original. defaults to false
35 - return this.findOneAndUpdate({ lecturename }, payload, { new: true });
36 -};
37 -
38 -// Delete by lecturename
39 -reviewSchema.statics.deleteBylecturename = function (lecturename) {
40 - return this.remove({ lecturename });
41 -};
42 -
43 -// Create Model & Export
44 -module.exports = mongoose.model('Review', reviewSchema);
This diff is collapsed. Click to expand it.
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
11 "license": "ISC", 11 "license": "ISC",
12 "dependencies": { 12 "dependencies": {
13 "body-parser": "^1.19.0", 13 "body-parser": "^1.19.0",
14 - "dotenv": "^8.0.0", 14 + "emoji-strip": "^1.0.1",
15 "express": "^4.17.0", 15 "express": "^4.17.0",
16 - "mongodb": "^3.2.6", 16 + "mongojs": "^2.6.0",
17 - "mongoose": "^5.5.11", 17 + "mysql": "^2.17.1",
18 "puppeteer": "^1.17.0", 18 "puppeteer": "^1.17.0",
19 "puppeteer-core": "^1.17.0", 19 "puppeteer-core": "^1.17.0",
20 "request": "^2.88.0" 20 "request": "^2.88.0"
......
1 -const router = require('express').Router();
2 -const Lecture = require('../models/lecture');
3 -
4 -// Find All
5 -router.get('/', (req, res) => {
6 - Lecture.findAll()
7 - .then((Lectures) => {
8 - if (!Lectures.length) return res.status(404).send({ err: 'Lecture not found' });
9 - res.send(`find successfully: ${Lectures}`);
10 - })
11 - .catch(err => res.status(500).send(err));
12 -});
13 -
14 -// Find One by lecturename
15 -router.get('/lecturename/:lecturename', (req, res) => {
16 - Lecture.findOneBylecturename(req.params.lecturename)
17 - .then((Lecture) => {
18 - if (!Lecture) return res.status(404).send({ err: 'Lecture not found' });
19 - res.send(`findOne successfully: ${Lecture}`);
20 - })
21 - .catch(err => res.status(500).send(err));
22 -});
23 -
24 -// Create new Lecture document
25 -router.post('/', (req, res) => {
26 - console.log(req.body)
27 - Lecture.create(req.body)
28 - .then(Lecture => res.send(Lecture))
29 - .catch(err => res.status(500).send(err));
30 -});
31 -
32 -// Update by lecturename
33 -router.put('/lecturename/:lecturename', (req, res) => {
34 - Lecture.updateBylecturename(req.params.lecturename, req.body)
35 - .then(Lecture => res.send(Lecture))
36 - .catch(err => res.status(500).send(err));
37 -});
38 -
39 -// Delete by lecturename
40 -router.delete('/lecturename/:lecturename', (req, res) => {
41 - Lecture.deleteBylecturename(req.params.lecturename)
42 - .then(() => res.sendStatus(200))
43 - .catch(err => res.status(500).send(err));
44 -});
45 -
46 -module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
1 -const router = require('express').Router();
2 -const Review = require('../models/review');
3 -
4 -// Find All
5 -router.get('/', (req, res) => {
6 - Review.findAll()
7 - .then((Reviews) => {
8 - if (!Reviews.length) return res.status(404).send({ err: 'Review not found' });
9 - res.send(`find successfully: ${Reviews}`);
10 - })
11 - .catch(err => res.status(500).send(err));
12 -});
13 -
14 -// Find One by Reviewid
15 -router.get('/lecturename/:lecturename', (req, res) => {
16 - Review.findBylecturename(req.params.lecturename)
17 - .then((Review) => {
18 - if (!Review) return res.status(404).send({ err: 'Review not found' });
19 - res.send(`findOne successfully: ${Review}`);
20 - })
21 - .catch(err => res.status(500).send(err));
22 -});
23 -
24 -router.get('/proname/:proname', (req, res) => {
25 - Review.findByproname(req.params.proname)
26 - .then((Review) => {
27 - if (!Review) return res.status(404).send({ err: 'Review not found' });
28 - res.send(`findOne successfully: ${Review}`);
29 - })
30 - .catch(err => res.status(500).send(err));
31 -});
32 -
33 -// Create new Review document
34 -router.post('/', (req, res) => {
35 - console.log(req.body)
36 - Review.create(req.body)
37 - .then(Review => res.send(Review))
38 - .catch(err => res.status(500).send(err));
39 -});
40 -
41 -// Update by lecturename
42 -router.put('/lecturename/:lecturename', (req, res) => {
43 - Review.updateBylecturename(req.params.lecturename, req.body)
44 - .then(Review => res.send(Review))
45 - .catch(err => res.status(500).send(err));
46 -});
47 -
48 -// Delete by lecturename
49 -router.delete('/lecturename/:lecturename', (req, res) => {
50 - Review.deleteBylecturename(req.params.lecturename)
51 - .then(() => res.sendStatus(200))
52 - .catch(err => res.status(500).send(err));
53 -});
54 -
55 -module.exports = router;
...\ No newline at end of file ...\ No newline at end of file
1 -// ENV
2 -require('dotenv').config();
3 -
4 -// DEPENDENCIES
5 -const express = require('express');
6 -const mongoose = require('mongoose');
7 -const bodyParser = require('body-parser');
8 -
9 -const app = express();
10 -const port = process.env.PORT || 4500;
11 -
12 -// Static File Service
13 -app.use(express.static('public'));
14 -// Body-parser
15 -app.use(bodyParser.urlencoded({ extended: true }));
16 -app.use(bodyParser.json());
17 -
18 -// Node의 native Promise 사용
19 -mongoose.Promise = global.Promise;
20 -
21 -// Connect to MongoDB
22 -mongoose.connect(process.env.MONGO_URI)
23 - .then(() => console.log('Successfully connected to mongodb'))
24 - .catch(e => console.error(e));
25 -
26 -// ROUTERS
27 -app.use('/lectures', require('./routes/lectures'));
28 -app.use('/reviews', require('./routes/reviews'));
29 -app.listen(port, () => console.log(`Server listening on port ${port}`));
...\ No newline at end of file ...\ No newline at end of file