-
Notifications
You must be signed in to change notification settings - Fork 28
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
[이노] step 5. XHR과 AJAX #136
Open
eNoLJ
wants to merge
21
commits into
codesquad-members-2021:eNoLJ
Choose a base branch
from
eNoLJ:mission5
base: eNoLJ
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
21 commits
Select commit
Hold shift + click to select a range
4800a4a
Create ApiAnswerController class
eNoLJ 80f2763
Fix logger of deleteAnswer in AnswerController class
eNoLJ dd23874
Add @JsonIgnore annotation in User and Question class
eNoLJ 9894af8
Create event in scripts.js
eNoLJ 3f5b778
Modify save method in AnswerService class
eNoLJ 5038c3c
Modify action of form tag in show.html
eNoLJ 6b82801
Add @ResponseStatus of handleUserSessionException method in GlobalExc…
eNoLJ c232a83
Modify answer delete url in show.html
eNoLJ 6fe83fb
Create an event to delete a answer
eNoLJ 839a6cd
Create deleteAnswer method in ApiAnswerController class
eNoLJ 954ae0b
Add @OrderBy annotation in Question class
eNoLJ c63eebe
Create updateAnswerCount method in scripts.js
eNoLJ 77f3452
Refactor : Entity 클래스의 update 메소드 리팩토링
eNoLJ 7101788
Refactor : Controller 클래스의 @PathVariable 어노테이션을 활용하여 query string을 받는…
eNoLJ 22f80f3
Feat : 에러 메세지를 상수로 관리하는 ErrorMessage enum 생성
eNoLJ 103a3f2
Refactor : ErrorMessage enum을 활용하여 리팩토링
eNoLJ 630d91a
Feat : AbstractEntity class 생성
eNoLJ 201df39
Refactor : AbstractEntity class를 사용하여 리팩토링
eNoLJ 5bf8245
Feat : Swagger2 라이브러리를 이용한 API 문서화
eNoLJ 7fe0468
Style : 메소드 순서 변경, 불필요한 코드 삭제
eNoLJ 28d66bf
Refactor : Question 클래스의 matchWriterOfAnswerList 메소드 수정
eNoLJ 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 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 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 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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/codessquad/qna/controller/ApiAnswerController.java
This file contains 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,38 @@ | ||
package com.codessquad.qna.controller; | ||
|
||
import com.codessquad.qna.model.Answer; | ||
import com.codessquad.qna.service.AnswerService; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpSession; | ||
|
||
import static com.codessquad.qna.controller.HttpSessionUtils.getUserFromSession; | ||
|
||
@RestController | ||
public class ApiAnswerController { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(AnswerController.class); | ||
private final AnswerService answerService; | ||
|
||
public ApiAnswerController(AnswerService answerService) { | ||
this.answerService = answerService; | ||
} | ||
|
||
@PostMapping("/api/answer/{questionId}") | ||
public Answer createAnswer(@PathVariable Long questionId, Answer answer, HttpSession session) { | ||
logger.info("댓글 등록 요청"); | ||
return this.answerService.save(questionId, answer, getUserFromSession(session)); | ||
} | ||
|
||
@DeleteMapping("/api/answer/{id}") | ||
public Answer deleteAnswer(@PathVariable Long id, HttpSession session) { | ||
logger.info("댓글 삭제 요청"); | ||
return this.answerService.delete(id, getUserFromSession(session)); | ||
} | ||
|
||
} |
This file contains 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 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 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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/codessquad/qna/exception/EntityNotFoundException.java
This file contains 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,9 @@ | ||
package com.codessquad.qna.exception; | ||
|
||
public class EntityNotFoundException extends RuntimeException { | ||
|
||
public EntityNotFoundException(ErrorMessage errorMessage) { | ||
super(errorMessage.getErrorMessage()); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/codessquad/qna/exception/ErrorMessage.java
This file contains 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,24 @@ | ||
package com.codessquad.qna.exception; | ||
|
||
public enum ErrorMessage { | ||
|
||
USER_NOT_FOUND("해당 유저를 찾을 수 없습니다."), | ||
QUESTION_NOT_FOUND("해당 질문을 찾을 수 없습니다."), | ||
ANSWER_NOT_FOUND("해당 답변을 찾을 수 없습니다."), | ||
NEED_LOGIN("로그인이 필요한 서비스입니다."), | ||
ILLEGAL_USER("접근 권한이 없는 유저입니다."), | ||
DUPLICATED_ID("이미 사용중인 아이디입니다."), | ||
LOGIN_FAILED("아이디 또는 비밀번호가 틀립니다. 다시 로그인 해주세요."), | ||
WRONG_PASSWORD("기존 비밀번호가 일치하지 않습니다."); | ||
|
||
private final String errorMessage; | ||
|
||
ErrorMessage(String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public String getErrorMessage() { | ||
return errorMessage; | ||
} | ||
|
||
} |
24 changes: 16 additions & 8 deletions
24
src/main/java/com/codessquad/qna/exception/GlobalExceptionHandler.java
This file contains 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,36 +1,44 @@ | ||
package com.codessquad.qna.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import static com.codessquad.qna.controller.HttpSessionUtils.getUserFromSession; | ||
import static com.codessquad.qna.controller.HttpSessionUtils.isLoginUser; | ||
|
||
@ControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(NotFoundException.class) | ||
private String handleNotFoundException() { | ||
@ExceptionHandler(EntityNotFoundException.class) | ||
private String handleEntityNotFoundException() { | ||
return "redirect:/"; | ||
} | ||
|
||
@ResponseStatus(HttpStatus.UNAUTHORIZED) | ||
@ExceptionHandler(UserSessionException.class) | ||
private String handleUserSessionException(Model model, UserSessionException e) { | ||
model.addAttribute("errorMessage", e.getMessage()); | ||
return "/user/login"; | ||
} | ||
|
||
@ExceptionHandler(UserAccountException.class) | ||
private String handleUserAccountException(Model model, HttpSession session, HttpServletRequest request, UserAccountException e) { | ||
private String handleUserAccountException(Model model, HttpSession session, UserAccountException e) { | ||
model.addAttribute("errorMessage", e.getMessage()); | ||
if (isLoginUser(session)) { | ||
model.addAttribute("user", getUserFromSession(session)); | ||
switch (e.getErrorMessage()) { | ||
case DUPLICATED_ID: | ||
return "/user/form"; | ||
case LOGIN_FAILED: | ||
return "/user/login"; | ||
case WRONG_PASSWORD: | ||
model.addAttribute("user", getUserFromSession(session)); | ||
return "/user/updateForm"; | ||
default: | ||
return "/"; | ||
} | ||
return (String) request.getAttribute("path"); | ||
} | ||
|
||
} |
9 changes: 0 additions & 9 deletions
9
src/main/java/com/codessquad/qna/exception/NotFoundException.java
This file was deleted.
Oops, something went wrong.
This file contains 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 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.
👍