Showing
4 changed files
with
120 additions
and
44 deletions
| ... | @@ -11,6 +11,7 @@ KHU-Hub repo: [khuhub.khu.ac.kr/2018102216/dev-profile](https://khuhub.khu.ac.kr | ... | @@ -11,6 +11,7 @@ KHU-Hub repo: [khuhub.khu.ac.kr/2018102216/dev-profile](https://khuhub.khu.ac.kr |
| 11 | - [x] random quotes **_for developers_** to motivate you :sparkles: | 11 | - [x] random quotes **_for developers_** to motivate you :sparkles: |
| 12 | - [ ] the amount of commits you've done on [GitHub](https://github.com/) at a glance | 12 | - [ ] the amount of commits you've done on [GitHub](https://github.com/) at a glance |
| 13 | - [ ] your most-contributed project on GitHub | 13 | - [ ] your most-contributed project on GitHub |
| 14 | +- [x] today's trending repositories on GitHub | ||
| 14 | <br> | 15 | <br> |
| 15 | 16 | ||
| 16 | ### Additional Features | 17 | ### Additional Features | ... | ... |
| ... | @@ -2,26 +2,83 @@ import axios from "axios"; | ... | @@ -2,26 +2,83 @@ import axios from "axios"; |
| 2 | import passport from "passport"; | 2 | import passport from "passport"; |
| 3 | import User from "../models/User"; | 3 | import User from "../models/User"; |
| 4 | 4 | ||
| 5 | -const getQuote = async (req,res) =>{ | 5 | +const getQuote = async (req, res) => { |
| 6 | - const url = "http://quotes.stormconsultancy.co.uk/random.json"; | 6 | + const url = "http://quotes.stormconsultancy.co.uk/random.json"; |
| 7 | - const quoteData = await axios.get(url).then(function(response){ | 7 | + const quoteData = await axios.get(url).then(function (response) { |
| 8 | - return response.data; | 8 | + return response.data; |
| 9 | - }); | 9 | + }); |
| 10 | - const quote = quoteData.quote; | 10 | + const quote = quoteData.quote; |
| 11 | - const author = quoteData.author; | 11 | + const author = quoteData.author; |
| 12 | - return {quote,author}; | 12 | + return { quote, author }; |
| 13 | -} | 13 | +}; |
| 14 | - | 14 | + |
| 15 | -export const handleHome = async (req,res)=>{ | 15 | +const gitTrend = async (req, res) => { |
| 16 | - const quote = await getQuote(); | 16 | + const url = |
| 17 | - res.render("home",{pageTitle:"Home", quote:quote.quote, author:quote.author}); | 17 | + "https://api.trending-github.com/github/repositories?period=daily"; |
| 18 | -} | 18 | + const trendData = await axios.get(url).then(function (response) { |
| 19 | - | 19 | + return response.data; |
| 20 | - | 20 | + }); |
| 21 | -export const getUserDetail = async (req,res) =>{ | 21 | + const name0 = trendData[0].name; |
| 22 | - const quote = await getQuote(); | 22 | + const description0 = trendData[0].description; |
| 23 | - res.render("userDetail",{pagetTitle:"User Detail", quote:quote.quote, author:quote.author}) | 23 | + const Url0 = trendData[0].url; |
| 24 | -} | 24 | + const stars0 = trendData[0].stars; |
| 25 | + const name1 = trendData[1].name; | ||
| 26 | + const description1 = trendData[1].description; | ||
| 27 | + const Url1 = trendData[1].url; | ||
| 28 | + const stars1 = trendData[1].stars; | ||
| 29 | + const name2 = trendData[2].name; | ||
| 30 | + const description2 = trendData[2].description; | ||
| 31 | + const Url2 = trendData[2].url; | ||
| 32 | + const stars2 = trendData[2].stars; | ||
| 33 | + | ||
| 34 | + return { | ||
| 35 | + name0, | ||
| 36 | + description0, | ||
| 37 | + Url0, | ||
| 38 | + stars0, | ||
| 39 | + name1, | ||
| 40 | + description1, | ||
| 41 | + Url1, | ||
| 42 | + stars1, | ||
| 43 | + name2, | ||
| 44 | + description2, | ||
| 45 | + Url2, | ||
| 46 | + stars2, | ||
| 47 | + }; | ||
| 48 | +}; | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + | ||
| 52 | +export const handleHome = async (req, res) => { | ||
| 53 | + const quote = await getQuote(); | ||
| 54 | + const trend = await gitTrend(); | ||
| 55 | + res.render("home", { | ||
| 56 | + pageTitle: "Home", | ||
| 57 | + quote: quote.quote, | ||
| 58 | + author: quote.author, | ||
| 59 | + name0: trend.name0, | ||
| 60 | + description0: trend.description0, | ||
| 61 | + Url0: trend.Url0, | ||
| 62 | + stars0: trend.stars0, | ||
| 63 | + name1: trend.name1, | ||
| 64 | + description1: trend.description1, | ||
| 65 | + Url1: trend.Url1, | ||
| 66 | + stars1: trend.stars1, | ||
| 67 | + name2: trend.name2, | ||
| 68 | + description2: trend.description2, | ||
| 69 | + Url2: trend.Url2, | ||
| 70 | + stars2: trend.stars2, | ||
| 71 | + }); | ||
| 72 | +}; | ||
| 73 | + | ||
| 74 | +export const getUserDetail = async (req, res) => { | ||
| 75 | + const quote = await getQuote(); | ||
| 76 | + res.render("userDetail", { | ||
| 77 | + pagetTitle: "User Detail", | ||
| 78 | + quote: quote.quote, | ||
| 79 | + author: quote.author, | ||
| 80 | + }); | ||
| 81 | +}; | ||
| 25 | 82 | ||
| 26 | export const getEditProfile = async (req,res)=> { | 83 | export const getEditProfile = async (req,res)=> { |
| 27 | const{ | 84 | const{ |
| ... | @@ -67,23 +124,32 @@ export const postEditProfile = async (req,res) =>{ | ... | @@ -67,23 +124,32 @@ export const postEditProfile = async (req,res) =>{ |
| 67 | } | 124 | } |
| 68 | }; | 125 | }; |
| 69 | 126 | ||
| 70 | - | 127 | +export const getJoin = (req, res) => { |
| 71 | -export const getJoin = (req,res)=>{ | 128 | + res.render("join", { pageTitle: "Join" }); |
| 72 | - res.render("join",{pageTitle: "Join"}); | ||
| 73 | }; | 129 | }; |
| 74 | 130 | ||
| 75 | -export const getLogin = (req,res)=>{ | 131 | +export const getLogin = (req, res) => { |
| 76 | - res.render("login",{pageTitle: "Login"}); | 132 | + res.render("login", { pageTitle: "Login" }); |
| 77 | }; | 133 | }; |
| 78 | 134 | ||
| 79 | -export const handleUsers = (req,res)=>{ | 135 | +export const handleUsers = (req, res) => { |
| 80 | - res.render("users",{pageTitle:"Users"}); | 136 | + res.render("users", { pageTitle: "Users" }); |
| 81 | -} | 137 | +}; |
| 82 | 138 | ||
| 83 | -export const githubLogin = passport.authenticate("github", {scope: [ "user:email" ]}); | 139 | +export const githubLogin = passport.authenticate("github", { |
| 140 | + scope: ["user:email"], | ||
| 141 | +}); | ||
| 84 | 142 | ||
| 85 | -export const githubLoginCallback = async (_, __, profile, done) =>{ | 143 | +export const githubLoginCallback = async (_, __, profile, done) => { |
| 86 | - const {_json: {id:githubId, login:githubName, avatar_url:avatarUrl, name, email}} = profile; | 144 | + const { |
| 145 | + _json: { | ||
| 146 | + id: githubId, | ||
| 147 | + login: githubName, | ||
| 148 | + avatar_url: avatarUrl, | ||
| 149 | + name, | ||
| 150 | + email, | ||
| 151 | + }, | ||
| 152 | + } = profile; | ||
| 87 | 153 | ||
| 88 | try{ | 154 | try{ |
| 89 | const user = await User.findOne({githubId}); | 155 | const user = await User.findOne({githubId}); |
| ... | @@ -107,12 +173,12 @@ export const githubLoginCallback = async (_, __, profile, done) =>{ | ... | @@ -107,12 +173,12 @@ export const githubLoginCallback = async (_, __, profile, done) =>{ |
| 107 | } | 173 | } |
| 108 | }; | 174 | }; |
| 109 | 175 | ||
| 110 | -export const postGithubLogin = (req,res)=>{ | 176 | +export const postGithubLogin = (req, res) => { |
| 111 | - const userId = req.user.id; | 177 | + const userId = req.user.id; |
| 112 | - res.redirect(`/users/${userId}`); | 178 | + res.redirect(`/users/${userId}`); |
| 113 | -} | 179 | +}; |
| 114 | 180 | ||
| 115 | -export const logout = (req,res)=>{ | ||
| 116 | - req.logout(); | ||
| 117 | - res.redirect("/"); | ||
| 118 | -} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 181 | +export const logout = (req, res) => { | ||
| 182 | + req.logout(); | ||
| 183 | + res.redirect("/"); | ||
| 184 | +}; | ... | ... |
| ... | @@ -2,15 +2,13 @@ import express from "express"; | ... | @@ -2,15 +2,13 @@ import express from "express"; |
| 2 | import { getEditProfile, getUserDetail, handleUsers, postEditProfile } from "../controllers/userController"; | 2 | import { getEditProfile, getUserDetail, handleUsers, postEditProfile } from "../controllers/userController"; |
| 3 | import { onlyPrivate, uploadFiles } from "../middlewares"; | 3 | import { onlyPrivate, uploadFiles } from "../middlewares"; |
| 4 | 4 | ||
| 5 | - | ||
| 6 | const userRouter = express.Router(); | 5 | const userRouter = express.Router(); |
| 7 | 6 | ||
| 8 | -userRouter.get("/",handleUsers); | 7 | +userRouter.get("/", handleUsers); |
| 9 | 8 | ||
| 10 | userRouter.get("/edit-profile", onlyPrivate, getEditProfile); | 9 | userRouter.get("/edit-profile", onlyPrivate, getEditProfile); |
| 11 | userRouter.post("/edit-profile", onlyPrivate, uploadFiles.single("photo"),postEditProfile); | 10 | userRouter.post("/edit-profile", onlyPrivate, uploadFiles.single("photo"),postEditProfile); |
| 12 | 11 | ||
| 13 | userRouter.get("/:id", getUserDetail); | 12 | userRouter.get("/:id", getUserDetail); |
| 14 | 13 | ||
| 15 | - | ||
| 16 | -export default userRouter; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 14 | +export default userRouter; | ... | ... |
| ... | @@ -14,4 +14,15 @@ block content | ... | @@ -14,4 +14,15 @@ block content |
| 14 | |#{' '} | 14 | |#{' '} |
| 15 | a(href="/login") Login | 15 | a(href="/login") Login |
| 16 | else | 16 | else |
| 17 | - a(href=`/users/${loggedUser._id}`) My profile | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 17 | + a(href=`/users/${loggedUser._id}`) My profile | ||
| 18 | + | ||
| 19 | + .gotoTrend(style="border: 1px solid blue;") | ||
| 20 | + p(style='color: orange;') Trending Repositories: | ||
| 21 | + br | ||
| 22 | + a(href=Url0, style={color:'grey'}) | ||
| 23 | + p=name0+": "+description0+" - "+stars0+" stars" | ||
| 24 | + a(href=Url1, style={color:'grey'}) | ||
| 25 | + p=name1+": "+description1+" - "+stars1+" stars" | ||
| 26 | + a(href=Url2, style={color:'grey'}) | ||
| 27 | + p=name2+": "+description2+" - "+stars2+" stars" | ||
| 28 | + | ... | ... |
-
Please register or login to post a comment