Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • 2023_2_webpromgramming_8/sicdorak
1 result
Show changes
Commits on Source (3)
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
|Method|Path|Message Format(JSON)|설명| |Method|Path|Message Format(JSON)|설명|
|---|---|---|---| |---|---|---|---|
|POST|/article|{<br>"title": string,<br>"content": string,<br>"img": string[],<br>"keyword": string,<br>"latitiude":number,<br>"longitude": number<br>}|게시글 작성 요청| |POST|/article|{<br>"title": string,<br>"content": string,<br>"img": string[],<br>"keyword": string,<br>"latitiude":number,<br>"longitude": number<br>}|게시글 작성 요청|
|DELETE|/article/[id]||특정 게시글 삭제 요청|
|GET|/article||전체 게시글 요청| |GET|/article||전체 게시글 요청|
|GET|/article/[id]||특정 게시글 요청| |GET|/article/[id]||특정 게시글 요청|
|GET|/article/search/[keyword]||키워드로 게시글 검색 요청| |GET|/article/search/[keyword]||키워드로 게시글 검색 요청|
......
...@@ -82,6 +82,12 @@ router.get("/:id", async (req, res) => { ...@@ -82,6 +82,12 @@ router.get("/:id", async (req, res) => {
} }
const articles = await articleService.findArticleById(req.params.id); const articles = await articleService.findArticleById(req.params.id);
res.send(JSON.stringify(articles)); 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) => { router.post("/:id/comment", async (req, res) => {
......
...@@ -39,13 +39,14 @@ router.post('/login', async (req, res) => { ...@@ -39,13 +39,14 @@ router.post('/login', async (req, res) => {
}); });
router.get("/logout", (req, res) => { router.get("/logout", (req, res) => {
res.clearCookie('name');
if (req.session.sessionid) { if (req.session.sessionid) {
req.session.destroy((err) => { req.session.destroy((err) => {
if (err) { if (err) {
console.log(err)
return; return;
} }
}); });
res.clearCookie('name');
res.send(req.body.name); res.send(req.body.name);
} else { } else {
res.send(req.body.name); res.send(req.body.name);
......
...@@ -4,6 +4,7 @@ import Article from '../components/Article.js'; ...@@ -4,6 +4,7 @@ import Article from '../components/Article.js';
import { UserContext, ArticleContext } from '../Context.js'; import { UserContext, ArticleContext } from '../Context.js';
import MapLocator from '../components/MapForLoaction.js'; import MapLocator from '../components/MapForLoaction.js';
import Comment from '../components/Comment.js'; import Comment from '../components/Comment.js';
import cookie from 'react-cookies';
import axios from 'axios'; import axios from 'axios';
axios.defaults.withCredentials = true; axios.defaults.withCredentials = true;
...@@ -12,7 +13,7 @@ function PostRead() { ...@@ -12,7 +13,7 @@ function PostRead() {
let params = useParams(); let params = useParams();
const userContext = useContext(UserContext); const userContext = useContext(UserContext);
const articleContext = useContext(ArticleContext); const articleContext = useContext(ArticleContext);
const userinfo = cookie.load('name')
const [article, setArticle] = useState(null) const [article, setArticle] = useState(null)
const [inputComment, setInputComment] = useState("") const [inputComment, setInputComment] = useState("")
const [commentList, setCommentList] = useState("") const [commentList, setCommentList] = useState("")
...@@ -85,6 +86,26 @@ function PostRead() { ...@@ -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) { if (article) {
return( return(
<> <>
...@@ -92,7 +113,11 @@ function PostRead() { ...@@ -92,7 +113,11 @@ function PostRead() {
<MapLocator loc={{lat: article.latitude, lng: article.longitude}} keyword={article.keyword}></MapLocator> <MapLocator loc={{lat: article.latitude, lng: article.longitude}} keyword={article.keyword}></MapLocator>
<div> <div>
<Article data={article}></Article> <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>
</div> </div>
<form onSubmit={onSubmit}> <form onSubmit={onSubmit}>
...@@ -130,4 +155,12 @@ async function requestLoadArticleById(id) { ...@@ -130,4 +155,12 @@ async function requestLoadArticleById(id) {
return response; return response;
} }
async function requestDeleteArticleById(id) {
const response = await axios({
url: `http://localhost:8080/article/${id}`, // 통신할 웹문서
method: 'delete', // 통신할 방식
});
return response;
}
export default PostRead; export default PostRead;
\ No newline at end of file
...@@ -29,11 +29,11 @@ function Search(props) { ...@@ -29,11 +29,11 @@ function Search(props) {
MoveTo('/login') MoveTo('/login')
} }
else { else {
requestLoadArticle() // requestLoadArticle()
.then((response) => { // .then((response) => {
console.log(response) // console.log(response)
setArticleList(response.data) // setArticleList(response.data)
}) // })
} }
}) })
.catch((response)=>{ .catch((response)=>{
...@@ -69,14 +69,22 @@ function Search(props) { ...@@ -69,14 +69,22 @@ function Search(props) {
<div style={{display: 'flex'}}> <div style={{display: 'flex'}}>
<div className="search"> <div className="search">
<h1>검색페이지입니다.</h1> <h1>검색페이지입니다.</h1>
<p>무엇을 드시고 싶나요? 어디 계시죠?</p>
<SearchMap loc={location} setLoc={setLocation}></SearchMap> <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>
<div className="searchresult"> <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> <h1>검색결과 {listItem.length} 확인</h1>
{listItem} {listItem}
</div> </div>
......