Skip to content

Commit

Permalink
Feature: Entity 생성 및 Domain Service 어노테이션 작성
Browse files Browse the repository at this point in the history
Feature: Entity 생성 및 Domain Service 어노테이션 작성
  • Loading branch information
lcomment authored May 1, 2024
2 parents 209c193 + 5da75a2 commit 6b958ff
Show file tree
Hide file tree
Showing 34 changed files with 1,363 additions and 32 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[{*.java,*.gradle}]
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 4
tab_width = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
id 'checkstyle'
}

allprojects {
Expand All @@ -18,6 +19,7 @@ subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'checkstyle'

configurations {
compileOnly {
Expand All @@ -33,6 +35,21 @@ subprojects {
testImplementation 'junit:junit:4.13.1'
}

checkstyle {
maxWarnings = 0
configFile = file("$rootDir/config/checkstyle/checkstyle-rules.xml")
configProperties = ["suppressionFile": "$rootDir/config/checkstyle/checkstyle-suppressions.xml"]
sourceSets = [sourceSets.main]

checkstyleMain {
source = fileTree("src/main/java")
}

checkstyleTest {
source = fileTree("src/test/java")
}
}

tasks.named('test') {
useJUnitPlatform()
}
Expand Down
8 changes: 8 additions & 0 deletions cakk-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ dependencies {
implementation(project(':cakk-common'))
implementation(project(':cakk-domain'))

// basic
implementation('org.springframework.boot:spring-boot-starter-web')
implementation 'org.springframework.boot:spring-boot-starter-validation'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'com.tngtech.archunit:archunit-junit5:1.1.0'

// slack 설정
implementation 'net.gpedro.integrations.slack:slack-webhook:1.4.0'
}

tasks.named("bootJar") {
Expand Down
2 changes: 2 additions & 0 deletions cakk-api/src/main/java/com/cakk/api/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.cakk.api;

import java.util.TimeZone;

import jakarta.annotation.PostConstruct;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cakk.common.enums;

public enum CakeDesignCategory {

FLOWER
}
6 changes: 6 additions & 0 deletions cakk-common/src/main/java/com/cakk/common/enums/Gender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cakk.common.enums;

public enum Gender {

MALE, FEMALE, UNKNOWN
}
6 changes: 6 additions & 0 deletions cakk-common/src/main/java/com/cakk/common/enums/LinkKind.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cakk.common.enums;

public enum LinkKind {

WEB, KAKAOTALK, INSTAGRAM
}
6 changes: 6 additions & 0 deletions cakk-common/src/main/java/com/cakk/common/enums/Provider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cakk.common.enums;

public enum Provider {

APPLE, GOOGLE, KAKAO
}
1 change: 1 addition & 0 deletions cakk-common/src/main/java/com/cakk/common/enums/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
public enum Role {

ROLE_ADMIN,
ROLE_MERCHANT,
ROLE_USER
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.cakk.common.exception;

import com.cakk.common.enums.ReturnCode;
import lombok.Getter;

import com.cakk.common.enums.ReturnCode;

@Getter
public class CakkException extends RuntimeException {

private final String code;
private final String message;

public CakkException(ReturnCode returnCode) {
public CakkException(ReturnCode returnCode) {
this.code = returnCode.getCode();
this.message = returnCode.getMessage();
}
Expand Down
36 changes: 10 additions & 26 deletions cakk-domain/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
//plugins {
// id "com.ewerk.gradle.plugins.querydsl" version "1.0.10"
//}

description = "domain module"

dependencies {
implementation(project(':cakk-common'))

// jpa
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation 'io.hypersistence:hypersistence-utils-hibernate-5:3.5.2'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.7.4'

// querydsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
Expand All @@ -18,28 +14,16 @@ dependencies {
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// database
runtimeOnly 'com.mysql:mysql-connector-j'
runtimeOnly 'com.mysql:mysql-connector-j:8.2.0'
runtimeOnly 'com.h2database:h2'
}

//def querydslDir = layout.buildDirectory.dir("generated/querydsl").get().asFile
//
//querydsl {
// jpa = true
// querydslSourcesDir = querydslDir
//}
//sourceSets {
// main.java.srcDir querydslDir
//}
//compileQuerydsl {
// options.annotationProcessorPath = configurations.querydsl
//}
//configurations {
// compileOnly {
// extendsFrom annotationProcessor
// }
// querydsl.extendsFrom compileClasspath
//}
// log
implementation 'com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.9.0'

// flyway
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'
}

bootJar {
enabled = false
Expand Down
34 changes: 34 additions & 0 deletions cakk-domain/src/main/java/com/cakk/domain/annotation/Reader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.cakk.domain.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;

/**
* Indicates that an annotated class is a "Reader" (e.g. a data access object).
*
* <p>This annotation serves as a specialization of {@link Component @Component},
* allowing for implementation classes to be autodetected through classpath scanning.
*
* @author komment
* @see Component
* @see Repository
*/

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Reader {

/**
* Alias for {@link Component#value}.
*/
@AliasFor(annotation = Component.class)
String value() default "";
}
34 changes: 34 additions & 0 deletions cakk-domain/src/main/java/com/cakk/domain/annotation/Writer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.cakk.domain.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.core.annotation.AliasFor;
import org.springframework.stereotype.Component;

/**
* Indicates that an annotated class is a "Writer" (e.g. a data access object).
*
* <p>This annotation serves as a specialization of {@link Component @Component},
* allowing for implementation classes to be autodetected through classpath scanning.
*
* @author komment
* @see Component
* @see Repository
*/

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Writer {

/**
* Alias for {@link Component#value}.
*/
@AliasFor(annotation = Component.class)
String value() default "";
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.cakk.domain.config;

import javax.sql.DataSource;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

Expand Down
16 changes: 16 additions & 0 deletions cakk-domain/src/main/java/com/cakk/domain/config/P6spyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.cakk.domain.config;

import jakarta.annotation.PostConstruct;

import org.springframework.context.annotation.Configuration;

import com.p6spy.engine.spy.P6SpyOptions;

@Configuration
public class P6spyConfig {

@PostConstruct
public void setLogMessageFormat() {
P6SpyOptions.getActiveInstance().setLogMessageFormat(P6spySqlFormatterConfig.class.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.cakk.domain.config;

import static java.util.Arrays.*;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.Stack;
import java.util.function.Predicate;

import org.hibernate.engine.jdbc.internal.FormatStyle;

import com.p6spy.engine.logging.Category;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;

public class P6spySqlFormatterConfig implements MessageFormattingStrategy {

private static final String NEW_LINE = System.lineSeparator();
private static final String P6SPY_FORMATTER = "P6spySqlFormatterConfig";
private static final String PACKAGE = "com.cakk";
private static final String CREATE = "create";
private static final String ALTER = "alter";
private static final String COMMENT = "comment";

@Override
public String formatMessage(final int connectionId,
final String now,
final long elapsed,
final String category,
final String prepared,
final String sql,
final String url) {
return sqlFormatToUpper(sql, category, getMessage(connectionId, elapsed, getStackBuilder()));
}

@SuppressWarnings("StringBufferReplaceableByString")
private String sqlFormatToUpper(final String sql, final String category, final String message) {
if (sql.trim().isEmpty()) {
return "";
}

return new StringBuilder()
.append(sqlFormatToUpper(sql, category))
.append(message)
.toString();
}

private String sqlFormatToUpper(final String sql, final String category) {
if (isStatementDdl(sql, category)) {
return FormatStyle.DDL
.getFormatter()
.format(sql)
.toUpperCase(Locale.ROOT)
.replace("+0900", "");
}
return FormatStyle.BASIC
.getFormatter()
.format(sql)
.replace("+0900", "");
}

private boolean isStatementDdl(final String sql, final String category) {
return isStatement(category) && isDdl(sql.trim().toLowerCase(Locale.ROOT));
}

private boolean isStatement(final String category) {
return Category.STATEMENT.getName().equals(category);
}

private boolean isDdl(final String lowerSql) {
return lowerSql.startsWith(CREATE) || lowerSql.startsWith(ALTER) || lowerSql.startsWith(COMMENT);
}

private String getMessage(final int connectionId, final long elapsed, final StringBuilder callStackBuilder) {
return new StringBuilder()
.append(NEW_LINE)
.append(NEW_LINE)
.append("\t").append(String.format("Connection ID: %s", connectionId))
.append(NEW_LINE)
.append("\t").append(String.format("Execution Time: %s ms", elapsed))
.append(NEW_LINE)
.append(NEW_LINE)
.append("\t").append(String.format("Call Stack (number 1 is entry point): %s", callStackBuilder))
.append(NEW_LINE)
.append(NEW_LINE)
.append("------------------------------------------------------------------------------------------------")
.toString();
}

private StringBuilder getStackBuilder() {
final Stack<String> callStack = new Stack<>();
stream(new Throwable().getStackTrace())
.map(StackTraceElement::toString)
.filter(isExcludeWords())
.forEach(callStack::push);

int order = 1;
final StringBuilder callStackBuilder = new StringBuilder();
while (!callStack.empty()) {
callStackBuilder.append(MessageFormat.format("{0}\t\t{1}. {2}", NEW_LINE, order++, callStack.pop()));
}
return callStackBuilder;
}

private Predicate<String> isExcludeWords() {
return charSequence -> charSequence.startsWith(PACKAGE) && !charSequence.contains(P6SPY_FORMATTER);
}
}
Loading

0 comments on commit 6b958ff

Please sign in to comment.