From e892b5981f27ea82a9f3e67d4b94d0e90b132ce3 Mon Sep 17 00:00:00 2001 From: DOEKYONG Date: Tue, 11 Apr 2023 18:54:18 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EC=B6=94=EA=B0=80=20DeleteMapping=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EA=B8=80=20=EB=B2=88=ED=98=B8=EA=B0=80=20?= =?UTF-8?q?pk=20=EC=9D=B4=EB=AF=80=EB=A1=9C=20=EC=A4=91=EB=B3=B5=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EA=B8=B0=20=EB=95=8C=EB=AC=B8=EC=97=90=20?= =?UTF-8?q?=EA=B8=80=20=EB=B2=88=ED=98=B8=EB=A1=9C=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codesqaud/cafe/controller/ArticleController.java | 12 +++++++----- .../article/repository/ArticleJdbcRepository.java | 8 ++++++++ .../article/repository/ArticleMemoryRepository.java | 3 +++ .../domain/article/repository/ArticleRepository.java | 2 ++ .../kr/codesqaud/cafe/service/ArticleService.java | 5 +++++ src/main/resources/templates/qna/show.html | 3 ++- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/kr/codesqaud/cafe/controller/ArticleController.java b/src/main/java/kr/codesqaud/cafe/controller/ArticleController.java index 6019c0258..ab7b2a77e 100644 --- a/src/main/java/kr/codesqaud/cafe/controller/ArticleController.java +++ b/src/main/java/kr/codesqaud/cafe/controller/ArticleController.java @@ -2,14 +2,10 @@ import kr.codesqaud.cafe.domain.article.Article; import kr.codesqaud.cafe.dto.ArticleFormDto; -import kr.codesqaud.cafe.dto.LoginSessionDto; import kr.codesqaud.cafe.service.ArticleService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpSession; @@ -63,4 +59,10 @@ public String putUpdate(@PathVariable int index,ArticleFormDto dto){ return "redirect:/article/show/"+index; } + @DeleteMapping("/article/delete/{index}") + public String delete(@PathVariable int index){ + articleService.delete(index); + return "redirect:/"; + } + } diff --git a/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleJdbcRepository.java b/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleJdbcRepository.java index 999bd1524..c5b08695e 100644 --- a/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleJdbcRepository.java +++ b/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleJdbcRepository.java @@ -51,4 +51,12 @@ public void update(Article article) { ,article.getTitle(),article.getContents(),article.getIndex() ); } + + @Override + public void delete(int index) { + jdbcTemplate.update( + "DELETE FROM ARTICLES WHERE IDX = ?" + ,index + ); + } } \ No newline at end of file diff --git a/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleMemoryRepository.java b/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleMemoryRepository.java index d77a7681f..aabc1ac4d 100644 --- a/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleMemoryRepository.java +++ b/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleMemoryRepository.java @@ -26,4 +26,7 @@ public Article findByIdx(int idx) { @Override public void update(Article article) {} + + @Override + public void delete(int index) {} } diff --git a/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleRepository.java b/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleRepository.java index 9aac75afe..56836f09a 100644 --- a/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleRepository.java +++ b/src/main/java/kr/codesqaud/cafe/domain/article/repository/ArticleRepository.java @@ -12,4 +12,6 @@ public interface ArticleRepository { Article findByIdx(int idx); void update(Article article); + + void delete(int index); } diff --git a/src/main/java/kr/codesqaud/cafe/service/ArticleService.java b/src/main/java/kr/codesqaud/cafe/service/ArticleService.java index 9604bbdc8..00bec9ad7 100644 --- a/src/main/java/kr/codesqaud/cafe/service/ArticleService.java +++ b/src/main/java/kr/codesqaud/cafe/service/ArticleService.java @@ -67,4 +67,9 @@ public boolean update(int index, ArticleFormDto dto) { articleRepository.update(article); return false; } + + public boolean delete(int index) { + articleRepository.delete(index); + return true; + } } \ No newline at end of file diff --git a/src/main/resources/templates/qna/show.html b/src/main/resources/templates/qna/show.html index ab7bae9c5..ed241c87c 100644 --- a/src/main/resources/templates/qna/show.html +++ b/src/main/resources/templates/qna/show.html @@ -40,7 +40,8 @@

{{article.title}}

수정
  • -
    + +