Skip to content
Snippets Groups Projects
Commit 0b36cffe authored by Hyun Woo Jeong's avatar Hyun Woo Jeong
Browse files

로그인, 검색 수정, 포스트 지우기 추가

parent 86cfc717
No related branches found
No related tags found
No related merge requests found
......@@ -82,6 +82,12 @@ router.get("/:id", async (req, res) => {
}
const articles = await articleService.findArticleById(req.params.id);
res.send(JSON.stringify(articles));
}).delete("/:id", async (req, res) => {
if (!req.session.sessionid) {
console.log("No session - del");
}
const articles = await articleService.deleteArticle(req.params.id);
res.send(JSON.stringify(articles));
});
router.post("/:id/comment", async (req, res) => {
......
......@@ -39,13 +39,14 @@ router.post('/login', async (req, res) => {
});
router.get("/logout", (req, res) => {
res.clearCookie('name');
if (req.session.sessionid) {
req.session.destroy((err) => {
if (err) {
console.log(err)
return;
}
});
res.clearCookie('name');
res.send(req.body.name);
} else {
res.send(req.body.name);
......
......@@ -4,6 +4,7 @@ import Article from '../components/Article.js';
import { UserContext, ArticleContext } from '../Context.js';
import MapLocator from '../components/MapForLoaction.js';
import Comment from '../components/Comment.js';
import cookie from 'react-cookies';
import axios from 'axios';
axios.defaults.withCredentials = true;
......@@ -12,7 +13,7 @@ function PostRead() {
let params = useParams();
const userContext = useContext(UserContext);
const articleContext = useContext(ArticleContext);
const userinfo = cookie.load('name')
const [article, setArticle] = useState(null)
const [inputComment, setInputComment] = useState("")
const [commentList, setCommentList] = useState("")
......@@ -85,6 +86,26 @@ function PostRead() {
});
};
function DelButton({isThatYou, target}){
function deleteArticle(){
console.log(target._id)
requestDeleteArticleById(target._id).then(res => {
alert("The article is successfully deleted");
MoveTo('/')
})
.catch(err => {
console.error(err);
});
}
if (isThatYou) {
return(<button onClick={deleteArticle}>지우기</button>)
}
else {
return null
}
}
if (article) {
return(
<>
......@@ -92,7 +113,11 @@ function PostRead() {
<MapLocator loc={{lat: article.latitude, lng: article.longitude}} keyword={article.keyword}></MapLocator>
<div>
<Article data={article}></Article>
<button onClick={SetLike}>조와요</button>
<div style={{display: 'flex'}}>
<button onClick={SetLike}>조와요</button>
<DelButton isThatYou={userinfo.id === article.author.user_id} target={article}></DelButton>
</div>
</div>
</div>
<form onSubmit={onSubmit}>
......@@ -130,4 +155,12 @@ async function requestLoadArticleById(id) {
return response;
}
async function requestDeleteArticleById(id) {
const response = await axios({
url: `http://localhost:8080/article/${id}`, // 통신할 웹문서
method: 'delete', // 통신할 방식
});
return response;
}
export default PostRead;
\ No newline at end of file
......@@ -29,11 +29,11 @@ function Search(props) {
MoveTo('/login')
}
else {
requestLoadArticle()
.then((response) => {
console.log(response)
setArticleList(response.data)
})
// requestLoadArticle()
// .then((response) => {
// console.log(response)
// setArticleList(response.data)
// })
}
})
.catch((response)=>{
......@@ -69,14 +69,22 @@ function Search(props) {
<div style={{display: 'flex'}}>
<div className="search">
<h1>검색페이지입니다.</h1>
<p>무엇을 드시고 싶나요? 어디 계시죠?</p>
<SearchMap loc={location} setLoc={setLocation}></SearchMap>
<form onSubmit={onSubmit} style={{display: 'flex'}}>
<input readonly value={location.keyword} type="text"></input>
<input type="submit"></input>
</form>
</div>
<div className="searchresult">
<p>선택한 키워드로 검색합니다.</p>
<form onSubmit={onSubmit} style={{display: 'flex'}}>
<input readonly value={location.keyword} type="text"></input>
<button type="submit">검색!</button>
<button type="button" onClick={()=>{
setLocation({
keyword: "",
center: { lat: null, lng: null }
})}}>선택 해제</button>
</form>
<h1>검색결과 {listItem.length} 확인</h1>
{listItem}
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment