Skip to content

Commit

Permalink
Merge branch 'dev' into feat/signUpandOut
Browse files Browse the repository at this point in the history
  • Loading branch information
minjman2659 authored Aug 27, 2021
2 parents 24ad497 + 646cd0c commit dcf4dcd
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 72 deletions.
158 changes: 98 additions & 60 deletions client/src/comp/SearchResult.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,103 @@
import React from "react";
import styled from "styled-components";
import empty from "../empty.png"
import empty from "../empty.png";

function SearchResult({data}){
// let result = data.sort((a,b)=>a.thumbsup-b.thumbsup).reverse().slice(0,3)
let result = []
const ResultList = styled.ul`
margin-top:20px;
width:75%;
margin: 0 auto;
display:flex;
flex-direction:column;
li{
display:flex;
height:8vh;
margin-top:2vh;
border:2px solid #000;
border-radius:40px;
text-align:center;
line-height:8vh;
background-color:#ffff8d;
p{
flex:1 1 auto
}
p:nth-child(2){
flex: 3 1 auto
}
}
li:nth-child(1){
margin-top:0px;
}
`
const EmptyResult = styled.div`
text-align:center;
> img{
width:20vh;
height:20vh;
}
`
return(
<>
{result.length===0?
<EmptyResult>
<img src={empty} alt="empty"/>
<p>검색 결과가 없습니다.</p>
</EmptyResult>
:
<ResultList>
{result.map((ele,idx)=>{
return (
<li key={idx}>
<p>{ele.wordName}</p>
<p>{ele.wordMean}</p>
<p>{ele.thumbsup}</p>
</li>
)
})}
</ResultList>
}
</>
)
function SearchResult({ data }) {
let result = data
.sort((a, b) => a.thumbsup - b.thumbsup)
.reverse()
.slice(0, 3);
//let result = [];
const ResultList = styled.ul`
margin-top: 20px;
width: 75%;
margin: 0 auto;
display: flex;
flex-direction: column;
li {
display: flex;
height: 8vh;
margin-top: 2vh;
border: 2px solid #000;
border-radius: 40px;
text-align: center;
line-height: 8vh;
background-color: #ffff8d;
p {
flex: 1 1 auto;
}
p:nth-child(2) {
flex: 3 1 auto;
}
}
li:nth-child(1) {
margin-top: 0px;
}
`;
const EmptyResult = styled.div`
text-align: center;
> img {
width: 20vh;
height: 20vh;
}
`;
const BtnWrap = styled.div`
width: 30%;
margin: 3% auto;
`;
const NewMoreBtn = styled.button`
width: 15vh;
height: 5vh;
border-radius: 5vh;
border: 2px solid black;
background-color: black;
color: white;
margin-left: 10%;
font-size: 0.8rem;
transition: 0.2s;
:hover {
background-color: white;
color: black;
cursor: pointer;
}
`;

return (
<>
{result.length === 0 ? (
<div>
<EmptyResult>
<img src={empty} alt="empty" />
<p>검색 결과가 없습니다.</p>
</EmptyResult>

<BtnWrap>
<NewMoreBtn>새로 만들기</NewMoreBtn>
<NewMoreBtn>더보기</NewMoreBtn>
</BtnWrap>
</div>
) : (
<div>
<ResultList>
{result.map((ele, idx) => {
return (
<li key={idx}>
<p>{ele.wordName}</p>
<p>{ele.wordMean}</p>
<p>{ele.thumbsup}</p>
</li>
);
})}
</ResultList>

<BtnWrap>
<NewMoreBtn>새로 만들기</NewMoreBtn>
<NewMoreBtn>더보기</NewMoreBtn>
</BtnWrap>
</div>
)}
</>
);
}

export default SearchResult;
export default SearchResult;
20 changes: 10 additions & 10 deletions client/src/pages/Search.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import SearchInput from "../comp/SearchInput"
import SearchResult from "../comp/SearchResult"
import SearchInput from "../comp/SearchInput";
import SearchResult from "../comp/SearchResult";
import dummyData from "../dummy/dummyData";

function Search (){
return(
<section>
<SearchInput />
<SearchResult data={dummyData.word}/>
</section>
)
function Search() {
return (
<section>
<SearchInput />
<SearchResult data={dummyData.word} />
</section>
);
}

export default Search;
export default Search;
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/controllers/search/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { content } = require("../../models");

module.exports = {
post: async (req, res) => {
try {
Expand Down
31 changes: 29 additions & 2 deletions server/controllers/user/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
const { user } = require("../../models");
const { generateAccessToken } = require("../tokenFunction/accessToken");
const { generateRefreshToken, sendRefreshToken } = require("../tokenFunction/refreshToken");

module.exports = {
post: (req, res) => {
res.send("This is user/login");
post: async (req, res) => {
try {
const { email, password } = req.body;
if(!email || !password) {
res.status(401).json({ message: "Invalid User" });
}
const findData = await user.findOne({
where: {email: email, password: password}
});
if(!findData) {
res.status(401).json({ message: "Invalid User" });
} else {
delete findData.dataValues.password;
const accessToken = generateAccessToken(findData.dataValues);
const refreshToken = generateRefreshToken(findData.dataValues);
sendRefreshToken(res, refreshToken);
res.status(200).json({
accessToken: accessToken,
userInfo: findData.dataValues,
message: "ok"
});
}
} catch(error) {
console.log(error);
res.status(500).json({ message: "Server Error" });
}
}
}

0 comments on commit dcf4dcd

Please sign in to comment.