Lee SeJin

quote api update

......@@ -15,6 +15,7 @@
"@babel/core": "^7.14.0",
"@babel/node": "^7.13.13",
"@babel/preset-env": "^7.14.1",
"axios": "^0.21.1",
"express": "^4.17.1",
"morgan": "^1.10.0",
"nodemon": "^2.0.7",
......
export const handleHome = (req,res)=>{
const list1 = [1,2,3,4,5]
res.render("home",{pageTitle:"Home",list1});
import axios from "axios";
const getQuote = async (req,res) =>{
const url = "http://quotes.stormconsultancy.co.uk/random.json";
const quoteData = await axios.get(url).then(function(response){
return response.data;
});
const quote = quoteData.quote;
const author = quoteData.author;
return {quote,author};
}
export const handleHome = async (req,res)=>{
const quote = await getQuote();
res.render("home",{pageTitle:"Home", quote:quote.quote, author:quote.author});
}
export const getUserDetail = async (req,res) =>{
const quote = await getQuote();
res.render("userDetail",{pagetTitle:"User Detail", quote:quote.quote, author:quote.author})
}
export const getEditProfile = (req,res)=> res.render("editProfile",{pageTitle:"Edit Profile"});
export const postEditProfile = (req,res) =>{
console.log(req.body);
res.redirect("/users/edit-profile");
};
export const getJoin = (req,res)=>{
res.render("join",{pageTitle: "Join"});
};
export const getLogin = (req,res)=>{
res.render("login",{pageTitle: "Login"});
};
export const handleUsers = (req,res)=>{
res.render("users",{pageTitle:"Users"});
}
\ No newline at end of file
}
......
import express from "express";
import { handleHome } from "../controllers/userController";
import { getJoin, getLogin, handleHome } from "../controllers/userController";
const globalRouter = express.Router();
globalRouter.get("/",handleHome);
globalRouter.get("/join",(req,res)=>res.render("join"));
globalRouter.get("/login",(req,res)=>res.render("login"));
globalRouter.get("/join", getJoin);
globalRouter.get("/login",getLogin);
export default globalRouter;
\ No newline at end of file
......
import express from "express";
import { handleUsers } from "../controllers/userController";
import { getEditProfile, getUserDetail, handleUsers, postEditProfile } from "../controllers/userController";
const userRouter = express.Router();
userRouter.get("/",handleUsers);
userRouter.get("/edit-profile",(req,res)=>res.render("editProfile"));
userRouter.get("/:id",(req,res)=>res.render("userDetail"));
userRouter.get("/edit-profile", getEditProfile);
userRouter.post("/edit-profile", postEditProfile);
userRouter.get("/:id", getUserDetail);
export default userRouter;
\ No newline at end of file
......
......@@ -13,6 +13,8 @@ app.set("view engine","pug");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "static")));
app.use(morgan("dev"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(localsMiddleware);
......@@ -24,3 +26,4 @@ app.use("/users", userRouter);
const handleListening = () => console.log(`✅ Server running : http://localhost:${PORT}`);
app.listen(PORT, handleListening);
......
h1 edit Profile
\ No newline at end of file
extends layouts/main
block content
.form-container
form(action="/users/edit-profile", method="POST", enctype="application/json")
.fileUpload
label(for="picture") Picture
input(type="file", id="picture", name="picture", accept="image/*")
input(type="text", placeholder="Name", name="name")
input(type="text", placeholder="Github Id", name="githubId")
input(type="email", placeholder="Email", name="email")
input(type="text", placeholder="School", name="school")
textarea(name="tech", placeholder="Add your Tech")
textarea(name="career", placeholder="Add your Career")
textarea(name="introduction", placeholder="Self introduction")
input(type="submit", value="Update Profile")
\ No newline at end of file
......
extends layouts/main
block content
h1 Welcome
each item in list1
span=item
\ No newline at end of file
block content
.home
.home-title
h2 Develop your value
h1 -Developer Profile-
h2=quote
h3=author
.home-link
a(href="/join") Join
a(href="/login") Login
......
h1 join
\ No newline at end of file
extends layouts/main
block content
i.fas.fa-location-arrow
h3 Start with GitHub!
button.login-github
a(href="#")
span
i.fab.fa-github
|Join with GitHub
\ No newline at end of file
......
doctype html
html
html
head
link(rel="stylesheet", href="https://use.fontawesome.com/releases/v5.15.2/css/all.css", integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu", crossorigin="anonymous")
link(rel="stylesheet", href="https://use.fontawesome.com/releases/v5.15.2/css/all.css", integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu", crossorigin="anonymous")
meta(charset="UTF-8")
title #{pageTitle} | #{siteName}
link(rel="stylesheet", href="/static/main.css")
link(rel="stylesheet", href="https://unpkg.com/mvp.css")
body
include ../partials/header
main
block content
include ../partials/footer
//- script(src="/static/main.js")
\ No newline at end of file
//- script(src="/static/main.js")
......
h1 Login
\ No newline at end of file
extends layouts/main
block content
i.fas.fa-location-arrow
h3 Login with GitHub!
button.login-github
a(href="#")
span
i.fab.fa-github
|Login with GitHub
\ No newline at end of file
......
footer.footer
.footer__icon
i.fas.fa-code-branch
span.footer__text dev-profile #{new Date().getFullYear()} ©
\ No newline at end of file
span.footer__text © dev-profile #{new Date().getFullYear()}
\ No newline at end of file
......
header.header
.header__wrapper
.header__column
ul
ul
li
a(href="/") Home
li
a(href="/join") Join
li
a(href="/login") Log In
\ No newline at end of file
a(href="/login") Log In
li
a(href="/users/edit-profile") Edit Profile
\ No newline at end of file
......
h1 User Detail
\ No newline at end of file
extends layouts/main
block content
h1 User Detail
.user-quote
h2=quote
h3=author
.user-profile
.user-profile__column
img(src="#")
.user-profile__link
a(href="#") Github
a(href="#") Blog
.user-profile__column
.user-profile__info
h3 NAME
h3 GITHUB NICKNAME
h3 EMAIL
h3 SCHOOL
h3 TECH
h3 CAREER
h3 SELF-INTRODUCTION
.user-status
.user-status__contributions
img(src="http://ghchart.rshah.org/lsj8706" alt="Name Your Github chart")
.user-status__character
h3 Your step | commit numbers
img(src="https://preview.free3d.com/img/2019/12/2269306250288170045/1oe8ymrc-900.jpg" alt="character" style="height:200px; width:250px;")
.user-repositories
.user-repo
h3 REPO 1
\ No newline at end of file
......