Lee SeJin

Update getting user repository

......@@ -119,4 +119,5 @@ dist
package-lock.json
/uploads
/assets
build
\ No newline at end of file
build
.vscode
\ No newline at end of file
......
......@@ -9,7 +9,7 @@ const handleRepo = (list) =>{
list.forEach(element => {
const anchor = document.createElement("a");
anchor.href = element.url;
anchor.target = "_blank"
anchor.target = "_blank";
anchor.innerHTML = `<span class="repoName">${element.name}</span> : ${element.description} - <span class="repoStar">${element.stars} stars</span>`
trendRepoBox.appendChild(anchor);
});
......
......@@ -6,8 +6,7 @@ const totalContributionIndicator = document.getElementById(
);
const userCharacterBox = document.querySelector(".user-status__character");
const userRepoBox = document.querySelector(".user-repo");
const URL =
"https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2";
const githubNickname = document.getElementById("jsGithubNickname");
const handleImage = () => {
const total = totalContributionIndicator.innerText;
......@@ -41,16 +40,16 @@ const handleRepo = (list) => {
});
};
const getGithubRepo = () => {
const response = fetch(URL)
.then(function (response) {
return response.json();
})
.then(function (data) {
const trendRepoList = data.slice(0, 2);
handleRepo(trendRepoList);
});
};
const getGithubRepo = () =>{
const nickname = githubNickname.innerText;
const userId = window.location.href.split("/users/")[1];
const response = fetch(`/users/${userId}/repo`,{headers:{nickname}}).then(function(reponse){
const data = reponse.json();
return data
}).then(function(data){
handleRepo(data);
})
}
const init = () => {
handleImage();
......
......@@ -4,9 +4,9 @@
flex-direction: column;
padding: 30px;
img {
width: 100px;
height: 100px;
object-fit: cover;
width: 176px;
height: 220px;
object-fit: contain;
}
.fileUpload {
display: flex;
......
......@@ -96,16 +96,21 @@
font-size: 1.2rem;
overflow-x: scroll;
}
i {
background: transparent;
button {
border: none;
background: none;
padding: 0;
i {
font-size: 1.5rem;
margin: 3px;
background: transparent;
border: none;
i {
font-size: 1.5rem;
margin: 3px;
}
}
i:hover {
cursor: pointer;
}
}
i:hover {
cursor: pointer;
}
}
.home-search__form:hover {
......
......@@ -48,7 +48,6 @@
}
.boxEffect {
z-index: -1;
content: "";
bottom: 15px;
right: 10px;
......@@ -85,9 +84,9 @@
.user-profile__column {
img {
width: 120px;
height: 120px;
object-fit: cover;
width: 176px;
height: 220px;
object-fit: contain;
margin: 5px;
}
.user-profile__link {
......@@ -117,6 +116,12 @@
.user-profile__tech {
display: flex;
}
.user-profile__introduction {
width: 100%;
overflow: hidden;
word-wrap: break-word;
word-break: break-all;
}
ul {
display: flex;
flex-direction: column;
......@@ -212,7 +217,7 @@
max-width: 200px;
height: auto;
object-fit: cover;
margin-top: px;
margin-top: 20px;
}
}
}
......
......@@ -27,18 +27,13 @@ export const getUserDetail = async (req, res) => {
const id = req.params.id;
const quote = await getQuote();
const user = await User.findById(id);
const repo = await getRepos();
const totalCon = await getContributions(user.githubName);
res.render("userDetail", {
pagetTitle: "User Detail",
quote: quote.quote,
author: quote.author,
user,
fitstRepoName: repo.fitstRepoName,
firstRepoUrl: repo.firstRepoUrl,
secondRepoName: repo.secondRepoName,
secondRepoUrl: repo.secondRepoUrl,
totalContributions: totalCon,
totalContributions: totalCon
});
} catch (error) {
console.log(error);
......@@ -87,7 +82,7 @@ export const postEditProfile = async (req, res) => {
);
req.session.passport.user = updatedUser;
//console.log(updatedUser);
res.redirect("/users/edit-profile");
res.redirect(`/users/${id}`);
} catch (error) {
console.log(error);
res.redirect("/");
......@@ -135,7 +130,7 @@ export const githubLoginCallback = async (_, __, profile, done) => {
avatarUrl,
githubUrl,
name,
email,
email
});
return done(null, newUser);
}
......@@ -154,25 +149,6 @@ export const logout = (req, res) => {
res.redirect("/");
};
const getRepos = async () => {
const url =
"https://api.github.com/users/lsj8706/repos?sort=updated&per_page=2";
const latelyRepos = await axios.get(url).then(function (response) {
return response.data;
});
const fitstRepoName = latelyRepos[0].name;
const secondRepoName = latelyRepos[1].name;
const firstRepoUrl = latelyRepos[0].html_url;
const secondRepoUrl = latelyRepos[1].html_url;
return {
fitstRepoName,
firstRepoUrl,
secondRepoName,
secondRepoUrl,
};
};
const getContributions = async (username) => {
const token = process.env.GH_SECRET_SH;
const headers = {
......@@ -192,3 +168,21 @@ const getContributions = async (username) => {
.totalContributions;
return total;
};
export const getRepos = async(req,res) =>{
try{
const githubNickname = req.headers.nickname
const URL = `https://api.github.com/users/${githubNickname}/repos?sort=updated&per_page=2`;
const response = await fetch(URL,{
headers: {
authorization: `token ${process.env.GH_SECRET_SH}`
}
}).then(function (response) {
return response.json();
}).then(function (data) {
return res.send(data);
});
}catch(error){
console.log(error);
}
}
\ No newline at end of file
......
import express from "express";
import {
getEditProfile,
getRepos,
getUserDetail,
handleUsers,
postEditProfile,
......@@ -20,5 +21,6 @@ userRouter.post(
);
userRouter.get("/:id", getUserDetail);
userRouter.get("/:id/repo", getRepos);
export default userRouter;
......
......@@ -18,7 +18,8 @@ block content
a(href="https://google.com" target="_blank")
img(src="https://user-images.githubusercontent.com/48612525/86507657-d54fbd80-bd8e-11ea-866b-ac26496481ae.png" alt="google icon")
input(type="text" id="jsInput" placeholder="Google 검색")
i.fa.fa-search(aria-hidden="true")
button
i.fa.fa-search(aria-hidden="true")
.home-quote
h2=quote
......
......@@ -12,7 +12,7 @@ block content
img(src=`/${user.avatarUrl}`)
.user-profile__link
a(href=user.githubUrl target="_blank") GitHub
i.fab.fa-github
i.fab.fa-github
a(href=`//${user.blogUrl}` target="_blank") Blog
i.fas.fa-link
.user-profile__column
......@@ -24,7 +24,7 @@ block content
h3 &nbsp; &nbsp; &nbsp;&nbsp;GITHUB
br
|NICKNAME
h4=user.githubName
h4#jsGithubNickname=user.githubName
.user-profile__email
h3 EMAIL
h4=user.email
......