diff --git a/src/main/java/api/goraebab/config/AppConfig.java b/src/main/java/api/goraebab/config/AppConfig.java index 5623e2f..b5de6e3 100644 --- a/src/main/java/api/goraebab/config/AppConfig.java +++ b/src/main/java/api/goraebab/config/AppConfig.java @@ -4,9 +4,24 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestClient; +/** + * Configuration class for application-level beans. + * + *
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(); diff --git a/src/main/java/api/goraebab/config/CorsConfig.java b/src/main/java/api/goraebab/config/CorsConfig.java index b82ebf0..b3c5c43 100644 --- a/src/main/java/api/goraebab/config/CorsConfig.java +++ b/src/main/java/api/goraebab/config/CorsConfig.java @@ -4,6 +4,21 @@ 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. + * + *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.
+ * + *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.
+ * + *For more details about CORS in Spring, refer to the Spring Documentation.
+ * + * @author whitem4rk + * @version 1.0 + */ @Configuration public class CorsConfig implements WebMvcConfigurer { diff --git a/src/main/java/api/goraebab/config/JpaConfig.java b/src/main/java/api/goraebab/config/JpaConfig.java index 01c6a3f..38790f9 100644 --- a/src/main/java/api/goraebab/config/JpaConfig.java +++ b/src/main/java/api/goraebab/config/JpaConfig.java @@ -14,6 +14,28 @@ import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; +/** + * Configuration class for JPA and database connection setup. + * + *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.
+ * + *Additionally, this configuration enables JPA auditing, allowing automatic management of entity audit fields.
+ * + *Supported DBMS dialects include:
+ *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 { diff --git a/src/main/java/api/goraebab/domain/remote/database/dto/StorageReqDto.java b/src/main/java/api/goraebab/domain/remote/database/dto/StorageReqDto.java index 30b96f9..fce111a 100644 --- a/src/main/java/api/goraebab/domain/remote/database/dto/StorageReqDto.java +++ b/src/main/java/api/goraebab/domain/remote/database/dto/StorageReqDto.java @@ -13,6 +13,14 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * Request DTO which client sends when connect to DBMS. + * Strict validation check is required. + * + * @author whitem4rk + * @version 1.0 + * @see DBMS + */ @Getter @NoArgsConstructor public class StorageReqDto { diff --git a/src/main/java/api/goraebab/domain/remote/database/dto/StorageResDto.java b/src/main/java/api/goraebab/domain/remote/database/dto/StorageResDto.java index f77353a..8afeb15 100644 --- a/src/main/java/api/goraebab/domain/remote/database/dto/StorageResDto.java +++ b/src/main/java/api/goraebab/domain/remote/database/dto/StorageResDto.java @@ -6,6 +6,14 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * Response DTO which client request details of connected DBMS. + * Password must not be contained. + * + * @author whitem4rk + * @version 1.0 + * @see DBMS + */ @Getter @NoArgsConstructor @Schema(description = "Represents the storage info.") diff --git a/src/main/java/api/goraebab/domain/remote/database/entity/DBMS.java b/src/main/java/api/goraebab/domain/remote/database/entity/DBMS.java index f444b5c..d55ecba 100644 --- a/src/main/java/api/goraebab/domain/remote/database/entity/DBMS.java +++ b/src/main/java/api/goraebab/domain/remote/database/entity/DBMS.java @@ -3,6 +3,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import java.util.Arrays; +/** + * The list of compatible DBMS. + * You can check connection logic in config package. + * + * @author whitem4rk + * @version 1.0 + * @see api.goraebab.config.JpaConfig + */ public enum DBMS { MYSQL, MARIADB, POSTGRESQL, ORACLE, SQLSERVER; diff --git a/src/main/java/api/goraebab/domain/remote/database/entity/Storage.java b/src/main/java/api/goraebab/domain/remote/database/entity/Storage.java index 3086c47..f8b1a2d 100644 --- a/src/main/java/api/goraebab/domain/remote/database/entity/Storage.java +++ b/src/main/java/api/goraebab/domain/remote/database/entity/Storage.java @@ -15,6 +15,16 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * Represents a storage entity that contains information about a database connection. + * + *Instances of this class are typically used to persist and retrieve storage configurations + * from the database.
+ * + * @author whitem4rk + * @version 1.0 + * @see BaseEntity + */ @Getter @Entity @Table(name = "storage") @@ -44,6 +54,16 @@ public class Storage extends BaseEntity { @Column(nullable = false) private String password; + /** + * Constructs a new {@link Storage} instance using the specified parameters. + * + * @param host the host address of the database server. + * @param port the port number of the database server. + * @param dbms the type of database management system. + * @param name the custom name of the connection. + * @param username the username for database authentication. + * @param password the password for database authentication. + */ @Builder public Storage(String host, Integer port, DBMS dbms, String name, String username, String password) { diff --git a/src/main/java/api/goraebab/domain/remote/database/mapper/StorageMapper.java b/src/main/java/api/goraebab/domain/remote/database/mapper/StorageMapper.java index f138112..9b10a13 100644 --- a/src/main/java/api/goraebab/domain/remote/database/mapper/StorageMapper.java +++ b/src/main/java/api/goraebab/domain/remote/database/mapper/StorageMapper.java @@ -8,6 +8,14 @@ import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; +/** + * Mapper interface for converting between {@link Storage} entities and their corresponding DTOs. + * + *This interface uses MapStruct for generating implementation code at compile time.
+ * + * @author whitem4rk + * @version 1.0 + */ @Mapper public interface StorageMapper { diff --git a/src/main/java/api/goraebab/domain/remote/database/repository/StorageRepository.java b/src/main/java/api/goraebab/domain/remote/database/repository/StorageRepository.java index 5747d14..e29d645 100644 --- a/src/main/java/api/goraebab/domain/remote/database/repository/StorageRepository.java +++ b/src/main/java/api/goraebab/domain/remote/database/repository/StorageRepository.java @@ -3,6 +3,23 @@ import api.goraebab.domain.remote.database.entity.Storage; import org.springframework.data.jpa.repository.JpaRepository; +/** + * Repository interface for managing {@link Storage} entities. + * + *Extends the {@link JpaRepository} interface to provide CRUD operations and + * additional query methods for {@link Storage} objects.
+ * + *This interface is a Spring Data JPA repository and will be implemented automatically + * by Spring at runtime.
+ * + *Note: This repository currently does not include QueryDSL integration. + * If you need to perform complex dynamic queries with type safety, you may consider + * adding a custom repository interface and implementing QueryDSL functionality.
+ * + * @author whitem4rk + * @version 1.0 + * @see org.springframework.data.jpa.repository.JpaRepository + */ public interface StorageRepository extends JpaRepositoryThis interface provides methods for retrieving, connecting, deleting, and copying storage configurations.
+ * + * @author whitem4rk + * @version 1.0 + */ public interface StorageService { ListThis method validates the storage configuration by attempting to execute a query on the target storage. + * If the connection is successful, the storage details are mapped to a {@link Storage} entity and persisted in the repository.
+ * + * @param storageReqDto the {@link StorageReqDto} containing the storage configuration details, such as host, port, username, and password. + * @throws CustomException if the connection fails ({@link ErrorCode#CONNECTION_FAILED}). + * @see ConnectionUtil + */ @Override @Transactional public void connectStorage(StorageReqDto storageReqDto) { @@ -64,6 +80,13 @@ public void deleteStorage(Long storageId) { } } + /** + * Copies all blueprints which are stored in target storage to local storage. + * This functionality allows users to import blueprints created on another server into the currently active server. + * + * @param storageId the ID of the storage whose blueprints are to be copied. + * @throws CustomException if the storage is not found ({@link ErrorCode#NOT_FOUND_VALUE}) or if the copy operation fails ({@link ErrorCode#COPY_FAILED}). + */ @Override @Transactional public void copyStorage(Long storageId) { diff --git a/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonReqDto.java b/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonReqDto.java index dd3bee9..eb69fb7 100644 --- a/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonReqDto.java +++ b/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonReqDto.java @@ -10,6 +10,12 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * Request DTO which Client sends when connect to remote Docker daemon + * + * @author whitem4rk + * @version 1.0 + */ @Getter @NoArgsConstructor public class DaemonReqDto { diff --git a/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonResDto.java b/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonResDto.java index 576ae59..62c0f72 100644 --- a/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonResDto.java +++ b/src/main/java/api/goraebab/domain/remote/docker/dto/DaemonResDto.java @@ -5,6 +5,12 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * Response DTO which client request list of Docker daemon connections. + * + * @author whitem4rk + * @version 1.0 + */ @Getter @NoArgsConstructor public class DaemonResDto { diff --git a/src/main/java/api/goraebab/domain/remote/docker/entity/Daemon.java b/src/main/java/api/goraebab/domain/remote/docker/entity/Daemon.java index a13edce..870635e 100644 --- a/src/main/java/api/goraebab/domain/remote/docker/entity/Daemon.java +++ b/src/main/java/api/goraebab/domain/remote/docker/entity/Daemon.java @@ -12,6 +12,18 @@ import lombok.Getter; import lombok.NoArgsConstructor; +/** + * Entity class representing a Daemon, which typically refers to a background process running on a + * specific host and port with a given name. This class is mapped to the "daemon" table in the + * database. + * + *This class extends {@code BaseEntity}, which may include common fields like + * creation and update timestamps. + * + * @author whitem4rk + * @version 1.0 + * @see BaseEntity + */ @Getter @Entity @Table(name = "daemon") diff --git a/src/main/java/api/goraebab/domain/remote/docker/mapper/DaemonMapper.java b/src/main/java/api/goraebab/domain/remote/docker/mapper/DaemonMapper.java index 64ad04f..28e1c76 100644 --- a/src/main/java/api/goraebab/domain/remote/docker/mapper/DaemonMapper.java +++ b/src/main/java/api/goraebab/domain/remote/docker/mapper/DaemonMapper.java @@ -8,6 +8,14 @@ import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; +/** + * Mapper interface for converting between {@link Daemon} entities and their corresponding DTOs. + * + *
This interface uses MapStruct to generate the implementation at compile time, ensuring efficient and type-safe mapping.
+ * + * @author whitem4rk + * @version 1.0 + */ @Mapper public interface DaemonMapper { diff --git a/src/main/java/api/goraebab/domain/remote/docker/repository/DaemonRepository.java b/src/main/java/api/goraebab/domain/remote/docker/repository/DaemonRepository.java index dc176dc..b8830c7 100644 --- a/src/main/java/api/goraebab/domain/remote/docker/repository/DaemonRepository.java +++ b/src/main/java/api/goraebab/domain/remote/docker/repository/DaemonRepository.java @@ -1,7 +1,25 @@ package api.goraebab.domain.remote.docker.repository; +import api.goraebab.domain.remote.database.entity.Storage; import api.goraebab.domain.remote.docker.entity.Daemon; import org.springframework.data.jpa.repository.JpaRepository; +/** + * Repository interface for managing {@link Storage} entities. + * + *Extends the {@link JpaRepository} interface to provide CRUD operations and + * additional query methods for {@link Storage} objects.
+ * + *This interface is a Spring Data JPA repository and will be implemented automatically + * by Spring at runtime.
+ * + *Note: This repository currently does not include QueryDSL integration. + * If you need to perform complex dynamic queries with type safety, you may consider + * adding a custom repository interface and implementing QueryDSL functionality.
+ * + * @author whitem4rk + * @version 1.0 + * @see org.springframework.data.jpa.repository.JpaRepository + */ public interface DaemonRepository extends JpaRepositoryThis interface provides methods for retrieving, connecting and deleting daemon configurations.
+ * + * @author whitem4rk + * @version 1.0 + */ public interface DaemonService { ListThis service handles operations such as retrieving all daemons, connecting a new daemon, + * and deleting existing daemons. It interacts with the {@link DaemonRepository} for data persistence + * and uses {@link DaemonMapper} for entity-DTO conversions.
+ * + * @author whitem4rk + * @version 1.0 + * @see ConnectionUtil + */ @Service @RequiredArgsConstructor public class DaemonServiceImpl implements DaemonService { @@ -28,6 +40,16 @@ public ListThe method validates the connection to the daemon using {@link ConnectionUtil#testDockerPing}, + * and if successful, maps the provided {@link DaemonReqDto} to a {@link Daemon} entity and saves it + * to the database.
+ * + * @param daemonReqDto the {@link DaemonReqDto} containing the connection details for the daemon. + * @throws CustomException if the connection to the daemon fails ({@link ErrorCode#CONNECTION_FAILED}). + */ @Override public void connectDaemon(DaemonReqDto daemonReqDto) { boolean connected = ConnectionUtil.testDockerPing(daemonReqDto.getHost(), daemonReqDto.getPort()); diff --git a/src/main/java/api/goraebab/global/entity/BaseEntity.java b/src/main/java/api/goraebab/global/entity/BaseEntity.java index 0d5eb26..f65d5f1 100644 --- a/src/main/java/api/goraebab/global/entity/BaseEntity.java +++ b/src/main/java/api/goraebab/global/entity/BaseEntity.java @@ -9,6 +9,20 @@ import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; +/** + * Abstract base class for entities, providing audit fields for creation and modification timestamps. + * + *This class is annotated as a {@link MappedSuperclass}, meaning its fields are inherited by subclasses + * and mapped to the corresponding database table columns.
+ * + *Note: For compatibility, columnDefinition about time fields was set to TIMESTAMP(0). + * This method was the most universal. However, since the table definition is done + * according to dbms through init.sql, it is not a big problem, + * and if a dbms type is added, it must be set accordingly.
+ * + * @author whitem4rk + * @version 1.0 + */ @MappedSuperclass @EntityListeners(AuditingEntityListener.class) @Getter diff --git a/src/main/java/api/goraebab/global/exception/CustomException.java b/src/main/java/api/goraebab/global/exception/CustomException.java index ac63410..e5376de 100644 --- a/src/main/java/api/goraebab/global/exception/CustomException.java +++ b/src/main/java/api/goraebab/global/exception/CustomException.java @@ -5,6 +5,20 @@ import java.util.List; import java.util.Map; +/** + * Custom exception class for handling application-specific errors. + * + *This exception extends {@link RuntimeException}, allowing it to be used for unchecked exceptions. + * It includes additional fields for capturing detailed information about the error. + * + *
Provides multiple constructors for different use cases, including custom error messages, + * nested exceptions, and additional metadata.
+ * + * @author whitem4rk + * @version 1.0 + * @see RuntimeException + * @see ErrorCode + */ @Getter public class CustomException extends RuntimeException {