-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* style: simplify file path * feat: add custom exception * feat: add exception handler, response * feat: add logback.yml * feat: depend on core module * feat: implement process of bootJar task * chore: update by code review * refactor: unify domain package path
- Loading branch information
Showing
33 changed files
with
240 additions
and
57 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,5 @@ out/ | |
### VS Code ### | ||
.vscode/ | ||
.DS_Store | ||
|
||
**/logs |
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,29 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.springframework.boot' version '3.2.1' | ||
id 'io.spring.dependency-management' version '1.1.4' | ||
} | ||
|
||
dependencies { | ||
implementation(project(":core")) | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
tasks.named('test') { | ||
useJUnitPlatform() | ||
} | ||
|
||
String jarName = "api-server.jar"; | ||
|
||
tasks.named("bootJar") { | ||
bootJar.getArchiveFileName().set(jarName); | ||
|
||
bootJar.doLast(task -> { | ||
copy(copySpec -> { | ||
copySpec.from("build/libs/" + jarName); | ||
copySpec.into("../build/libs"); | ||
}); | ||
}); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...iserver/DividendApiServerApplication.java → ...iserver/DividendApiServerApplication.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
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 @@ | ||
spring.profiles.include=console-logging, file-logging |
2 changes: 1 addition & 1 deletion
2
...er/DividendApiServerApplicationTests.java → ...er/DividendApiServerApplicationTests.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
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
2 changes: 1 addition & 1 deletion
2
...videndbatch/DividendBatchApplication.java → ...idend/batch/DividendBatchApplication.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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...dbatch/DividendBatchApplicationTests.java → .../batch/DividendBatchApplicationTests.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
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,10 +1,14 @@ | ||
allprojects { | ||
apply plugin: 'java' | ||
group = 'nexters' | ||
apply plugin: 'java' | ||
group = 'nexters' | ||
|
||
sourceCompatibility = '17' | ||
sourceCompatibility = '17' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
repositories { | ||
mavenCentral() | ||
} | ||
} | ||
|
||
jar { | ||
enabled = false | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...dividendcore/DividendCoreApplication.java → ...ividend/core/DividendCoreApplication.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
7 changes: 7 additions & 0 deletions
7
core/src/main/java/nexters/dividend/core/exception/ErrorResponse.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,7 @@ | ||
package nexters.dividend.core.exception; | ||
|
||
public record ErrorResponse( | ||
int code, | ||
String message | ||
) { | ||
} |
90 changes: 90 additions & 0 deletions
90
core/src/main/java/nexters/dividend/core/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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package nexters.dividend.core.exception; | ||
|
||
import nexters.dividend.core.exception.error.AlreadyExistsException; | ||
import nexters.dividend.core.exception.error.BadRequestException; | ||
import nexters.dividend.core.exception.error.NotFoundException; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.HttpStatusCode; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.converter.HttpMessageNotReadableException; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.MissingServletRequestParameterException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.context.request.WebRequest; | ||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { | ||
|
||
@Override | ||
protected ResponseEntity<Object> handleMethodArgumentNotValid( | ||
final MethodArgumentNotValidException ex, | ||
final HttpHeaders headers, | ||
final HttpStatusCode status, | ||
final WebRequest request) { | ||
logger.error("message", ex); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage())); | ||
} | ||
|
||
@Override | ||
protected ResponseEntity<Object> handleHttpMessageNotReadable( | ||
final HttpMessageNotReadableException ex, | ||
final HttpHeaders headers, | ||
final HttpStatusCode status, | ||
final WebRequest request) { | ||
logger.error("message", ex); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage())); | ||
} | ||
|
||
@Override | ||
protected ResponseEntity<Object> handleMissingServletRequestParameter( | ||
final MissingServletRequestParameterException ex, | ||
final HttpHeaders headers, | ||
final HttpStatusCode status, | ||
final WebRequest request) { | ||
logger.error("message", ex); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), ex.getMessage())); | ||
} | ||
|
||
@ExceptionHandler({IllegalArgumentException.class, BadRequestException.class}) | ||
public ResponseEntity<ErrorResponse> handleBadRequestException(final RuntimeException exception) { | ||
logger.error("message", exception); | ||
|
||
return ResponseEntity.status(HttpStatus.BAD_REQUEST) | ||
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), exception.getMessage())); | ||
} | ||
|
||
@ExceptionHandler({NoSuchElementException.class, NotFoundException.class}) | ||
public ResponseEntity<ErrorResponse> handleNotFoundException(final RuntimeException exception) { | ||
logger.error("message", exception); | ||
|
||
return ResponseEntity.status(HttpStatus.NOT_FOUND) | ||
.body(new ErrorResponse(HttpStatus.NOT_FOUND.value(), exception.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(AlreadyExistsException.class) | ||
public ResponseEntity<ErrorResponse> handleDuplicateException(final AlreadyExistsException exception) { | ||
logger.error("message", exception); | ||
|
||
return ResponseEntity.status(HttpStatus.CONFLICT) | ||
.body(new ErrorResponse(HttpStatus.CONFLICT.value(), exception.getMessage())); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<ErrorResponse> handleException(final Exception exception) { | ||
logger.error("message", exception); | ||
|
||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), exception.getMessage())); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/nexters/dividend/core/exception/error/AlreadyExistsException.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,7 @@ | ||
package nexters.dividend.core.exception.error; | ||
|
||
public class AlreadyExistsException extends BaseException { | ||
public AlreadyExistsException(final String message) { | ||
super(message); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/nexters/dividend/core/exception/error/BadRequestException.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,7 @@ | ||
package nexters.dividend.core.exception.error; | ||
|
||
public class BadRequestException extends BaseException { | ||
public BadRequestException(final String message) { | ||
super(message); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
core/src/main/java/nexters/dividend/core/exception/error/BaseException.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,14 @@ | ||
package nexters.dividend.core.exception.error; | ||
|
||
public class BaseException extends RuntimeException { | ||
private final String message; | ||
|
||
public BaseException(final String message) { | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/java/nexters/dividend/core/exception/error/NotFoundException.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,7 @@ | ||
package nexters.dividend.core.exception.error; | ||
|
||
public class NotFoundException extends BaseException { | ||
public NotFoundException(final String message) { | ||
super(message); | ||
} | ||
} |
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,29 @@ | ||
<configuration> | ||
<springProfile name="console-logging"> | ||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/> | ||
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/> | ||
<root level="INFO"> | ||
<appender-ref ref="CONSOLE"/> | ||
</root> | ||
</springProfile> | ||
|
||
<springProfile name="file-logging"> | ||
<property name="LOG_PATH" value="./logs"/> | ||
<property name="LOG_FILE_NAME" value="dividend"/> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>${LOG_PATH}/${LOG_FILE_NAME}.log</file> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> | ||
<fileNamePattern>${LOG_PATH}/%d{yyyy-MM-dd}-info-%i.log</fileNamePattern> | ||
<maxFileSize>50MB</maxFileSize> | ||
<maxHistory>30</maxHistory> | ||
</rollingPolicy> | ||
<encoder> | ||
<pattern>%d{HH:mm:ss.SSS} [%level] [%thread] [%logger{36}] - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
<root level="INFO"> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
</springProfile> | ||
</configuration> |
2 changes: 1 addition & 1 deletion
2
...endcore/DividendCoreApplicationTests.java → ...nd/core/DividendCoreApplicationTests.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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
.../java/nexters/domain/base/BaseEntity.java → ...a/nexters/dividend/domain/BaseEntity.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
2 changes: 1 addition & 1 deletion
2
...ava/nexters/domain/DomainApplication.java → ...rs/dividend/domain/DomainApplication.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
4 changes: 2 additions & 2 deletions
4
...ava/nexters/domain/dividend/Dividend.java → ...rs/dividend/domain/dividend/Dividend.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
4 changes: 2 additions & 2 deletions
4
...vidend/repository/DividendRepository.java → ...vidend/repository/DividendRepository.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
2 changes: 1 addition & 1 deletion
2
...ain/java/nexters/domain/stock/Sector.java → ...nexters/dividend/domain/stock/Sector.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
Oops, something went wrong.