Skip to content

Commit

Permalink
게시물 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
wjxor committed Jul 15, 2021
1 parent 267e534 commit dc7ef6f
Showing 1 changed file with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@
public class UsrArticleController {
private int articlesLastId;
private List<Article> articles;

public UsrArticleController() {
// 멤버변수 초기화
articlesLastId = 0;
articles = new ArrayList<>();

// 게시물 2개 생성
articles.add(new Article(++articlesLastId, "2020-12-12 12:12:12", "제목1", "내용1"));
articles.add(new Article(++articlesLastId, "2020-12-12 12:12:12", "제목2", "내용2"));
}

@RequestMapping("/usr/article/detail")
@ResponseBody
public Article showDetail(int id) {

return articles.get(id - 1);
}

@RequestMapping("/usr/article/list")
@ResponseBody
public List<Article> showList() {

return articles;
}

@RequestMapping("/usr/article/doAdd")
@ResponseBody
public Map<String, Object> doAdd(String regDate, String title, String body) {
Expand All @@ -49,7 +49,43 @@ public Map<String, Object> doAdd(String regDate, String title, String body) {
rs.put("resultCode", "S-1");
rs.put("msg", "성공하였습니다.");
rs.put("id", articlesLastId);

return rs;
}

@RequestMapping("/usr/article/doDelete")
@ResponseBody
public Map<String, Object> doDelete(int id) {
boolean deleteArticleRs = deleteArticle(id);

Map<String, Object> rs = new HashMap<>();

if (deleteArticleRs) {
rs.put("resultCode", "S-1");
rs.put("msg", "성공하였습니다.");
}

else {
rs.put("resultCode", "F-1");
rs.put("msg", "해당 게시물은 존재하지 않습니다.");
}

rs.put("id", id);

return rs;

}

private boolean deleteArticle(int id) {
for (Article article : articles) {
if (article.getId() == id) {
articles.remove(article);

return true;
}
}

return false;

}
}

0 comments on commit dc7ef6f

Please sign in to comment.