diff --git a/.gitignore b/.gitignore index a281dd40..2eb1fafa 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ out/ ### VS Code ### .vscode/ .DS_Store + +**/logs \ No newline at end of file diff --git a/api-server/build.gradle b/api-server/build.gradle new file mode 100644 index 00000000..632f4fcb --- /dev/null +++ b/api-server/build.gradle @@ -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"); + }); + }); +}; \ No newline at end of file diff --git a/dividend-api-server/src/main/java/nexters/dividendapiserver/DividendApiServerApplication.java b/api-server/src/main/java/nexters/dividend/apiserver/DividendApiServerApplication.java similarity index 89% rename from dividend-api-server/src/main/java/nexters/dividendapiserver/DividendApiServerApplication.java rename to api-server/src/main/java/nexters/dividend/apiserver/DividendApiServerApplication.java index ab81d5ab..d66a9812 100644 --- a/dividend-api-server/src/main/java/nexters/dividendapiserver/DividendApiServerApplication.java +++ b/api-server/src/main/java/nexters/dividend/apiserver/DividendApiServerApplication.java @@ -1,4 +1,4 @@ -package nexters.dividendapiserver; +package nexters.dividend.apiserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/api-server/src/main/resources/application.properties b/api-server/src/main/resources/application.properties new file mode 100644 index 00000000..900d48b2 --- /dev/null +++ b/api-server/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.profiles.include=console-logging, file-logging diff --git a/dividend-api-server/src/test/java/nexters/dividendapiserver/DividendApiServerApplicationTests.java b/api-server/src/test/java/nexters/dividend/apiserver/DividendApiServerApplicationTests.java similarity index 84% rename from dividend-api-server/src/test/java/nexters/dividendapiserver/DividendApiServerApplicationTests.java rename to api-server/src/test/java/nexters/dividend/apiserver/DividendApiServerApplicationTests.java index 560320af..fc07be99 100644 --- a/dividend-api-server/src/test/java/nexters/dividendapiserver/DividendApiServerApplicationTests.java +++ b/api-server/src/test/java/nexters/dividend/apiserver/DividendApiServerApplicationTests.java @@ -1,4 +1,4 @@ -package nexters.dividendapiserver; +package nexters.dividend.apiserver; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/dividend-batch/build.gradle b/batch/build.gradle similarity index 51% rename from dividend-batch/build.gradle rename to batch/build.gradle index 28ac8b6b..7587ea9a 100644 --- a/dividend-batch/build.gradle +++ b/batch/build.gradle @@ -4,10 +4,9 @@ plugins { id 'io.spring.dependency-management' version '1.1.4' } -group = 'nexters' -version = '0.0.1-SNAPSHOT' - dependencies { + implementation(project(":core")) + implementation 'org.springframework.boot:spring-boot-starter' testImplementation 'org.springframework.boot:spring-boot-starter-test' } @@ -15,3 +14,16 @@ dependencies { tasks.named('test') { useJUnitPlatform() } + +String jarName = "batch.jar"; + +tasks.named("bootJar") { + bootJar.getArchiveFileName().set(jarName); + + bootJar.doLast(task -> { + copy(copySpec -> { + copySpec.from("build/libs/" + jarName); + copySpec.into("../build/libs"); + }); + }); +}; \ No newline at end of file diff --git a/dividend-batch/src/main/java/nexters/dividendbatch/DividendBatchApplication.java b/batch/src/main/java/nexters/dividend/batch/DividendBatchApplication.java similarity index 90% rename from dividend-batch/src/main/java/nexters/dividendbatch/DividendBatchApplication.java rename to batch/src/main/java/nexters/dividend/batch/DividendBatchApplication.java index ad6c13da..2159dda8 100644 --- a/dividend-batch/src/main/java/nexters/dividendbatch/DividendBatchApplication.java +++ b/batch/src/main/java/nexters/dividend/batch/DividendBatchApplication.java @@ -1,4 +1,4 @@ -package nexters.dividendbatch; +package nexters.dividend.batch; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/dividend-api-server/src/main/resources/application.properties b/batch/src/main/resources/application.properties similarity index 100% rename from dividend-api-server/src/main/resources/application.properties rename to batch/src/main/resources/application.properties diff --git a/dividend-batch/src/test/java/nexters/dividendbatch/DividendBatchApplicationTests.java b/batch/src/test/java/nexters/dividend/batch/DividendBatchApplicationTests.java similarity index 86% rename from dividend-batch/src/test/java/nexters/dividendbatch/DividendBatchApplicationTests.java rename to batch/src/test/java/nexters/dividend/batch/DividendBatchApplicationTests.java index 60d77d21..61ed9250 100644 --- a/dividend-batch/src/test/java/nexters/dividendbatch/DividendBatchApplicationTests.java +++ b/batch/src/test/java/nexters/dividend/batch/DividendBatchApplicationTests.java @@ -1,4 +1,4 @@ -package nexters.dividendbatch; +package nexters.dividend.batch; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/build.gradle b/build.gradle index 258d2d3d..4f56a3b9 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } \ No newline at end of file diff --git a/dividend-core/build.gradle b/core/build.gradle similarity index 88% rename from dividend-core/build.gradle rename to core/build.gradle index 6943bb78..99a76661 100644 --- a/dividend-core/build.gradle +++ b/core/build.gradle @@ -4,14 +4,11 @@ plugins { id 'io.spring.dependency-management' version '1.1.4' } -group = 'nexters' -version = '0.0.1-SNAPSHOT' - bootJar.enabled = false jar.enabled = true dependencies { - implementation 'org.springframework.boot:spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-web' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/dividend-core/src/main/java/nexters/dividendcore/DividendCoreApplication.java b/core/src/main/java/nexters/dividend/core/DividendCoreApplication.java similarity index 90% rename from dividend-core/src/main/java/nexters/dividendcore/DividendCoreApplication.java rename to core/src/main/java/nexters/dividend/core/DividendCoreApplication.java index 9b264774..7622dfc1 100644 --- a/dividend-core/src/main/java/nexters/dividendcore/DividendCoreApplication.java +++ b/core/src/main/java/nexters/dividend/core/DividendCoreApplication.java @@ -1,4 +1,4 @@ -package nexters.dividendcore; +package nexters.dividend.core; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/core/src/main/java/nexters/dividend/core/exception/ErrorResponse.java b/core/src/main/java/nexters/dividend/core/exception/ErrorResponse.java new file mode 100644 index 00000000..d2e1ff00 --- /dev/null +++ b/core/src/main/java/nexters/dividend/core/exception/ErrorResponse.java @@ -0,0 +1,7 @@ +package nexters.dividend.core.exception; + +public record ErrorResponse( + int code, + String message +) { +} \ No newline at end of file diff --git a/core/src/main/java/nexters/dividend/core/exception/GlobalExceptionHandler.java b/core/src/main/java/nexters/dividend/core/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..adcd078f --- /dev/null +++ b/core/src/main/java/nexters/dividend/core/exception/GlobalExceptionHandler.java @@ -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 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 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 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 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 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 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 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())); + } +} diff --git a/core/src/main/java/nexters/dividend/core/exception/error/AlreadyExistsException.java b/core/src/main/java/nexters/dividend/core/exception/error/AlreadyExistsException.java new file mode 100644 index 00000000..0ef83ef6 --- /dev/null +++ b/core/src/main/java/nexters/dividend/core/exception/error/AlreadyExistsException.java @@ -0,0 +1,7 @@ +package nexters.dividend.core.exception.error; + +public class AlreadyExistsException extends BaseException { + public AlreadyExistsException(final String message) { + super(message); + } +} diff --git a/core/src/main/java/nexters/dividend/core/exception/error/BadRequestException.java b/core/src/main/java/nexters/dividend/core/exception/error/BadRequestException.java new file mode 100644 index 00000000..80a1b8e7 --- /dev/null +++ b/core/src/main/java/nexters/dividend/core/exception/error/BadRequestException.java @@ -0,0 +1,7 @@ +package nexters.dividend.core.exception.error; + +public class BadRequestException extends BaseException { + public BadRequestException(final String message) { + super(message); + } +} diff --git a/core/src/main/java/nexters/dividend/core/exception/error/BaseException.java b/core/src/main/java/nexters/dividend/core/exception/error/BaseException.java new file mode 100644 index 00000000..75a43773 --- /dev/null +++ b/core/src/main/java/nexters/dividend/core/exception/error/BaseException.java @@ -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; + } +} diff --git a/core/src/main/java/nexters/dividend/core/exception/error/NotFoundException.java b/core/src/main/java/nexters/dividend/core/exception/error/NotFoundException.java new file mode 100644 index 00000000..8cdb366d --- /dev/null +++ b/core/src/main/java/nexters/dividend/core/exception/error/NotFoundException.java @@ -0,0 +1,7 @@ +package nexters.dividend.core.exception.error; + +public class NotFoundException extends BaseException { + public NotFoundException(final String message) { + super(message); + } +} diff --git a/core/src/main/resources/logback-spring.xml b/core/src/main/resources/logback-spring.xml new file mode 100644 index 00000000..a1923d19 --- /dev/null +++ b/core/src/main/resources/logback-spring.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + ${LOG_PATH}/${LOG_FILE_NAME}.log + + ${LOG_PATH}/%d{yyyy-MM-dd}-info-%i.log + 50MB + 30 + + + %d{HH:mm:ss.SSS} [%level] [%thread] [%logger{36}] - %msg%n + + + + + + + diff --git a/dividend-core/src/test/java/nexters/dividendcore/DividendCoreApplicationTests.java b/core/src/test/java/nexters/dividend/core/DividendCoreApplicationTests.java similarity index 86% rename from dividend-core/src/test/java/nexters/dividendcore/DividendCoreApplicationTests.java rename to core/src/test/java/nexters/dividend/core/DividendCoreApplicationTests.java index d48fa8a0..41471b56 100644 --- a/dividend-core/src/test/java/nexters/dividendcore/DividendCoreApplicationTests.java +++ b/core/src/test/java/nexters/dividend/core/DividendCoreApplicationTests.java @@ -1,4 +1,4 @@ -package nexters.dividendcore; +package nexters.dividend.core; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/dividend-api-server/build.gradle b/dividend-api-server/build.gradle deleted file mode 100644 index b29578cc..00000000 --- a/dividend-api-server/build.gradle +++ /dev/null @@ -1,17 +0,0 @@ -plugins { - id 'java' - id 'org.springframework.boot' version '3.2.1' - id 'io.spring.dependency-management' version '1.1.4' -} - -group = 'nexters' -version = '0.0.1-SNAPSHOT' - -dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' - testImplementation 'org.springframework.boot:spring-boot-starter-test' -} - -tasks.named('test') { - useJUnitPlatform() -} diff --git a/dividend-batch/src/main/resources/application.properties b/dividend-batch/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/dividend-batch/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/dividend-core/src/main/resources/application.properties b/dividend-core/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/dividend-core/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/domain/build.gradle b/domain/build.gradle index 90412950..d1cae002 100644 --- a/domain/build.gradle +++ b/domain/build.gradle @@ -4,9 +4,6 @@ plugins { id 'io.spring.dependency-management' version '1.1.4' } -group = 'nexters' -version = '0.0.1-SNAPSHOT' - repositories { mavenCentral() } diff --git a/domain/src/main/java/nexters/domain/base/BaseEntity.java b/domain/src/main/java/nexters/dividend/domain/BaseEntity.java similarity index 97% rename from domain/src/main/java/nexters/domain/base/BaseEntity.java rename to domain/src/main/java/nexters/dividend/domain/BaseEntity.java index d251971d..69747dc6 100644 --- a/domain/src/main/java/nexters/domain/base/BaseEntity.java +++ b/domain/src/main/java/nexters/dividend/domain/BaseEntity.java @@ -1,4 +1,4 @@ -package nexters.domain.base; +package nexters.dividend.domain; import jakarta.persistence.*; import lombok.Getter; diff --git a/domain/src/main/java/nexters/domain/DomainApplication.java b/domain/src/main/java/nexters/dividend/domain/DomainApplication.java similarity index 89% rename from domain/src/main/java/nexters/domain/DomainApplication.java rename to domain/src/main/java/nexters/dividend/domain/DomainApplication.java index 632848cf..c3545a19 100644 --- a/domain/src/main/java/nexters/domain/DomainApplication.java +++ b/domain/src/main/java/nexters/dividend/domain/DomainApplication.java @@ -1,4 +1,4 @@ -package nexters.domain; +package nexters.dividend.domain; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/domain/src/main/java/nexters/domain/dividend/Dividend.java b/domain/src/main/java/nexters/dividend/domain/dividend/Dividend.java similarity index 94% rename from domain/src/main/java/nexters/domain/dividend/Dividend.java rename to domain/src/main/java/nexters/dividend/domain/dividend/Dividend.java index ae8a8d8b..6fd57d64 100644 --- a/domain/src/main/java/nexters/domain/dividend/Dividend.java +++ b/domain/src/main/java/nexters/dividend/domain/dividend/Dividend.java @@ -1,11 +1,11 @@ -package nexters.domain.dividend; +package nexters.dividend.domain.dividend; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import nexters.domain.base.BaseEntity; +import nexters.dividend.domain.BaseEntity; import java.time.Instant; import java.util.UUID; diff --git a/domain/src/main/java/nexters/domain/dividend/repository/DividendRepository.java b/domain/src/main/java/nexters/dividend/domain/dividend/repository/DividendRepository.java similarity index 70% rename from domain/src/main/java/nexters/domain/dividend/repository/DividendRepository.java rename to domain/src/main/java/nexters/dividend/domain/dividend/repository/DividendRepository.java index 7c3599df..703d5821 100644 --- a/domain/src/main/java/nexters/domain/dividend/repository/DividendRepository.java +++ b/domain/src/main/java/nexters/dividend/domain/dividend/repository/DividendRepository.java @@ -1,6 +1,6 @@ -package nexters.domain.dividend.repository; +package nexters.dividend.domain.dividend.repository; -import nexters.domain.dividend.Dividend; +import nexters.dividend.domain.dividend.Dividend; import org.springframework.data.jpa.repository.JpaRepository; import java.util.UUID; diff --git a/domain/src/main/java/nexters/domain/stock/Sector.java b/domain/src/main/java/nexters/dividend/domain/stock/Sector.java similarity index 93% rename from domain/src/main/java/nexters/domain/stock/Sector.java rename to domain/src/main/java/nexters/dividend/domain/stock/Sector.java index a995b2f1..a074b434 100644 --- a/domain/src/main/java/nexters/domain/stock/Sector.java +++ b/domain/src/main/java/nexters/dividend/domain/stock/Sector.java @@ -1,4 +1,4 @@ -package nexters.domain.stock; +package nexters.dividend.domain.stock; public enum Sector { TECHNOLOGY("Technology"), diff --git a/domain/src/main/java/nexters/domain/stock/Stock.java b/domain/src/main/java/nexters/dividend/domain/stock/Stock.java similarity index 88% rename from domain/src/main/java/nexters/domain/stock/Stock.java rename to domain/src/main/java/nexters/dividend/domain/stock/Stock.java index fcba3a3f..8816e847 100644 --- a/domain/src/main/java/nexters/domain/stock/Stock.java +++ b/domain/src/main/java/nexters/dividend/domain/stock/Stock.java @@ -1,14 +1,13 @@ -package nexters.domain.stock; +package nexters.dividend.domain.stock; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; -import nexters.domain.base.BaseEntity; +import nexters.dividend.domain.BaseEntity; import java.util.ArrayList; import java.util.List; -import java.util.UUID; @Entity @Getter diff --git a/domain/src/main/java/nexters/domain/stock/StockRepository.java b/domain/src/main/java/nexters/dividend/domain/stock/StockRepository.java similarity index 80% rename from domain/src/main/java/nexters/domain/stock/StockRepository.java rename to domain/src/main/java/nexters/dividend/domain/stock/StockRepository.java index 96299e39..0d854ff4 100644 --- a/domain/src/main/java/nexters/domain/stock/StockRepository.java +++ b/domain/src/main/java/nexters/dividend/domain/stock/StockRepository.java @@ -1,4 +1,4 @@ -package nexters.domain.stock; +package nexters.dividend.domain.stock; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/domain/src/test/java/nexters/domain/DomainApplicationTests.java b/domain/src/test/java/nexters/dividend/domain/DomainApplicationTests.java similarity index 85% rename from domain/src/test/java/nexters/domain/DomainApplicationTests.java rename to domain/src/test/java/nexters/dividend/domain/DomainApplicationTests.java index 80fb1f3e..21429bb8 100644 --- a/domain/src/test/java/nexters/domain/DomainApplicationTests.java +++ b/domain/src/test/java/nexters/dividend/domain/DomainApplicationTests.java @@ -1,4 +1,4 @@ -package nexters.domain; +package nexters.dividend.domain; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; diff --git a/settings.gradle b/settings.gradle index d6226f43..8578c629 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,6 @@ -rootProject.name = 'dividend' +rootProject.name = 'dividend-server' -include(":dividend-api-server") -include(":dividend-batch") -include(":dividend-core") +include(":api-server") +include(":batch") +include(":core") include(":domain") \ No newline at end of file