diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml new file mode 100644 index 00000000..b8e110a5 --- /dev/null +++ b/.github/workflows/dev-deploy.yml @@ -0,0 +1,31 @@ +name: Deploy development profile about lotdiz +on: + workflow_dispatch: + push: + branches: + - 'develop' +env: + DOCKERHUB_USERNAME: ${{ secrets.DEV_DOCKER_ID }} + DOCKERHUB_PASSWORD: ${{ secrets.DEV_DOCKER_PW }} + DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} +jobs: + deploy: + needs: test + environment: develop + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ env.DOCKERHUB_PASSWORD }} + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_REPOSITORY }}:product \ No newline at end of file diff --git a/build.gradle b/build.gradle index 81f16cc4..814f8402 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'org.springframework.boot' version '2.7.17' id 'io.spring.dependency-management' version '1.0.15.RELEASE' + id 'jacoco' } group = 'kr.bb' @@ -36,9 +37,12 @@ dependencies { implementation "org.springframework.cloud:spring-cloud-starter-bus-kafka" implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'mysql:mysql-connector-java:8.0.33' - implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '0.1.0-alpha1' + implementation group: 'io.github.lotteon-maven', name: 'blooming-blooms-utils', version: '0.1.0-alpha2' // https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb implementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.12.592' + runtimeOnly 'com.h2database:h2' + implementation 'org.mapstruct:mapstruct:1.5.3.Final' + annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.3.Final' } dependencyManagement { @@ -54,3 +58,56 @@ tasks.named('bootBuildImage') { tasks.named('test') { useJUnitPlatform() } + +// jacoco +jacoco { + toolVersion = '0.8.5' +} + +jacocoTestCoverageVerification { + violationRules { + rule { + enabled = true + element = 'CLASS' + + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + minimum = 0.80 + } + excludes = ["*.mapper*"] + } + } +} + +test { + jacoco { + destinationFile = file("$buildDir/jacoco/jacoco.exec") + } + useJUnitPlatform() + finalizedBy 'jacocoTestReport' +} + +jacocoTestReport { + reports { + html.required = true + } + def Qdomains = [] + for (qPattern in '**/QA'..'**/QZ') { + Qdomains.add(qPattern + '*') + } + afterEvaluate { + classDirectories.setFrom( + files(classDirectories.files.collect { + fileTree(dir: it, excludes: [ + "**/*Application*", + "**/*generated*", + "**/*mapper*", + "**/*Config*", + "**/*Dto*", + ] + Qdomains) + }) + ) + } + finalizedBy 'jacocoTestCoverageVerification' +} \ No newline at end of file diff --git a/lombok.config b/lombok.config new file mode 100644 index 00000000..8f7e8aa1 --- /dev/null +++ b/lombok.config @@ -0,0 +1 @@ +lombok.addLombokGeneratedAnnotation = true \ No newline at end of file diff --git a/src/main/java/kr/bb/product/dto/category/Category.java b/src/main/java/kr/bb/product/dto/category/Category.java new file mode 100644 index 00000000..fc041d03 --- /dev/null +++ b/src/main/java/kr/bb/product/dto/category/Category.java @@ -0,0 +1,17 @@ +package kr.bb.product.dto.category; + +import kr.bb.product.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Category extends BaseEntity { + private Long id; + private String categoryName; +} diff --git a/src/main/java/kr/bb/product/dto/tag/Tag.java b/src/main/java/kr/bb/product/dto/tag/Tag.java new file mode 100644 index 00000000..5daccdb5 --- /dev/null +++ b/src/main/java/kr/bb/product/dto/tag/Tag.java @@ -0,0 +1,17 @@ +package kr.bb.product.dto.tag; + +import kr.bb.product.entity.BaseEntity; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +public class Tag extends BaseEntity { + private Long id; + private String categoryName; +} diff --git a/src/main/java/kr/bb/product/entity/Category.java b/src/main/java/kr/bb/product/entity/Category.java deleted file mode 100644 index 28df8bd1..00000000 --- a/src/main/java/kr/bb/product/entity/Category.java +++ /dev/null @@ -1,29 +0,0 @@ -package kr.bb.product.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Builder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@Entity -@Table(name = "category") -public class Category extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "category_id") - private Long id; - - @Column(name = "category_name") - private String categoryName; -} diff --git a/src/main/java/kr/bb/product/entity/Product.java b/src/main/java/kr/bb/product/entity/Product.java index 54ca05c0..cac87f68 100644 --- a/src/main/java/kr/bb/product/entity/Product.java +++ b/src/main/java/kr/bb/product/entity/Product.java @@ -4,6 +4,8 @@ import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAutoGeneratedKey; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; +import kr.bb.product.dto.category.Category; +import kr.bb.product.dto.tag.Tag; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.Builder; @@ -31,7 +33,7 @@ public class Product { private Long productPrice; @DynamoDBAttribute(attributeName = "product_sale_status") - private String productSaleStatus; + private ProductSaleStatus productSaleStatus; @DynamoDBAttribute(attributeName = "tag") private Tag tag; diff --git a/src/main/java/kr/bb/product/entity/ProductSaleStatus.java b/src/main/java/kr/bb/product/entity/ProductSaleStatus.java new file mode 100644 index 00000000..88b2b87d --- /dev/null +++ b/src/main/java/kr/bb/product/entity/ProductSaleStatus.java @@ -0,0 +1,14 @@ +package kr.bb.product.entity; + +import lombok.Getter; + +@Getter +public enum ProductSaleStatus { + SALE("판매 중"), + DISCONTINUED("판매 중지"); + private final String message; + + ProductSaleStatus(String message) { + this.message = message; + } +} diff --git a/src/main/java/kr/bb/product/entity/Review.java b/src/main/java/kr/bb/product/entity/Review.java index 7b2a6f0e..066996b8 100644 --- a/src/main/java/kr/bb/product/entity/Review.java +++ b/src/main/java/kr/bb/product/entity/Review.java @@ -1,14 +1,10 @@ package kr.bb.product.entity; -import java.util.List; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.persistence.OneToMany; import javax.persistence.Table; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/src/main/java/kr/bb/product/entity/Tag.java b/src/main/java/kr/bb/product/entity/Tag.java deleted file mode 100644 index 34b380b9..00000000 --- a/src/main/java/kr/bb/product/entity/Tag.java +++ /dev/null @@ -1,29 +0,0 @@ -package kr.bb.product.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Getter -@Builder -@NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@Entity -@Table(name = "tag") -public class Tag extends BaseEntity { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "tag_id") - private Long id; - - @Column(name = "tag_name") - private String categoryName; -} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 00000000..5bd2e59d --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,18 @@ +spring: + cloud: + config: + enabled: false + datasource: + username: sa + password: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL + h2: + console: + enabled: true +aws: + dynamodb: + endpoint: http://localhost:9000 + region: ap-northease-2 + accessKey: accessKey + secretKey: secretKey \ No newline at end of file