-
Notifications
You must be signed in to change notification settings - Fork 13
[core] (step-5) 게시글 권한 부여 [게시글 열람, 수정, 삭제 권한] #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
meena2003
wants to merge
11
commits into
codesquad-members-2023:core
Choose a base branch
from
meena2003:feature5
base: core
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
53fa560
feat(mission5): 게시글 작성시 작성자 입력 필드 삭제
meena2003 0c45ea9
feat(mission5): 로그인 이전에 게시글쓰기 시도시 로그인 페이지로 이동하는 기능 구현
meena2003 7af2c75
feat(mission5): 로그인 이전에 게시글 조회시 로그인 화면으로 이동하는 기능 구현
meena2003 c75d94a
feat(mission5): 로그인 한 닉네임과 글 작성 닉네임이 일치하는 경우에 수정 페이지로 이동 기능 구현.
meena2003 8a0a81d
fix(mission5): db/be-java-cafe.trace.db 파일 추적 안하기 위해 .gitignore 파일에 등록
meena2003 ff6233d
feat(mission5): 게시글 수정 시 기존 게시글의 제목과 본문 내용을 가져와서 출력하는 기능 구현
meena2003 756b58d
feat(mission5): 게시글 수정 기능 구현
meena2003 d53f9cc
fix(mission5): 새로운 게시글 저장시 세션 값을 통해 writer 등록하여 NPE 해결
meena2003 bac2c2a
feat(mission5): 게시글 삭제 기능 구현
meena2003 8f3dc21
fix(mission5): 피드백 반영- Optional orElse(null)을 orElseThrow()로 교체
meena2003 b70e120
fix(mission5): 피드백 반영 - .DS_Store 파일 삭제함
meena2003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| package kr.codesqaud.cafe.controller; | ||
|
|
||
| import kr.codesqaud.cafe.domain.Article; | ||
| import kr.codesqaud.cafe.domain.Member; | ||
| import kr.codesqaud.cafe.service.ArticleService; | ||
| import org.springframework.dao.EmptyResultDataAccessException; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import javax.servlet.http.HttpSession; | ||
|
|
||
| @Controller | ||
| public class ArticleController { | ||
|
|
||
|
|
@@ -16,12 +20,30 @@ public ArticleController(ArticleService articleService) { | |
| this.articleService = articleService; | ||
| } | ||
|
|
||
| @GetMapping("/qna/article") | ||
| public String askQuestion(HttpSession httpSession) { | ||
| Member member = (Member) httpSession.getAttribute("sessionedUser"); | ||
| if (member == null) { | ||
| return "redirect:/user/login"; | ||
| } | ||
| return "qna/form"; | ||
| } | ||
|
|
||
| @PostMapping("/qna/ask") | ||
| public String registerArticle(Article article) { | ||
| public String registerArticle(Article article, HttpSession httpSession) { | ||
| Member loginMember = (Member) httpSession.getAttribute("sessionedUser"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 로그인이 안 되었을 경우 처리가 필요합니다. |
||
| article.setWriter(loginMember.getNickName()); | ||
| articleService.writeArticle(article); | ||
| return "redirect:/"; | ||
| } | ||
|
|
||
| @PostMapping("/qna/{articleId}/update") | ||
| public String updateArticle(@PathVariable long articleId, Article article) { | ||
| article.setArticleId(articleId); | ||
| articleService.updateArticle(article); | ||
| return "redirect:/"; | ||
| } | ||
|
|
||
| @GetMapping("/") | ||
| public String printArticleList(Model model) { | ||
| model.addAttribute("article", articleService.findArticles()); | ||
|
|
@@ -30,9 +52,34 @@ public String printArticleList(Model model) { | |
| } | ||
|
|
||
| @GetMapping("/qna/{articleId}") | ||
| public String printDetailArticle(@PathVariable int articleId, Model model) { | ||
| public String printDetailArticle(@PathVariable int articleId, HttpSession httpSession, Model model) { | ||
| if (httpSession.getAttribute("sessionedUser") == null) { | ||
| return "redirect:/user/login"; | ||
| }; | ||
| Article article = articleService.findOneArticleById(articleId).get(); | ||
| model.addAttribute("article", article); | ||
| return "qna/show"; | ||
| } | ||
|
|
||
| @GetMapping("/article/{articleId}/edite") | ||
| public String editeArticle(@PathVariable long articleId, HttpSession httpSession, Model model) { | ||
| Article writedArticle = articleService.findOneArticleById(articleId).orElseThrow(() -> new EmptyResultDataAccessException(1)); | ||
| Member loginMember = (Member) httpSession.getAttribute("sessionedUser"); | ||
| if (loginMember.getNickName().equals(writedArticle.getWriter())) { | ||
| model.addAttribute("article", writedArticle); | ||
| return "qna/updateForm"; | ||
| } | ||
| return "qna/edite_fail"; | ||
| } | ||
|
|
||
| @DeleteMapping("/article/{articleId}/delete") | ||
| public String deleteArticle(@PathVariable long articleId, HttpSession httpSession) { | ||
| Article writedArticle = articleService.findOneArticleById(articleId).orElseThrow(() -> new EmptyResultDataAccessException(1)); | ||
| Member loginMember = (Member) httpSession.getAttribute("sessionedUser"); | ||
| if (loginMember.getNickName().equals(writedArticle.getWriter())) { | ||
| articleService.deleteArticle(articleId); | ||
| return "redirect:/"; | ||
| } | ||
| return "qna/delete_fail"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import kr.codesqaud.cafe.domain.Member; | ||
| import kr.codesqaud.cafe.service.MemberService; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.dao.EmptyResultDataAccessException; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
|
|
||
|
|
@@ -19,7 +20,7 @@ public LoginController(MemberService memberService) { | |
|
|
||
| @PostMapping("/login") | ||
| public String login(Member member, HttpSession httpSession) { | ||
| Member loginMember = memberService.findOneMemberByEmail(member.getEmail()).orElse(null); | ||
| Member loginMember = memberService.findOneMemberByEmail(member.getEmail()).orElseThrow(() -> new EmptyResultDataAccessException(1)); | ||
| if (loginMember != null && memberService.checkMember(loginMember, member)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| httpSession.setAttribute("sessionedUser", loginMember); | ||
| return "redirect:/"; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,7 @@ insert into member (email, nickname, password) | |
| values ('[email protected]', 'kim', '123'); | ||
|
|
||
| insert into article (writer, title, contents) | ||
| values ('manju', 'hi', 'hello'); | ||
| values ('manju', '가입인사 드립니다.', '등업해주세요!'); | ||
|
|
||
| insert into article (writer, title, contents) | ||
| values ('core', '자바 질문', '스트림에 대해서 질문합니다.'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| {{>user/header}} | ||
|
|
||
| <link href="../../css/user/login_fail.css" rel="stylesheet"> | ||
|
|
||
| <div class="container" id="main"> | ||
| <header class="post-header"> | ||
| <p class="title">다른 사람의 글을 삭제할 수 없습니다!</p> | ||
| </header> | ||
| <a href="/" class="btn">홈으로</a> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| {{>user/header}} | ||
|
|
||
| <link href="../../css/user/login_fail.css" rel="stylesheet"> | ||
|
|
||
| <div class="container" id="main"> | ||
| <header class="post-header"> | ||
| <p class="title">다른 사람의 글을 수정할 수 없습니다!</p> | ||
| </header> | ||
| <a href="/" class="btn">홈으로</a> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
form 을 리턴해 주는 경우 명시적으로 URL 등에 form 이 들어가는 게 좋을 것 같아요.