Skip to content

Commit

Permalink
Merge pull request #74 from Team-Goraebab/develop
Browse files Browse the repository at this point in the history
Merge develop into main branch
  • Loading branch information
whitem4rk authored Dec 3, 2024
2 parents 627320d + 8b71c35 commit bb40213
Show file tree
Hide file tree
Showing 63 changed files with 2,688 additions and 1,960 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
gradlew text eol=lf
* text=auto
*.java text eol=lf
*.sh text eol=lf
*.bat text eol=crlf
21 changes: 21 additions & 0 deletions .github/workflows/spotless-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Spotless Check

on: [push, pull_request]

jobs:
spotless-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'adopt'

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Run Spotless Check
run: ./gradlew spotlessCheck
26 changes: 24 additions & 2 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.8'
id 'io.spring.dependency-management' version '1.1.6'
id "com.diffplug.spotless" version "6.11.0"
}

group = 'api'
Expand Down Expand Up @@ -58,11 +59,32 @@ dependencies {

implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'jakarta.activation:jakarta.activation-api:2.1.3'

implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
implementation 'org.apache.httpcomponents:httpclient:4.5.14'
}

spotless {
java {
importOrder(
"java",
"javax",
"lombok",
"org.springframework",
"",
"org.junit",
"com.guide"
)
removeUnusedImports()
googleJavaFormat()
endWithNewline()
}
}

tasks.named('test') {
useJUnitPlatform()
}

tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
options.docEncoding = 'UTF-8'
options.charSet = 'UTF-8'
}
1 change: 0 additions & 1 deletion src/main/java/api/goraebab/GoraebabApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public class GoraebabApplication {
public static void main(String[] args) {
SpringApplication.run(GoraebabApplication.class, args);
}

}
18 changes: 16 additions & 2 deletions src/main/java/api/goraebab/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;

/**
* Configuration class for application-level beans.
*
* <p>This class defines beans that are required across the application, ensuring centralized
* management and reusability of these components.
*
* @author whitem4rk
* @version 1.0
*/
@Configuration
public class AppConfig {

/**
* Creates and returns a {@link RestClient} bean for making HTTP requests.
*
* @return a configured instance of {@link RestClient}.
* @see api.goraebab.global.util.ConnectionUtil
*/
@Bean
public RestClient restClient() {
return RestClient.create();
}

}
}
23 changes: 20 additions & 3 deletions src/main/java/api/goraebab/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
package api.goraebab.config;
package api.goraebab.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Configuration class for setting up Cross-Origin Resource Sharing (CORS) rules.
*
* <p>This configuration allows the application to handle requests from different origins, enabling
* cross-origin communication for frontend-backend interactions in a secure and configurable way.
*
* <p>Note: While this configuration is useful for rapid development and testing, a more restrictive
* policy is recommended for production environments to prevent potential security risks such as
* unauthorized access from malicious origins.
*
* <p>For more details about CORS in Spring, refer to the <a
* href="https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-cors">Spring
* Documentation</a>.
*
* @author whitem4rk
* @version 1.0
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
registry
.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("*")
.allowCredentials(true);
}

}
45 changes: 35 additions & 10 deletions src/main/java/api/goraebab/config/JpaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

/**
* Configuration class for JPA and database connection setup.
*
* <p>This class configures database-related properties, including dialect detection based on the
* {@code spring.datasource.url}, and provides a {@link DataSource} bean for database access.
*
* <p>Additionally, this configuration enables JPA auditing, allowing automatic management of entity
* audit fields.
*
* <p>Supported DBMS dialects include:
*
* <ul>
* <li>MySQL
* <li>MariaDB
* <li>PostgreSQL
* <li>Oracle
* <li>SQL Server
* </ul>
*
* @author whitem4rk
* @version 1.0
* @see JpaProperties
* @see DataSource
*/
@Configuration
@EnableJpaAuditing
public class JpaConfig {
Expand All @@ -36,16 +60,17 @@ public class JpaConfig {
private static final String MYSQL_DIALECT = "org.hibernate.dialect.MySQL8Dialect";
private static final String MARIADB_DIALECT = "org.hibernate.dialect.MariaDBDialect";
private static final String POSTGRESQL_DIALECT = "org.hibernate.dialect.PostgreSQLDialect";
private static final String ORACLE_DIALECT = "org.hibernate.dialect.OracleDialect";
private static final String ORACLE_DIALECT = "org.hibernate.dialect.OracleDialect";
private static final String SQLSERVER_DIALECT = "org.hibernate.dialect.SQLServerDialect";

private static final EnumMap<DBMS, String> DIALECT_MAP = new EnumMap<>(Map.of(
MYSQL, MYSQL_DIALECT,
MARIADB, MARIADB_DIALECT,
POSTGRESQL, POSTGRESQL_DIALECT,
ORACLE, ORACLE_DIALECT,
SQLSERVER, SQLSERVER_DIALECT
));
private static final EnumMap<DBMS, String> DIALECT_MAP =
new EnumMap<>(
Map.of(
MYSQL, MYSQL_DIALECT,
MARIADB, MARIADB_DIALECT,
POSTGRESQL, POSTGRESQL_DIALECT,
ORACLE, ORACLE_DIALECT,
SQLSERVER, SQLSERVER_DIALECT));

public JpaConfig(JpaProperties jpaProperties) {
this.jpaProperties = jpaProperties;
Expand All @@ -66,7 +91,8 @@ private DBMS getDatasourceType(String datasourceUrl) {
return DIALECT_MAP.keySet().stream()
.filter(dbms -> datasourceUrl.toUpperCase().contains(dbms.name()))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Unsupported Database Type: " + datasourceUrl));
.orElseThrow(
() -> new IllegalArgumentException("Unsupported Database Type: " + datasourceUrl));
}

@Bean
Expand All @@ -78,5 +104,4 @@ public DataSource dataSource() {
.driverClassName(driverClassName)
.build();
}

}
28 changes: 17 additions & 11 deletions src/main/java/api/goraebab/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,32 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for Swagger/OpenAPI documentation.
*
* <p>This configuration sets up the OpenAPI documentation for the application, providing metadata
* about the API such as its title, description, and version. The documentation helps developers
* understand and interact with the API effectively.
*
* @author whitem4rk
* @version 1.0
* @see OpenAPI
* @see Info
*/
@Configuration
public class SwaggerConfig {

private static final String API_TITLE = "Goraebab API";
private static final String API_CONTENT = "Goraebab helps Docker starters to easily configure Docker";
private static final String API_CONTENT =
"Goraebab helps Docker starters to easily configure Docker";
private static final String API_VERSION = "1.0.0";


@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.components(new Components())
.info(apiInfo());
return new OpenAPI().components(new Components()).info(apiInfo());
}

private Info apiInfo() {
return new Info()
.title(API_TITLE)
.description(API_CONTENT)
.version(API_VERSION);
return new Info().title(API_TITLE).description(API_CONTENT).version(API_VERSION);
}

}
}
Loading

0 comments on commit bb40213

Please sign in to comment.