This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
회원가입 및 로그인 기능 추가 #3
Open
Daniel-Taeyoun
wants to merge
4
commits into
develop
Choose a base branch
from
feature1
base: develop
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 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
39 changes: 39 additions & 0 deletions
39
src/main/java/me/naming/onlineshoppingmall/config/RestResponseEntityExceptionHandler.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,39 @@ | ||
package me.naming.onlineshoppingmall.config; | ||
|
||
import java.time.LocalDateTime; | ||
import me.naming.onlineshoppingmall.domain.ResponseData; | ||
import me.naming.onlineshoppingmall.exception.MessageException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.context.request.ServletWebRequest; | ||
import org.springframework.web.context.request.WebRequest; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
// @Controller or @RestController에서 발생하는 예외를 관리 할 수 있게 만들어주는 어노테이션 | ||
// @ExceptionHandler를 통해 각각의 예외처리 메세지를 원하는 형태로 작성 할 수 있다. | ||
@ControllerAdvice | ||
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler { | ||
|
||
@ExceptionHandler(value = { MessageException.class }) | ||
protected ResponseEntity handleConflict(MessageException messageException, WebRequest request) { | ||
String path = ((ServletWebRequest)request).getRequest().getRequestURI(); | ||
int code; | ||
|
||
if(messageException.getStatusCode() != 0) { | ||
code = messageException.getStatusCode(); | ||
} else { | ||
code = HttpStatus.INTERNAL_SERVER_ERROR.value(); | ||
} | ||
|
||
ResponseData responseData = ResponseData.builder() | ||
.localDateTime(LocalDateTime.now()) | ||
.statusCode(code) | ||
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. 이렇게하면 status code가 body에 들어가지 않을까요? |
||
.path(path) | ||
.message(messageException.getMessage()) | ||
.build(); | ||
|
||
return new ResponseEntity<>(responseData, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
} |
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
48 changes: 43 additions & 5 deletions
48
src/main/java/me/naming/onlineshoppingmall/controller/MemberController.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,17 +1,55 @@ | ||
package me.naming.onlineshoppingmall.controller; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.validation.Valid; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.extern.slf4j.Slf4j; | ||
import me.naming.onlineshoppingmall.domain.Member; | ||
import me.naming.onlineshoppingmall.service.MemberService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
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.RequestBody; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
public class MemberController { | ||
|
||
private static final Logger logger = LogManager.getLogger(MemberController.class); | ||
private final MemberService memberService; | ||
|
||
@GetMapping | ||
public void hello() { | ||
@Autowired | ||
public MemberController(MemberService memberService) { | ||
this.memberService = memberService; | ||
} | ||
|
||
// 회원가입 | ||
@PostMapping(value = "/members/signup") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public void memberJoin(@RequestBody @Valid Member member) { | ||
memberService.signUp(member); | ||
} | ||
|
||
// 회원정보 갖고오기 | ||
@GetMapping(value = "/members/{memNo}") | ||
@ResponseStatus(HttpStatus.OK) | ||
public Member getMemberInfo(@PathVariable(name = "memNo") Long memNo) { | ||
return memberService.getMemberInfo(memNo); | ||
} | ||
|
||
@GetMapping(value = "/login") | ||
@ResponseStatus(HttpStatus.OK) | ||
public void login(@RequestBody UserLoginRequest userLoginRequest, HttpServletRequest request) { | ||
memberService.doLogin(userLoginRequest.getEmail(), userLoginRequest.getPassword(), request); | ||
} | ||
|
||
@Getter | ||
private static class UserLoginRequest { | ||
@NonNull String email; | ||
@NonNull String password; | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/me/naming/onlineshoppingmall/domain/ResponseData.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 me.naming.onlineshoppingmall.domain; | ||
|
||
import java.time.LocalDateTime; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Builder | ||
@ToString | ||
@Getter | ||
public class ResponseData { | ||
private LocalDateTime localDateTime; | ||
private int statusCode; | ||
private String path; | ||
private String message; | ||
|
||
public ResponseData(LocalDateTime localDateTime, int statusCode, String path, String message) { | ||
this.localDateTime = localDateTime; | ||
this.statusCode = statusCode; | ||
this.path = path; | ||
this.message = message; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/me/naming/onlineshoppingmall/exception/MessageException.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,23 @@ | ||
package me.naming.onlineshoppingmall.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class MessageException extends RuntimeException{ | ||
|
||
private int statusCode; | ||
|
||
public MessageException(String message) { | ||
super(message); | ||
this.statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value(); | ||
} | ||
|
||
public MessageException(String message, int statusCode) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
} |
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.
Intellij
지원이면 intellij가 아닌 환경에서는 에러가 나지 않나요??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.
해당 내용은 개인적으로 블로그 글을 잘못 이해했습니다. 스프링 내부(
org.springframework.boot:spring-boot-starter-test
)에서 jupiter를 제공해주고 있으며, 따라서 추가했던 jupiter는 삭제했습니다.