Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최재은
/
밀당강의봇
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최재은
2019-05-31 18:45:49 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
04490e5efff96d2068f031411a4efdad9582a3ff
04490e5e
1 parent
d33b285f
Add ce.khu.ac.kr crawling & lecture data file
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
207 additions
and
83 deletions
Database/lecture.json
khu.js
models/lecture.js
models/review.js
package-lock.json
package.json
routes/lectures.js
routes/reviews.js
test.png
Database/lecture.json
0 → 100644
View file @
04490e5
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2825"
},
"lecturename"
:
"전공 기초"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2826"
},
"lecturename"
:
"미분적분학"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2827"
},
"lecturename"
:
"선형대수"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2828"
},
"lecturename"
:
"확률 및 랜덤변수"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2829"
},
"lecturename"
:
"미분방정식"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced282a"
},
"lecturename"
:
"이산구조"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced282b"
},
"lecturename"
:
"전공 필수"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced282c"
},
"lecturename"
:
"웹/파이선프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced282d"
},
"lecturename"
:
"객체지향프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced282e"
},
"lecturename"
:
"논리회로"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced282f"
},
"lecturename"
:
"컴퓨터구조"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2830"
},
"lecturename"
:
"자료구조"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2831"
},
"lecturename"
:
"운영체제"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2832"
},
"lecturename"
:
"컴퓨터네트워크"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2833"
},
"lecturename"
:
"소프트웨어공학"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2834"
},
"lecturename"
:
"알고리즘분석"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2835"
},
"lecturename"
:
"데이터베이스"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2836"
},
"lecturename"
:
"오픈소스SW개발"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2837"
},
"lecturename"
:
"IT기술영어 1"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2838"
},
"lecturename"
:
"IT기술영어 2"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2839"
},
"lecturename"
:
"IT기술영어 3"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced283a"
},
"lecturename"
:
"캡스톤디자인 1"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced283b"
},
"lecturename"
:
"캡스톤디자인 2"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced283c"
},
"lecturename"
:
"졸업논문"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced283d"
},
"lecturename"
:
"전공 선택"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced283e"
},
"lecturename"
:
"문제해결"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced283f"
},
"lecturename"
:
"형식언어 및컴파일러"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2840"
},
"lecturename"
:
"파일처리"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2841"
},
"lecturename"
:
"멀티미디어시스템"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2842"
},
"lecturename"
:
"시스템분석 및 설계"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2843"
},
"lecturename"
:
"프로그래밍언어구조론"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2844"
},
"lecturename"
:
"JAVA프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2845"
},
"lecturename"
:
"SW스타트업비즈니스"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2846"
},
"lecturename"
:
"SW스타트업프로젝트"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2847"
},
"lecturename"
:
"최신기술프로젝트 1"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2848"
},
"lecturename"
:
"최신기술프로젝트 2"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2849"
},
"lecturename"
:
"최신기술콜로키움 1"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced284a"
},
"lecturename"
:
"최신기술콜로키움 2"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced284b"
},
"lecturename"
:
"단기현장실습"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced284c"
},
"lecturename"
:
"장기현장실습"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced284d"
},
"lecturename"
:
"연구연수활동 1"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced284e"
},
"lecturename"
:
"연구연수활동 2"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced284f"
},
"lecturename"
:
"독립심화학습1 (컴퓨터공학과)"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2850"
},
"lecturename"
:
"독립심화학습2 (컴퓨터공학과)"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2851"
},
"lecturename"
:
"인공지능"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2852"
},
"lecturename"
:
"머신러닝"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2853"
},
"lecturename"
:
"빅데이터프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2854"
},
"lecturename"
:
"클라우드컴퓨팅"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2855"
},
"lecturename"
:
"데이터센터프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2856"
},
"lecturename"
:
"네트워크분석및 설계"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2857"
},
"lecturename"
:
"인터넷프로토콜및 프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2858"
},
"lecturename"
:
"정보보호"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2859"
},
"lecturename"
:
"모바일프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced285a"
},
"lecturename"
:
"웹서비스프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced285b"
},
"lecturename"
:
"리눅스시스템프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced285c"
},
"lecturename"
:
"IoT디지털시스템"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced285d"
},
"lecturename"
:
"IoT소프트웨어"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced285e"
},
"lecturename"
:
"로봇소프트웨어"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced285f"
},
"lecturename"
:
"영상처리"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2860"
},
"lecturename"
:
"컴퓨터그래픽스"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2861"
},
"lecturename"
:
"멀티미디어처리"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2862"
},
"lecturename"
:
"인간-컴퓨터상호작용"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2863"
},
"lecturename"
:
"UI/UX프로그래밍"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2864"
},
"lecturename"
:
"컴퓨터비젼"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2865"
},
"lecturename"
:
"디자인적사고"
,
"__v"
:{
"$numberInt"
:
"0"
}}
{
"_id"
:{
"$oid"
:
"5cf0da0c7c7624ccbced2866"
},
"lecturename"
:
"신호와시스템"
,
"__v"
:{
"$numberInt"
:
"0"
}}
khu.js
0 → 100644
View file @
04490e5
const
puppeteer
=
require
(
'puppeteer'
);
const
request
=
require
(
'request'
);
(
async
()
=>
{
const
browser
=
await
puppeteer
.
launch
();
const
page
=
await
browser
.
newPage
();
await
page
.
goto
(
'http://ce.khu.ac.kr/index.php?hCode=UNIVERSITY_02_01_01'
);
await
page
.
screenshot
({
path
:
'test.png'
});
var
lecture
=
[];
lecture
=
await
page
.
evaluate
(()
=>
{
const
anchors
=
Array
.
from
(
document
.
querySelectorAll
(
'#conTD > td > div > table > tbody > tr > td:nth-child(2)'
));
return
anchors
.
map
(
anchor
=>
anchor
.
textContent
);
})
lecture
.
push
(
"디자인적사고"
)
lecture
.
push
(
"신호와시스템"
)
console
.
log
(
lecture
)
var
opts
var
posturl
=
"mongodb://localhost/facebookbot"
+
"/lectures"
for
(
var
i
=
0
;
i
<
lecture
.
length
;
i
++
){
console
.
log
(
lecture
[
i
])
request
.
post
(
'http://127.0.0.1:4500/lectures'
,
{
form
:
{
lecturename
:
lecture
[
i
]
}
})
}
await
browser
.
close
();
})();
\ No newline at end of file
models/lecture.js
View file @
04490e5
const
mongoose
=
require
(
'mongoose'
);
// Define Schemes
const
lectureSchema
=
new
mongoose
.
Schema
({
lectureid
:
{
type
:
String
,
unique
:
true
},
lecturename
:
{
type
:
String
},
proname
:
{
type
:
String
},
avg_rate
:
{
type
:
Number
}
});
const
reviewSchema
=
new
mongoose
.
Schema
({
lectureid
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
review
:
{
type
:
String
,
required
:
true
}
const
LectureSchema
=
new
mongoose
.
Schema
({
lecturename
:
{
type
:
String
,
required
:
true
,
unique
:
true
}
});
// // Create new
lecture
document
l
ectureSchema
.
statics
.
create
=
function
(
payload
)
{
// // Create new
review
document
L
ectureSchema
.
statics
.
create
=
function
(
payload
)
{
// this === Model
const
lecture
=
new
this
(
payload
);
const
review
=
new
this
(
payload
);
// return Promise
return
lecture
.
save
();
return
review
.
save
();
};
// Find All
l
ectureSchema
.
statics
.
findAll
=
function
()
{
L
ectureSchema
.
statics
.
findAll
=
function
()
{
// return promise
// V4부터 exec() 필요없음
return
this
.
find
({});
};
// Find One by lecture
id
lectureSchema
.
statics
.
findOneBylectureid
=
function
(
lectureid
)
{
return
this
.
findOne
({
lecture
id
});
// Find One by lecture
name
LectureSchema
.
statics
.
findOneBylecturename
=
function
(
lecturename
)
{
return
this
.
findOne
({
lecture
name
});
};
// Update by lecture
id
lectureSchema
.
statics
.
updateBylectureid
=
function
(
lectureid
,
payload
)
{
// Update by lecture
name
LectureSchema
.
statics
.
updateBylecturename
=
function
(
lecturename
,
payload
)
{
// { new: true }: return the modified document rather than the original. defaults to false
return
this
.
findOneAndUpdate
({
lecture
id
},
payload
,
{
new
:
true
});
return
this
.
findOneAndUpdate
({
lecture
name
},
payload
,
{
new
:
true
});
};
// Delete by lecture
id
lectureSchema
.
statics
.
deleteBylectureid
=
function
(
lectureid
)
{
return
this
.
remove
({
lecture
id
});
// Delete by lecture
name
LectureSchema
.
statics
.
deleteBylecturename
=
function
(
lecturename
)
{
return
this
.
remove
({
lecture
name
});
};
// Create Model & Export
module
.
exports
=
mongoose
.
model
(
'Lecture'
,
l
ectureSchema
);
module
.
exports
=
mongoose
.
model
(
'Lecture'
,
L
ectureSchema
);
\ No newline at end of file
...
...
models/review.js
View file @
04490e5
const
mongoose
=
require
(
'mongoose'
);
// Define Schemes
const
reviewSchema
=
new
mongoose
.
Schema
({
lectureid
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
review
:
{
type
:
String
,
required
:
true
}
lecturename
:
{
type
:
String
},
proname
:
{
type
:
String
},
avg_rate
:
{
type
:
Number
},
review
:
{
type
:
String
}
});
// // Create new review document
// // Create new lecture document
reviewSchema
.
statics
.
create
=
function
(
payload
)
{
// this === Model
const
review
=
new
this
(
payload
);
const
lecture
=
new
this
(
payload
);
// return Promise
return
review
.
save
();
return
lecture
.
save
();
};
// Find
All
reviewSchema
.
statics
.
find
All
=
function
(
)
{
// Find
lecturename
reviewSchema
.
statics
.
find
Bylecturename
=
function
(
lecturename
)
{
// return promise
// V4부터 exec() 필요없음
return
this
.
find
({});
return
this
.
find
({
lecturename
});
};
// Find
One by reviewid
reviewSchema
.
statics
.
find
OneByreviewid
=
function
(
reviewid
)
{
return
this
.
find
One
({
reviewid
});
// Find
by professor name
reviewSchema
.
statics
.
find
Byproname
=
function
(
proname
)
{
return
this
.
find
({
proname
});
};
// Update by
reviewid
reviewSchema
.
statics
.
updateBy
reviewid
=
function
(
reviewid
,
payload
)
{
// Update by
lecturename
reviewSchema
.
statics
.
updateBy
lecturename
=
function
(
lecturename
,
payload
)
{
// { new: true }: return the modified document rather than the original. defaults to false
return
this
.
findOneAndUpdate
({
reviewid
},
payload
,
{
new
:
true
});
return
this
.
findOneAndUpdate
({
lecturename
},
payload
,
{
new
:
true
});
};
// Delete by
reviewid
reviewSchema
.
statics
.
deleteBy
reviewid
=
function
(
reviewid
)
{
return
this
.
remove
({
reviewid
});
// Delete by
lecturename
reviewSchema
.
statics
.
deleteBy
lecturename
=
function
(
lecturename
)
{
return
this
.
remove
({
lecturename
});
};
// Create Model & Export
...
...
package-lock.json
View file @
04490e5
...
...
@@ -617,12 +617,25 @@
}
},
"mongodb"
:
{
"version"
:
"3.2.
5
"
,
"resolved"
:
"https://registry.npmjs.org/mongodb/-/mongodb-3.2.
5
.tgz"
,
"integrity"
:
"sha512-
VEu2nsfFMwWA6q6JVnlJ2kNVwjluU4op2J/YiG1LeI14t9HotLXbg8w3I794BvezC4ZCZ/wBTTdby01txalww
Q=="
,
"version"
:
"3.2.
6
"
,
"resolved"
:
"https://registry.npmjs.org/mongodb/-/mongodb-3.2.
6
.tgz"
,
"integrity"
:
"sha512-
qnHc4tjEkHKemuzBq9R7ycYnhFE0Dlpt6+n6suoZp2DcDdqviQ+teloJU24fsOw/PLmr75yGk4mRx/YabjDQE
Q=="
,
"requires"
:
{
"mongodb-core"
:
"3.2.
5
"
,
"mongodb-core"
:
"3.2.
6
"
,
"safe-buffer"
:
"^5.1.2"
},
"dependencies"
:
{
"mongodb-core"
:
{
"version"
:
"3.2.6"
,
"resolved"
:
"https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.6.tgz"
,
"integrity"
:
"sha512-i+XRVjur9D0ywGF7cFebOUnALnbvMHajdNhhl3TQuopW6QDE655G8CpPeERbqSqfa3rOKEUo08lENDIiBIuAvQ=="
,
"requires"
:
{
"bson"
:
"^1.1.1"
,
"require_optional"
:
"^1.0.1"
,
"safe-buffer"
:
"^5.1.2"
,
"saslprep"
:
"^1.0.0"
}
}
}
},
"mongodb-core"
:
{
...
...
@@ -656,6 +669,15 @@
"sliced"
:
"1.0.1"
},
"dependencies"
:
{
"mongodb"
:
{
"version"
:
"3.2.5"
,
"resolved"
:
"https://registry.npmjs.org/mongodb/-/mongodb-3.2.5.tgz"
,
"integrity"
:
"sha512-VEu2nsfFMwWA6q6JVnlJ2kNVwjluU4op2J/YiG1LeI14t9HotLXbg8w3I794BvezC4ZCZ/wBTTdby01txalwwQ=="
,
"requires"
:
{
"mongodb-core"
:
"3.2.5"
,
"safe-buffer"
:
"^5.1.2"
}
},
"ms"
:
{
"version"
:
"2.1.1"
,
"resolved"
:
"https://registry.npmjs.org/ms/-/ms-2.1.1.tgz"
,
...
...
package.json
View file @
04490e5
...
...
@@ -13,6 +13,7 @@
"body-parser"
:
"^1.19.0"
,
"dotenv"
:
"^8.0.0"
,
"express"
:
"^4.17.0"
,
"mongodb"
:
"^3.2.6"
,
"mongoose"
:
"^5.5.11"
,
"puppeteer"
:
"^1.17.0"
,
"puppeteer-core"
:
"^1.17.0"
,
...
...
routes/lectures.js
View file @
04490e5
...
...
@@ -4,41 +4,41 @@ const Lecture = require('../models/lecture');
// Find All
router
.
get
(
'/'
,
(
req
,
res
)
=>
{
Lecture
.
findAll
()
.
then
((
l
ectures
)
=>
{
if
(
!
l
ectures
.
length
)
return
res
.
status
(
404
).
send
({
err
:
'Lecture not found'
});
res
.
send
(
`find successfully:
${
l
ectures
}
`
);
.
then
((
L
ectures
)
=>
{
if
(
!
L
ectures
.
length
)
return
res
.
status
(
404
).
send
({
err
:
'Lecture not found'
});
res
.
send
(
`find successfully:
${
L
ectures
}
`
);
})
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Find One by lecture
id
router
.
get
(
'/lecture
id/:lectureid
'
,
(
req
,
res
)
=>
{
Lecture
.
findOneBylecture
id
(
req
.
params
.
lectureid
)
.
then
((
l
ecture
)
=>
{
if
(
!
l
ecture
)
return
res
.
status
(
404
).
send
({
err
:
'Lecture not found'
});
res
.
send
(
`findOne successfully:
${
l
ecture
}
`
);
// Find One by lecture
name
router
.
get
(
'/lecture
name/:lecturename
'
,
(
req
,
res
)
=>
{
Lecture
.
findOneBylecture
name
(
req
.
params
.
lecturename
)
.
then
((
L
ecture
)
=>
{
if
(
!
L
ecture
)
return
res
.
status
(
404
).
send
({
err
:
'Lecture not found'
});
res
.
send
(
`findOne successfully:
${
L
ecture
}
`
);
})
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Create new
l
ecture document
// Create new
L
ecture document
router
.
post
(
'/'
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
Lecture
.
create
(
req
.
body
)
.
then
(
lecture
=>
res
.
send
(
l
ecture
))
.
then
(
Lecture
=>
res
.
send
(
L
ecture
))
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Update by lecture
id
router
.
put
(
'/lecture
id/:lectureid
'
,
(
req
,
res
)
=>
{
Lecture
.
updateBylecture
id
(
req
.
params
.
lectureid
,
req
.
body
)
.
then
(
lecture
=>
res
.
send
(
l
ecture
))
// Update by lecture
name
router
.
put
(
'/lecture
name/:lecturename
'
,
(
req
,
res
)
=>
{
Lecture
.
updateBylecture
name
(
req
.
params
.
lecturename
,
req
.
body
)
.
then
(
Lecture
=>
res
.
send
(
L
ecture
))
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Delete by lecture
id
router
.
delete
(
'/lecture
id/:lectureid
'
,
(
req
,
res
)
=>
{
Lecture
.
deleteBylecture
id
(
req
.
params
.
lectureid
)
// Delete by lecture
name
router
.
delete
(
'/lecture
name/:lecturename
'
,
(
req
,
res
)
=>
{
Lecture
.
deleteBylecture
name
(
req
.
params
.
lecturename
)
.
then
(()
=>
res
.
sendStatus
(
200
))
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
...
...
routes/reviews.js
View file @
04490e5
...
...
@@ -4,41 +4,50 @@ const Review = require('../models/review');
// Find All
router
.
get
(
'/'
,
(
req
,
res
)
=>
{
Review
.
findAll
()
.
then
((
r
eviews
)
=>
{
if
(
!
r
eviews
.
length
)
return
res
.
status
(
404
).
send
({
err
:
'Review not found'
});
res
.
send
(
`find successfully:
${
r
eviews
}
`
);
.
then
((
R
eviews
)
=>
{
if
(
!
R
eviews
.
length
)
return
res
.
status
(
404
).
send
({
err
:
'Review not found'
});
res
.
send
(
`find successfully:
${
R
eviews
}
`
);
})
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Find One by
r
eviewid
router
.
get
(
'/
reviewid/:reviewid
'
,
(
req
,
res
)
=>
{
Review
.
find
OneByreviewid
(
req
.
params
.
reviewid
)
.
then
((
r
eview
)
=>
{
if
(
!
r
eview
)
return
res
.
status
(
404
).
send
({
err
:
'Review not found'
});
res
.
send
(
`findOne successfully:
${
r
eview
}
`
);
// Find One by
R
eviewid
router
.
get
(
'/
lecturename/:lecturename
'
,
(
req
,
res
)
=>
{
Review
.
find
Bylecturename
(
req
.
params
.
lecturename
)
.
then
((
R
eview
)
=>
{
if
(
!
R
eview
)
return
res
.
status
(
404
).
send
({
err
:
'Review not found'
});
res
.
send
(
`findOne successfully:
${
R
eview
}
`
);
})
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Create new review document
router
.
get
(
'/proname/:proname'
,
(
req
,
res
)
=>
{
Review
.
findByproname
(
req
.
params
.
proname
)
.
then
((
Review
)
=>
{
if
(
!
Review
)
return
res
.
status
(
404
).
send
({
err
:
'Review not found'
});
res
.
send
(
`findOne successfully:
${
Review
}
`
);
})
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Create new Review document
router
.
post
(
'/'
,
(
req
,
res
)
=>
{
console
.
log
(
req
.
body
)
Review
.
create
(
req
.
body
)
.
then
(
review
=>
res
.
send
(
r
eview
))
.
then
(
Review
=>
res
.
send
(
R
eview
))
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Update by
reviewid
router
.
put
(
'/
reviewid/:reviewid
'
,
(
req
,
res
)
=>
{
Review
.
updateBy
reviewid
(
req
.
params
.
reviewid
,
req
.
body
)
.
then
(
review
=>
res
.
send
(
r
eview
))
// Update by
lecturename
router
.
put
(
'/
lecturename/:lecturename
'
,
(
req
,
res
)
=>
{
Review
.
updateBy
lecturename
(
req
.
params
.
lecturename
,
req
.
body
)
.
then
(
Review
=>
res
.
send
(
R
eview
))
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
// Delete by
reviewid
router
.
delete
(
'/
reviewid/:reviewid
'
,
(
req
,
res
)
=>
{
Review
.
deleteBy
reviewid
(
req
.
params
.
reviewid
)
// Delete by
lecturename
router
.
delete
(
'/
lecturename/:lecturename
'
,
(
req
,
res
)
=>
{
Review
.
deleteBy
lecturename
(
req
.
params
.
lecturename
)
.
then
(()
=>
res
.
sendStatus
(
200
))
.
catch
(
err
=>
res
.
status
(
500
).
send
(
err
));
});
...
...
test.png
0 → 100644
View file @
04490e5
334 KB
Please
register
or
login
to post a comment