-
Couldn't load subscription status.
- Fork 170
[4기 - 윤영운] SpringBoot Part3 Weekly Mission 제출합니다. #857
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
Changes from all commits
ada3fd2
27388b3
1d3e520
271cd64
8dafde3
3b99851
321583f
4ad9ed2
4bd9684
e8cecb6
033e898
2bc4f5a
7a15ca8
f96ea98
6c54b0a
8af940c
a5538e6
dbe3840
f14c270
d6dfbe7
4672f90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package org.prgrms.kdt.member.controller.mapper; | ||
|
|
||
| import javax.annotation.processing.Generated; | ||
| import org.prgrms.kdt.member.controller.dto.CreateMemberApiRequest; | ||
| import org.prgrms.kdt.member.domain.MemberStatus; | ||
| import org.prgrms.kdt.member.service.dto.CreateMemberRequest; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Generated( | ||
| value = "org.mapstruct.ap.MappingProcessor", | ||
| date = "2023-08-01T21:55:33+0900", | ||
| comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.7 (Oracle Corporation)" | ||
| ) | ||
| @Component | ||
| public class ControllerMemberMapperImpl implements ControllerMemberMapper { | ||
|
|
||
| @Override | ||
| public CreateMemberRequest convertRequest(CreateMemberApiRequest request) { | ||
| if ( request == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| String name = null; | ||
| MemberStatus status = null; | ||
|
|
||
| name = request.name(); | ||
| status = request.status(); | ||
|
|
||
| CreateMemberRequest createMemberRequest = new CreateMemberRequest( name, status ); | ||
|
|
||
| return createMemberRequest; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package org.prgrms.kdt.voucher.controller.mapper; | ||
|
|
||
| import javax.annotation.processing.Generated; | ||
| import org.prgrms.kdt.voucher.controller.dto.CreateVoucherApiRequest; | ||
| import org.prgrms.kdt.voucher.controller.dto.SearchApiRequest; | ||
| import org.prgrms.kdt.voucher.domain.VoucherType; | ||
| import org.prgrms.kdt.voucher.service.dto.CreateVoucherRequest; | ||
| import org.prgrms.kdt.voucher.service.dto.SearchRequest; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Generated( | ||
| value = "org.mapstruct.ap.MappingProcessor", | ||
| date = "2023-08-01T21:55:34+0900", | ||
| comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.7 (Oracle Corporation)" | ||
| ) | ||
| @Component | ||
| public class ControllerVoucherMapperImpl implements ControllerVoucherMapper { | ||
|
|
||
| @Override | ||
| public CreateVoucherRequest convertRequest(CreateVoucherApiRequest createVoucherApiRequest) { | ||
| if ( createVoucherApiRequest == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| VoucherType voucherType = null; | ||
| double discountAmount = 0.0d; | ||
|
|
||
| voucherType = createVoucherApiRequest.voucherType(); | ||
| discountAmount = createVoucherApiRequest.discountAmount(); | ||
|
|
||
| CreateVoucherRequest createVoucherRequest = new CreateVoucherRequest( voucherType, discountAmount ); | ||
|
|
||
| return createVoucherRequest; | ||
| } | ||
|
|
||
| @Override | ||
| public SearchRequest convertRequest(SearchApiRequest searchApiRequest) { | ||
| if ( searchApiRequest == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| long page = 0L; | ||
| long recordSize = 0L; | ||
| VoucherType voucherType = null; | ||
|
|
||
| page = searchApiRequest.getPage(); | ||
| recordSize = searchApiRequest.getRecordSize(); | ||
| voucherType = searchApiRequest.getVoucherType(); | ||
|
|
||
| SearchRequest searchRequest = new SearchRequest( page, recordSize, voucherType ); | ||
|
|
||
| return searchRequest; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package org.prgrms.kdt.wallet.controller.mapper; | ||
|
|
||
| import java.util.UUID; | ||
| import javax.annotation.processing.Generated; | ||
| import org.prgrms.kdt.wallet.controller.dto.CreateWalletApiRequest; | ||
| import org.prgrms.kdt.wallet.service.dto.CreateWalletRequest; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Generated( | ||
| value = "org.mapstruct.ap.MappingProcessor", | ||
| date = "2023-08-01T21:55:34+0900", | ||
| comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.7 (Oracle Corporation)" | ||
| ) | ||
| @Component | ||
| public class ControllerWalletMapperImpl implements ControllerWalletMapper { | ||
|
|
||
| @Override | ||
| public CreateWalletRequest convertRequest(CreateWalletApiRequest request) { | ||
| if ( request == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| UUID memberId = null; | ||
| UUID voucherId = null; | ||
|
|
||
| memberId = request.memberId(); | ||
| voucherId = request.voucherId(); | ||
|
|
||
| CreateWalletRequest createWalletRequest = new CreateWalletRequest( memberId, voucherId ); | ||
|
|
||
| return createWalletRequest; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package org.prgrms.kdt; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
|
|
||
| @Controller | ||
| public class HomeController { | ||
|
|
||
| @GetMapping("/") | ||
| public String home(){ | ||
| return "home"; | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package org.prgrms.kdt.global; | ||
|
|
||
| import org.prgrms.kdt.global.exception.EntityNotFoundException; | ||
| import org.prgrms.kdt.global.exception.InvalidInputException; | ||
| import org.prgrms.kdt.voucher.exception.InvalidDiscountException; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.http.converter.HttpMessageNotReadableException; | ||
| import org.springframework.validation.BindException; | ||
| import org.springframework.validation.BindingResult; | ||
| import org.springframework.validation.FieldError; | ||
| import org.springframework.web.bind.MissingRequestHeaderException; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
| import org.springframework.web.client.HttpClientErrorException; | ||
| import org.springframework.web.servlet.NoHandlerFoundException; | ||
|
|
||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| @RestControllerAdvice | ||
| public class ApiExceptionHandler { | ||
| private static final Logger logger = LoggerFactory.getLogger(ApiExceptionHandler.class); | ||
|
|
||
| @ExceptionHandler(BindException.class) | ||
| public ResponseEntity<ErrorResponse> handleBindException(HttpServletRequest request, BindException e) { | ||
| BindingResult bindingResult = e.getBindingResult(); | ||
| StringBuilder stringBuilder = new StringBuilder(); | ||
|
|
||
| for (FieldError fieldError : bindingResult.getFieldErrors()) { | ||
| stringBuilder.append(fieldError.getField()).append(":"); | ||
| stringBuilder.append(fieldError.getDefaultMessage()); | ||
| stringBuilder.append(", "); | ||
| } | ||
| int statusCode = HttpStatus.BAD_REQUEST.value(); | ||
|
Comment on lines
+30
to
+36
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. 메서드로 뺄 수 있을것 같습니다 |
||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(getErrorResponse(statusCode, stringBuilder.toString(), request.getRequestURI())); | ||
| } | ||
|
|
||
| @ExceptionHandler({NullPointerException.class, InvalidInputException.class, InvalidDiscountException.class, MissingRequestHeaderException.class, HttpMessageNotReadableException.class, | ||
|
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. NPE는 서버측 잘못일수도 있다고 생각해요 |
||
| HttpClientErrorException.BadRequest.class, NoHandlerFoundException.class}) | ||
| public ResponseEntity<ErrorResponse> handleBadRequestException(HttpServletRequest request, Exception e) { | ||
| int statusCode = HttpStatus.BAD_REQUEST.value(); | ||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(getErrorResponse(statusCode, e.getMessage(), request.getRequestURI())); | ||
| } | ||
|
|
||
| @ExceptionHandler(EntityNotFoundException.class) | ||
| public ResponseEntity<ErrorResponse> handleNotFoundException(HttpServletRequest request, EntityNotFoundException e) { | ||
| int statusCode = HttpStatus.NOT_FOUND.value(); | ||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body(getErrorResponse(statusCode, e.getMessage(), request.getRequestURI())); | ||
| } | ||
|
|
||
| @ExceptionHandler(Exception.class) | ||
| public ResponseEntity<ErrorResponse> handleException(HttpServletRequest request, Exception e) { | ||
| logger.error("Sever Exception: ", e.getMessage()); | ||
| int statusCode = HttpStatus.OK.value(); | ||
| return ResponseEntity.ok(getErrorResponse(statusCode, e.getMessage(), request.getRequestURI())); | ||
| } | ||
|
|
||
| private static ErrorResponse getErrorResponse(int status, String masesage, String requestURI) { | ||
| return new ErrorResponse(status, masesage, requestURI); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.prgrms.kdt.global; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public record ErrorResponse(int statusCode, String detail, String instance, String time) { | ||
|
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. 필드가 많아지니 개행할 위치가 애매해지죠. 가독성을 위해 public record ErrorResponse(
int statusCode,
String detail,
String instance,
String time
) { }로 둬도 좋을것 같아요. instance라는 필드는 애매모호해보입니다. 명확하게 바꾸는건 어떨까요? |
||
| public ErrorResponse(int statusCode, String detail, String instance) { | ||
| this(statusCode, detail, instance, LocalDateTime.now().toString()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package org.prgrms.kdt.global; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| public interface Generator { | ||
| UUID generateId(); | ||
|
|
||
| LocalDateTime generateTime(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.prgrms.kdt.global; | ||
|
|
||
| import com.fasterxml.uuid.Generators; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| @Component | ||
| public class GeneratorImp implements Generator{ | ||
|
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. Imp는 무엇인가용 |
||
| private GeneratorImp() { | ||
| } | ||
|
|
||
| @Override | ||
| public UUID generateId() { | ||
| UUID generateId = Generators.timeBasedGenerator().generate(); | ||
| String[] idArr = generateId.toString().split("-"); | ||
| return UUID.fromString(idArr[2]+"-"+idArr[1]+"-"+idArr[0]+"-"+idArr[3]+"-"+idArr[4]); | ||
| } | ||
|
|
||
| @Override | ||
| public LocalDateTime generateTime() { | ||
| return LocalDateTime.now(); | ||
| } | ||
| } | ||
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.
오타나신거같아용