Skip to content

Commit

Permalink
feat : 게시글 삭제 추가
Browse files Browse the repository at this point in the history
DeleteMapping 추가
글 번호가 pk 이므로 중복되지 않기 때문에 글 번호로 삭제함
  • Loading branch information
DOEKYONG committed Apr 11, 2023
1 parent f0031a8 commit e892b59
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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:/";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ public Article findByIdx(int idx) {

@Override
public void update(Article article) {}

@Override
public void delete(int index) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface ArticleRepository {
Article findByIdx(int idx);

void update(Article article);

void delete(int index);
}
5 changes: 5 additions & 0 deletions src/main/java/kr/codesqaud/cafe/service/ArticleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/templates/qna/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ <h2 class="qna-title">{{article.title}}</h2>
<a class="link-modify-article" href="/article/update/{{article.index}}">수정</a>
</li>
<li>
<form class="form-delete" action="/questions/423" method="POST">
<form class="form-delete" action="/article/delete/{{article.index}}" method="POST">
<input type="hidden" name="_method" value="DELETE" />
<input type="hidden" name="_method" value="DELETE">
<button class="link-delete-article" type="submit">삭제</button>
</form>
Expand Down

0 comments on commit e892b59

Please sign in to comment.