diff --git a/backend/src/article/articleController.js b/backend/src/article/articleController.js index 78f6a888824a49cc0ad4db29fb79cfd7caa91f44..04e4683b49d3b15cf8da81111e525c4ae1659dcc 100644 --- a/backend/src/article/articleController.js +++ b/backend/src/article/articleController.js @@ -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) => { diff --git a/backend/src/auth/authController.js b/backend/src/auth/authController.js index fe6133b6d6d9a8a0d3308a62ebd3674cb6e6e823..34ee420d6fe1bd62c4300a684c42d7c79384bcf8 100644 --- a/backend/src/auth/authController.js +++ b/backend/src/auth/authController.js @@ -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); diff --git a/frontend/src/pages/PostRead.js b/frontend/src/pages/PostRead.js index c03632b88ced4b35b4562970b4d3a72d645d31dd..af80f9e8d85f5e74b9b5ae753d2ccc4960112705 100644 --- a/frontend/src/pages/PostRead.js +++ b/frontend/src/pages/PostRead.js @@ -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 diff --git a/frontend/src/pages/Search.js b/frontend/src/pages/Search.js index 7c4cdeea28518c4ca7e9fbb6762d56a020bcec69..5f01b8213624c0cac1c06d0befe20e0d585e0742 100644 --- a/frontend/src/pages/Search.js +++ b/frontend/src/pages/Search.js @@ -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>