From cda46248dfc042db3c7d68d77433116ac6cc0c3a Mon Sep 17 00:00:00 2001 From: TakahashiNguyen Date: Wed, 25 Mar 2026 02:08:19 +0000 Subject: [PATCH] feat(eatery-service): init with tests (#3) Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Co-authored-by: gitea-actions Co-authored-by: TranHuuDanh Reviewed-on: https://git.demonkernel.io.vn/FoodSurf/backend/pulls/3 --- .gitea/workflows/test.yaml | 36 +++ .github/dependabot.yml | 12 - CHANGELOG.md | 7 + account-service/pom.xml | 11 +- .../com/drinkool/entities/CustomerEntity.java | 8 + .../java/com/drinkool/models/Customer.java | 7 - .../models/{User.java => UserModel.java} | 10 +- .../AuthenticationService.java} | 16 +- .../src/main/resources/application.properties | 13 +- .../com/drinkool/models/UserModelTest.java | 41 +++ .../src/test/resources/application.properties | 9 + eatery-service/.dockerignore | 5 + .../.mvn/wrapper/maven-wrapper.properties | 4 + eatery-service/README.md | 79 +++++ eatery-service/mvnw | 295 ++++++++++++++++++ eatery-service/mvnw.cmd | 189 +++++++++++ eatery-service/pom.xml | 163 ++++++++++ eatery-service/src/main/docker/Dockerfile.jvm | 100 ++++++ .../src/main/docker/Dockerfile.legacy-jar | 96 ++++++ .../src/main/docker/Dockerfile.native | 29 ++ .../src/main/docker/Dockerfile.native-micro | 32 ++ .../entities/InventoryItemEntity.java | 29 ++ .../com/drinkool/entities/ReviewEntity.java | 28 ++ .../drinkool/services/InventoryService.java | 22 ++ .../com/drinkool/services/ReviewService.java | 22 ++ .../src/main/resources/application.properties | 16 + eatery-service/src/main/resources/import.sql | 6 + .../services/InventoryServiceTest.java | 36 +++ .../drinkool/services/ReviewServiceTest.java | 44 +++ .../src/test/resources/application.properties | 9 + gateway-service/pom.xml | 2 +- .../src/main/resources/application.properties | 4 - .../java/com/drinkool/GreetingResourceIT.java | 8 - .../com/drinkool/GreetingResourceTest.java | 21 -- .../drinkool/MyMessagingApplicationTest.java | 20 -- lib/pom.xml | 15 +- .../java/com/drinkool/dtos/AddInventory.java | 8 + .../java/com/drinkool/dtos/SendReview.java | 11 + .../com/drinkool/entities/BaseEntity.java | 13 + .../java/com/drinkool/models/ReviewModel.java | 19 ++ pom.xml | 3 +- 41 files changed, 1401 insertions(+), 97 deletions(-) create mode 100644 .gitea/workflows/test.yaml delete mode 100644 .github/dependabot.yml create mode 100644 account-service/src/main/java/com/drinkool/entities/CustomerEntity.java delete mode 100644 account-service/src/main/java/com/drinkool/models/Customer.java rename account-service/src/main/java/com/drinkool/models/{User.java => UserModel.java} (86%) rename account-service/src/main/java/com/drinkool/{RestAPI.java => services/AuthenticationService.java} (82%) create mode 100644 account-service/src/test/java/com/drinkool/models/UserModelTest.java create mode 100644 account-service/src/test/resources/application.properties create mode 100644 eatery-service/.dockerignore create mode 100644 eatery-service/.mvn/wrapper/maven-wrapper.properties create mode 100644 eatery-service/README.md create mode 100755 eatery-service/mvnw create mode 100644 eatery-service/mvnw.cmd create mode 100644 eatery-service/pom.xml create mode 100644 eatery-service/src/main/docker/Dockerfile.jvm create mode 100644 eatery-service/src/main/docker/Dockerfile.legacy-jar create mode 100644 eatery-service/src/main/docker/Dockerfile.native create mode 100644 eatery-service/src/main/docker/Dockerfile.native-micro create mode 100644 eatery-service/src/main/java/com/drinkool/entities/InventoryItemEntity.java create mode 100644 eatery-service/src/main/java/com/drinkool/entities/ReviewEntity.java create mode 100644 eatery-service/src/main/java/com/drinkool/services/InventoryService.java create mode 100644 eatery-service/src/main/java/com/drinkool/services/ReviewService.java create mode 100644 eatery-service/src/main/resources/application.properties create mode 100644 eatery-service/src/main/resources/import.sql create mode 100644 eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java create mode 100644 eatery-service/src/test/java/com/drinkool/services/ReviewServiceTest.java create mode 100644 eatery-service/src/test/resources/application.properties delete mode 100644 gateway-service/src/test/java/com/drinkool/GreetingResourceIT.java delete mode 100644 gateway-service/src/test/java/com/drinkool/GreetingResourceTest.java delete mode 100644 gateway-service/src/test/java/com/drinkool/MyMessagingApplicationTest.java create mode 100644 lib/src/main/java/com/drinkool/dtos/AddInventory.java create mode 100644 lib/src/main/java/com/drinkool/dtos/SendReview.java create mode 100644 lib/src/main/java/com/drinkool/entities/BaseEntity.java create mode 100644 lib/src/main/java/com/drinkool/models/ReviewModel.java diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml new file mode 100644 index 0000000..77fa5f3 --- /dev/null +++ b/.gitea/workflows/test.yaml @@ -0,0 +1,36 @@ +name: Java CI with Maven + +on: + push: + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Set up JDK + uses: actions/setup-java@v5 + with: + distribution: "temurin" + java-version: "25" + + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build and Test all modules + run: ./mvnw -B clean verify -Dquarkus.container-image.build=false -Dquarkus.container-image.push=false + + - name: Publish Test Report + uses: scacap/action-surefire-report@v1 + if: failure() + with: + github_token: ${{ secrets.ACCESS_TOKEN }} diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index f33a02c..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,12 +0,0 @@ -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for more information: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates -# https://containers.dev/guide/dependabot - -version: 2 -updates: - - package-ecosystem: "devcontainers" - directory: "/" - schedule: - interval: weekly diff --git a/CHANGELOG.md b/CHANGELOG.md index cfabed5..ecb2242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.1.0-dev.1](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.0.0...v1.1.0-dev.1) (2026-03-24) + + +### Features + +* add inventory entity, service, test ([5a72c9f](https://git.demonkernel.io.vn/FoodSurf/backend/commit/5a72c9f9e38cd9f00fe3884d9ddc52675324bd31)) + # [1.0.0-dev.21](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.0.0-dev.20...v1.0.0-dev.21) (2026-03-23) diff --git a/account-service/pom.xml b/account-service/pom.xml index a6edf70..55972ca 100644 --- a/account-service/pom.xml +++ b/account-service/pom.xml @@ -9,7 +9,7 @@ com.drinkool drinkool - 1.0.0-dev.21 + 1.1.0-dev.1 ../pom.xml @@ -48,6 +48,11 @@ lib ${project.version} + + io.quarkus + quarkus-jdbc-h2 + test + io.quarkus quarkus-hibernate-orm-panache @@ -143,8 +148,8 @@ @{argLine} - ${project.build.directory}/${project.build.finalName}-runner + + ${project.build.directory}/${project.build.finalName}-runner org.jboss.logmanager.LogManager ${maven.home} diff --git a/account-service/src/main/java/com/drinkool/entities/CustomerEntity.java b/account-service/src/main/java/com/drinkool/entities/CustomerEntity.java new file mode 100644 index 0000000..5824f0c --- /dev/null +++ b/account-service/src/main/java/com/drinkool/entities/CustomerEntity.java @@ -0,0 +1,8 @@ +package com.drinkool.entities; + +import com.drinkool.models.UserModel; +import jakarta.persistence.*; + +@Entity +@Table(name = "customer") +public class CustomerEntity extends UserModel {} diff --git a/account-service/src/main/java/com/drinkool/models/Customer.java b/account-service/src/main/java/com/drinkool/models/Customer.java deleted file mode 100644 index 491137f..0000000 --- a/account-service/src/main/java/com/drinkool/models/Customer.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.drinkool.models; - -import jakarta.persistence.*; - -@Entity -@Table(name = "customer") -public class Customer extends User {} diff --git a/account-service/src/main/java/com/drinkool/models/User.java b/account-service/src/main/java/com/drinkool/models/UserModel.java similarity index 86% rename from account-service/src/main/java/com/drinkool/models/User.java rename to account-service/src/main/java/com/drinkool/models/UserModel.java index debaf29..078614d 100644 --- a/account-service/src/main/java/com/drinkool/models/User.java +++ b/account-service/src/main/java/com/drinkool/models/UserModel.java @@ -1,8 +1,8 @@ package com.drinkool.models; +import com.drinkool.entities.BaseEntity; import com.drinkool.utils.PhoneValidator; import com.password4j.Password; -import io.quarkus.hibernate.orm.panache.PanacheEntity; import jakarta.persistence.*; import jakarta.transaction.*; import jakarta.ws.rs.BadRequestException; @@ -11,7 +11,7 @@ import java.util.UUID; @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "users") -public abstract class User extends PanacheEntity { +public abstract class UserModel extends BaseEntity { @Column(nullable = false) public String name; @@ -22,10 +22,6 @@ public abstract class User extends PanacheEntity { @Column(nullable = false, length = 1024) public String hashedPassword; - public User() { - super(); - } - @Transactional public void signup(String phone) { this.signup(phone, phone, UUID.randomUUID().toString().substring(0, 32)); @@ -34,7 +30,7 @@ public abstract class User extends PanacheEntity { @Transactional public void signup(String name, String phone, String rawPassword) { // Check existed user - Customer existedUser = User.find("phone", phone).firstResult(); + UserModel existedUser = find("phone", phone).firstResult(); if (existedUser != null) throw new BadRequestException("ExistedUser"); diff --git a/account-service/src/main/java/com/drinkool/RestAPI.java b/account-service/src/main/java/com/drinkool/services/AuthenticationService.java similarity index 82% rename from account-service/src/main/java/com/drinkool/RestAPI.java rename to account-service/src/main/java/com/drinkool/services/AuthenticationService.java index 899474f..fe2cbdf 100644 --- a/account-service/src/main/java/com/drinkool/RestAPI.java +++ b/account-service/src/main/java/com/drinkool/services/AuthenticationService.java @@ -1,15 +1,14 @@ -package com.drinkool; +package com.drinkool.services; import com.drinkool.dtos.*; -import com.drinkool.models.Customer; -import com.drinkool.services.*; +import com.drinkool.entities.CustomerEntity; import jakarta.inject.Inject; import jakarta.transaction.Transactional; import jakarta.ws.rs.*; import jakarta.ws.rs.core.*; @Path("/api") -public class RestAPI { +public class AuthenticationService { @Inject OtpService otpService; @@ -18,7 +17,7 @@ public class RestAPI { @Path("/signup") @Transactional public Response signup(Signup input) { - Customer newCustomer = new Customer(); + CustomerEntity newCustomer = new CustomerEntity(); newCustomer.signup(input.name, input.phone, input.password); @@ -29,7 +28,7 @@ public class RestAPI { @Path("/quickSignup") @Transactional public Response quickSignup(QuickSignup input) { - Customer newCustomer = new Customer(); + CustomerEntity newCustomer = new CustomerEntity(); newCustomer.signup(input.phone); @@ -39,7 +38,10 @@ public class RestAPI { @POST @Path("/login") public Response login(Login input) { - Customer customer = Customer.find("phone", input.phone).firstResult(); + CustomerEntity customer = CustomerEntity.find( + "phone", + input.phone + ).firstResult(); if (customer == null) throw new BadRequestException("InvalidPhoneNumber"); diff --git a/account-service/src/main/resources/application.properties b/account-service/src/main/resources/application.properties index e2e690f..857f702 100644 --- a/account-service/src/main/resources/application.properties +++ b/account-service/src/main/resources/application.properties @@ -1,13 +1,13 @@ -# Cấu hình Database +# Database quarkus.datasource.db-kind=postgresql quarkus.datasource.username=postgres quarkus.datasource.password=password quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres -# Tự động tạo bảng từ Entity (chỉ dùng cho môi trường dev) quarkus.hibernate-orm.database.generation=update -# URL của Gitea Registry (thường là gitea.yourdomain.com) +# Docker +## URL của Gitea Registry (thường là gitea.yourdomain.com) quarkus.container-image.registry=git.demonkernel.io.vn quarkus.container-image.group=foodsurf quarkus.container-image.name=account-service @@ -16,4 +16,9 @@ quarkus.container-image.build=true quarkus.container-image.builder=docker # Redis -quarkus.redis.hosts=redis://localhost:6379 \ No newline at end of file +quarkus.redis.hosts=redis://localhost:6379 + + +# Dependency +quarkus.index-dependency.lib.group-id=com.drinkool +quarkus.index-dependency.lib.artifact-id=lib \ No newline at end of file diff --git a/account-service/src/test/java/com/drinkool/models/UserModelTest.java b/account-service/src/test/java/com/drinkool/models/UserModelTest.java new file mode 100644 index 0000000..5c8e8fc --- /dev/null +++ b/account-service/src/test/java/com/drinkool/models/UserModelTest.java @@ -0,0 +1,41 @@ +package com.drinkool.models; + +import static org.junit.jupiter.api.Assertions.*; + +import io.quarkus.test.junit.QuarkusTest; +import jakarta.persistence.*; +import jakarta.transaction.Transactional; +import java.util.*; +import org.junit.jupiter.api.Test; + +@Entity +@Table +class TestUserEntity extends UserModel {} + +@QuarkusTest +public class UserModelTest { + + @Test + @Transactional + public void testSignupSuccess() { + //dang nhap thanh cong + TestUserEntity user = new TestUserEntity(); + String phone = + "+8477" + String.format("%07d", (new Random()).nextInt(10000000)); + String password = "02092006Danh"; + user.signup("Tran Huu Danh", phone, password); + + assertNotNull(user.id, "ID not null after persist"); + assertEquals("Tran Huu Danh", user.name); + assertEquals(phone, user.phone); + assertNotNull(user.hashedPassword, "password phai hash"); + + TestUserEntity savedUser = TestUserEntity.find( + "phone", + phone + ).firstResult(); + assertNotNull(savedUser); + } + // 2. Test case: Đăng ký thất bại do số điện thoại đã tồn tại + // 3. Test case: Đăng ký thất bại do số điện thoại sai định dạng +} diff --git a/account-service/src/test/resources/application.properties b/account-service/src/test/resources/application.properties new file mode 100644 index 0000000..1566eab --- /dev/null +++ b/account-service/src/test/resources/application.properties @@ -0,0 +1,9 @@ +# Database +%test.quarkus.datasource.db-kind=h2 +%test.quarkus.datasource.jdbc.url=jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1 + +%test.quarkus.hibernate-orm.database.generation=drop-and-create + +# Docker +%test.quarkus.container-image.build=false +%test.quarkus.container-image.push=false \ No newline at end of file diff --git a/eatery-service/.dockerignore b/eatery-service/.dockerignore new file mode 100644 index 0000000..94810d0 --- /dev/null +++ b/eatery-service/.dockerignore @@ -0,0 +1,5 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* +!target/quarkus-app/* \ No newline at end of file diff --git a/eatery-service/.mvn/wrapper/maven-wrapper.properties b/eatery-service/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..533e775 --- /dev/null +++ b/eatery-service/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,4 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip +distributionSha256Sum=305773a68d6ddfd413df58c82b3f8050e89778e777f3a745c8e5b8cbea4018ef diff --git a/eatery-service/README.md b/eatery-service/README.md new file mode 100644 index 0000000..1824ac6 --- /dev/null +++ b/eatery-service/README.md @@ -0,0 +1,79 @@ +# eatery-service + +This project uses Quarkus, the Supersonic Subatomic Java Framework. + +If you want to learn more about Quarkus, please visit its website: . + +## Running the application in dev mode + +You can run your application in dev mode that enables live coding using: + +```shell script +./mvnw quarkus:dev +``` + +> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at . + +## Packaging and running the application + +The application can be packaged using: + +```shell script +./mvnw package +``` + +It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. +Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. + +The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. + +If you want to build an _über-jar_, execute the following command: + +```shell script +./mvnw package -Dquarkus.package.jar.type=uber-jar +``` + +The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. + +## Creating a native executable + +You can create a native executable using: + +```shell script +./mvnw package -Dnative +``` + +Or, if you don't have GraalVM installed, you can run the native executable build in a container using: + +```shell script +./mvnw package -Dnative -Dquarkus.native.container-build=true +``` + +You can then execute your native executable with: `./target/eatery-service-1.0.0-SNAPSHOT-runner` + +If you want to learn more about building native executables, please consult . + +## Related Guides + +- Hibernate ORM with Panache ([guide](https://quarkus.io/guides/hibernate-orm-panache)): Simplify your persistence code for Hibernate ORM via the active record or the repository pattern +- Messaging - Kafka Connector ([guide](https://quarkus.io/guides/kafka-getting-started)): Connect to Kafka with Reactive Messaging +- JDBC Driver - PostgreSQL ([guide](https://quarkus.io/guides/datasource)): Connect to the PostgreSQL database via JDBC + +## Provided Code + +### Hibernate ORM + +Create your first JPA entity + +[Related guide section...](https://quarkus.io/guides/hibernate-orm) + + +[Related Hibernate with Panache section...](https://quarkus.io/guides/hibernate-orm-panache) + + +### Messaging codestart + +Use Quarkus Messaging + +[Related Apache Kafka guide section...](https://quarkus.io/guides/kafka-reactive-getting-started) + diff --git a/eatery-service/mvnw b/eatery-service/mvnw new file mode 100755 index 0000000..bd8896b --- /dev/null +++ b/eatery-service/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/eatery-service/mvnw.cmd b/eatery-service/mvnw.cmd new file mode 100644 index 0000000..5761d94 --- /dev/null +++ b/eatery-service/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/eatery-service/pom.xml b/eatery-service/pom.xml new file mode 100644 index 0000000..2304bdb --- /dev/null +++ b/eatery-service/pom.xml @@ -0,0 +1,163 @@ + + + 4.0.0 + + + com.drinkool + drinkool + 1.1.0-dev.1 + ../pom.xml + + + eatery-service + quarkus + + + 3.15.0 + 21 + UTF-8 + UTF-8 + quarkus-bom + io.quarkus.platform + 3.32.4 + true + 3.5.4 + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + com.drinkool + lib + ${project.version} + + + io.quarkus + quarkus-jdbc-h2 + test + + + io.rest-assured + rest-assured + test + + + io.quarkus + quarkus-hibernate-orm-panache + + + io.quarkus + quarkus-jackson + + + io.quarkus + quarkus-messaging-kafka + + + io.quarkus + quarkus-jdbc-postgresql + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-hibernate-orm + + + io.quarkus + quarkus-rest-jackson + + + io.quarkus + quarkus-junit + test + + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + maven-surefire-plugin + ${surefire-plugin.version} + + @{argLine} + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + @{argLine} + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + false + false + true + + + + diff --git a/eatery-service/src/main/docker/Dockerfile.jvm b/eatery-service/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..23c1893 --- /dev/null +++ b/eatery-service/src/main/docker/Dockerfile.jvm @@ -0,0 +1,100 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/eatery-service-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/eatery-service-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/eatery-service-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +# You can find more information about the UBI base runtime images and their configuration here: +# https://rh-openjdk.github.io/redhat-openjdk-containers/ +### +FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.24 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/eatery-service/src/main/docker/Dockerfile.legacy-jar b/eatery-service/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 0000000..5059b5c --- /dev/null +++ b/eatery-service/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,96 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/eatery-service-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/eatery-service-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/eatery-service-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") - Be aware that this will override +# the default JVM options, use `JAVA_OPTS_APPEND` to append options +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +# You can find more information about the UBI base runtime images and their configuration here: +# https://rh-openjdk.github.io/redhat-openjdk-containers/ +### +FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.24 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/eatery-service/src/main/docker/Dockerfile.native b/eatery-service/src/main/docker/Dockerfile.native new file mode 100644 index 0000000..e0e93f0 --- /dev/null +++ b/eatery-service/src/main/docker/Dockerfile.native @@ -0,0 +1,29 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/eatery-service . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/eatery-service +# +# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.7` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`. +### +FROM registry.access.redhat.com/ubi9/ubi-minimal:9.7 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/eatery-service/src/main/docker/Dockerfile.native-micro b/eatery-service/src/main/docker/Dockerfile.native-micro new file mode 100644 index 0000000..f043cde --- /dev/null +++ b/eatery-service/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,32 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/eatery-service . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/eatery-service +# +# The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on UBI 9. +# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`. +### +FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root --chmod=0755 target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/eatery-service/src/main/java/com/drinkool/entities/InventoryItemEntity.java b/eatery-service/src/main/java/com/drinkool/entities/InventoryItemEntity.java new file mode 100644 index 0000000..397b469 --- /dev/null +++ b/eatery-service/src/main/java/com/drinkool/entities/InventoryItemEntity.java @@ -0,0 +1,29 @@ +package com.drinkool.entities; + +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import jakarta.transaction.Transactional; + +@Entity +@Table(name = "inventory_items") +public class InventoryItemEntity extends BaseEntity { + + public String name; + public int quantity; + public String unit; + + // Create + @Transactional + public void add(String name, int quantity, String unit) { + this.name = name; + this.quantity = quantity; + this.unit = unit; + + this.persist(); + } + + @Transactional + public void add(String name, int quantity) { + add(name, quantity, "unit"); + } +} diff --git a/eatery-service/src/main/java/com/drinkool/entities/ReviewEntity.java b/eatery-service/src/main/java/com/drinkool/entities/ReviewEntity.java new file mode 100644 index 0000000..8d7a208 --- /dev/null +++ b/eatery-service/src/main/java/com/drinkool/entities/ReviewEntity.java @@ -0,0 +1,28 @@ +package com.drinkool.entities; + +import com.drinkool.models.ReviewModel; +import jakarta.persistence.*; +import jakarta.transaction.Transactional; +import java.util.UUID; + +@Entity +@Table(name = "reviews") +public class ReviewEntity extends ReviewModel { + + public UUID reviewerId; + + public UUID eateryId; + + @Transactional + public void receive(UUID reviewerId, UUID eateryId, ReviewModel review) { + this.reviewerId = reviewerId; + + this.eateryId = eateryId; + + this.rating = review.rating; + + this.comment = review.comment; + + this.persist(); + } +} diff --git a/eatery-service/src/main/java/com/drinkool/services/InventoryService.java b/eatery-service/src/main/java/com/drinkool/services/InventoryService.java new file mode 100644 index 0000000..1de9561 --- /dev/null +++ b/eatery-service/src/main/java/com/drinkool/services/InventoryService.java @@ -0,0 +1,22 @@ +package com.drinkool.services; + +import com.drinkool.dtos.AddInventory; +import com.drinkool.entities.InventoryItemEntity; +import jakarta.transaction.Transactional; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.Response; + +@Path("/api/inventory") +public class InventoryService { + + @POST + @Path("/add") + @Transactional + public Response add(AddInventory input) { + InventoryItemEntity newItem = new InventoryItemEntity(); + + newItem.add(input.name, input.quantity, input.unit); + + return Response.ok().build(); + } +} diff --git a/eatery-service/src/main/java/com/drinkool/services/ReviewService.java b/eatery-service/src/main/java/com/drinkool/services/ReviewService.java new file mode 100644 index 0000000..4a774de --- /dev/null +++ b/eatery-service/src/main/java/com/drinkool/services/ReviewService.java @@ -0,0 +1,22 @@ +package com.drinkool.services; + +import com.drinkool.dtos.SendReview; +import com.drinkool.entities.ReviewEntity; +import jakarta.transaction.Transactional; +import jakarta.ws.rs.*; +import jakarta.ws.rs.core.Response; + +@Path("/api") +public class ReviewService { + + @POST + @Path("/leaveReview") + @Transactional + public Response leaveReview(SendReview input) { + ReviewEntity newReview = new ReviewEntity(); + + newReview.receive(input.reviewerId, input.orderId, input.review); + + return Response.status(201).build(); + } +} diff --git a/eatery-service/src/main/resources/application.properties b/eatery-service/src/main/resources/application.properties new file mode 100644 index 0000000..88f3d6f --- /dev/null +++ b/eatery-service/src/main/resources/application.properties @@ -0,0 +1,16 @@ +# Kafka +kafka.bootstrap.servers=localhost:9092 + +# Postgress +## Cấu hình Database +quarkus.datasource.db-kind=postgresql +quarkus.datasource.username=postgres +quarkus.datasource.password=password +quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/eatery + +## Tự động tạo bảng từ Entity (chỉ dùng cho môi trường dev) +quarkus.hibernate-orm.database.generation=update + +# Dependency +quarkus.index-dependency.lib.group-id=com.drinkool +quarkus.index-dependency.lib.artifact-id=lib \ No newline at end of file diff --git a/eatery-service/src/main/resources/import.sql b/eatery-service/src/main/resources/import.sql new file mode 100644 index 0000000..16aa523 --- /dev/null +++ b/eatery-service/src/main/resources/import.sql @@ -0,0 +1,6 @@ +-- This file allow to write SQL commands that will be emitted in test and dev. +-- The commands are commented as their support depends of the database +-- insert into myentity (id, field) values(1, 'field-1'); +-- insert into myentity (id, field) values(2, 'field-2'); +-- insert into myentity (id, field) values(3, 'field-3'); +-- alter sequence myentity_seq restart with 4; \ No newline at end of file diff --git a/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java b/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java new file mode 100644 index 0000000..8e396cb --- /dev/null +++ b/eatery-service/src/test/java/com/drinkool/services/InventoryServiceTest.java @@ -0,0 +1,36 @@ +package com.drinkool.services; + +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.drinkool.dtos.AddInventory; +import com.drinkool.entities.InventoryItemEntity; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; +import java.util.Random; +import java.util.UUID; +import org.junit.jupiter.api.Test; + +@QuarkusTest +public class InventoryServiceTest { + + @Test + void add() { + Random random = new Random(); + + String name = UUID.randomUUID().toString(); + + AddInventory input = new AddInventory(); + input.name = name; + input.quantity = random.nextInt(100); + + given() + .contentType(ContentType.JSON) + .body(input) + .when() + .post("/api/inventory/add") + .then(); + + assertEquals(1, InventoryItemEntity.find("name", name).count()); + } +} diff --git a/eatery-service/src/test/java/com/drinkool/services/ReviewServiceTest.java b/eatery-service/src/test/java/com/drinkool/services/ReviewServiceTest.java new file mode 100644 index 0000000..4f788fe --- /dev/null +++ b/eatery-service/src/test/java/com/drinkool/services/ReviewServiceTest.java @@ -0,0 +1,44 @@ +package com.drinkool.services; + +import static io.restassured.RestAssured.given; +import static org.junit.jupiter.api.Assertions.*; + +import com.drinkool.dtos.SendReview; +import com.drinkool.entities.ReviewEntity; +import com.drinkool.models.ReviewModel; +import io.quarkus.test.junit.QuarkusTest; +import io.restassured.http.ContentType; +import java.util.Random; +import java.util.UUID; +import org.junit.jupiter.api.*; + +@QuarkusTest +public class ReviewServiceTest { + + @Test + void receiveReview() { + Random random = new Random(); + + UUID reviewerId = UUID.randomUUID(); + UUID orderId = UUID.randomUUID(); + String comment = UUID.randomUUID().toString(); + int rating = random.nextInt(); + + SendReview input = new SendReview(); + input.reviewerId = reviewerId; + input.orderId = orderId; + ReviewModel reviewModel = new ReviewModel(); + reviewModel.comment = comment; + reviewModel.rating = rating; + input.review = reviewModel; + + given() + .contentType(ContentType.JSON) + .body(input) + .when() + .post("/api/leaveReview") + .then(); + + assertEquals(1, ReviewEntity.find("reviewerId", reviewerId).count()); + } +} diff --git a/eatery-service/src/test/resources/application.properties b/eatery-service/src/test/resources/application.properties new file mode 100644 index 0000000..3dd44ee --- /dev/null +++ b/eatery-service/src/test/resources/application.properties @@ -0,0 +1,9 @@ +# Quarkus +quarkus.http.host=0.0.0.0 + +# Database +# Database +%test.quarkus.datasource.db-kind=h2 +%test.quarkus.datasource.jdbc.url=jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1 + +%test.quarkus.hibernate-orm.database.generation=drop-and-create diff --git a/gateway-service/pom.xml b/gateway-service/pom.xml index 7587c8d..592580f 100644 --- a/gateway-service/pom.xml +++ b/gateway-service/pom.xml @@ -9,7 +9,7 @@ com.drinkool drinkool - 1.0.0-dev.21 + 1.1.0-dev.1 ../pom.xml diff --git a/gateway-service/src/main/resources/application.properties b/gateway-service/src/main/resources/application.properties index 92a3501..6993984 100644 --- a/gateway-service/src/main/resources/application.properties +++ b/gateway-service/src/main/resources/application.properties @@ -1,5 +1 @@ -mp.messaging.incoming.words-in.auto.offset.reset=earliest -mp.messaging.incoming.words-in.topic=words -mp.messaging.outgoing.words-out.topic=words - quarkus.rest-client.account.url=http://localhost:502 \ No newline at end of file diff --git a/gateway-service/src/test/java/com/drinkool/GreetingResourceIT.java b/gateway-service/src/test/java/com/drinkool/GreetingResourceIT.java deleted file mode 100644 index 43c437f..0000000 --- a/gateway-service/src/test/java/com/drinkool/GreetingResourceIT.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.drinkool; - -import io.quarkus.test.junit.QuarkusIntegrationTest; - -@QuarkusIntegrationTest -class GreetingResourceIT extends GreetingResourceTest { - // Execute the same tests but in packaged mode. -} diff --git a/gateway-service/src/test/java/com/drinkool/GreetingResourceTest.java b/gateway-service/src/test/java/com/drinkool/GreetingResourceTest.java deleted file mode 100644 index f529514..0000000 --- a/gateway-service/src/test/java/com/drinkool/GreetingResourceTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.drinkool; - -import static io.restassured.RestAssured.given; -import static org.hamcrest.CoreMatchers.is; - -import io.quarkus.test.junit.QuarkusTest; -import org.junit.jupiter.api.Test; - -@QuarkusTest -class GreetingResourceTest { - - @Test - void testHelloEndpoint() { - given() - .when() - .get("/hello") - .then() - .statusCode(200) - .body(is("Hello from Quarkus REST")); - } -} diff --git a/gateway-service/src/test/java/com/drinkool/MyMessagingApplicationTest.java b/gateway-service/src/test/java/com/drinkool/MyMessagingApplicationTest.java deleted file mode 100644 index 7573d8d..0000000 --- a/gateway-service/src/test/java/com/drinkool/MyMessagingApplicationTest.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.drinkool; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import io.quarkus.test.junit.QuarkusTest; -import jakarta.inject.Inject; -import org.junit.jupiter.api.Test; - -@QuarkusTest -class MyMessagingApplicationTest { - - @Inject - MyMessagingApplication application; - - @Test - void test() { - assertEquals("HELLO", application.toUpperCase("Hello")); - assertEquals("BONJOUR", application.toUpperCase("bonjour")); - } -} diff --git a/lib/pom.xml b/lib/pom.xml index 855f655..9890614 100644 --- a/lib/pom.xml +++ b/lib/pom.xml @@ -9,7 +9,7 @@ com.drinkool drinkool - 1.0.0-dev.21 + 1.1.0-dev.1 ../pom.xml @@ -26,7 +26,18 @@ jackson-annotations 2.15.2 - + + jakarta.persistence + jakarta.persistence-api + 3.1.0 + provided + + + io.quarkus + quarkus-hibernate-orm-panache + 3.32.4 + provided + org.junit.jupiter junit-jupiter-api diff --git a/lib/src/main/java/com/drinkool/dtos/AddInventory.java b/lib/src/main/java/com/drinkool/dtos/AddInventory.java new file mode 100644 index 0000000..49eb2a8 --- /dev/null +++ b/lib/src/main/java/com/drinkool/dtos/AddInventory.java @@ -0,0 +1,8 @@ +package com.drinkool.dtos; + +public class AddInventory { + + public String name; + public int quantity; + public String unit; +} diff --git a/lib/src/main/java/com/drinkool/dtos/SendReview.java b/lib/src/main/java/com/drinkool/dtos/SendReview.java new file mode 100644 index 0000000..637f40b --- /dev/null +++ b/lib/src/main/java/com/drinkool/dtos/SendReview.java @@ -0,0 +1,11 @@ +package com.drinkool.dtos; + +import com.drinkool.models.ReviewModel; +import java.util.UUID; + +public class SendReview { + + public UUID reviewerId; + public UUID orderId; + public ReviewModel review; +} diff --git a/lib/src/main/java/com/drinkool/entities/BaseEntity.java b/lib/src/main/java/com/drinkool/entities/BaseEntity.java new file mode 100644 index 0000000..984cab9 --- /dev/null +++ b/lib/src/main/java/com/drinkool/entities/BaseEntity.java @@ -0,0 +1,13 @@ +package com.drinkool.entities; + +import io.quarkus.hibernate.orm.panache.PanacheEntityBase; +import jakarta.persistence.*; +import java.util.UUID; + +@MappedSuperclass +public class BaseEntity extends PanacheEntityBase { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + public UUID id; +} diff --git a/lib/src/main/java/com/drinkool/models/ReviewModel.java b/lib/src/main/java/com/drinkool/models/ReviewModel.java new file mode 100644 index 0000000..acca3c4 --- /dev/null +++ b/lib/src/main/java/com/drinkool/models/ReviewModel.java @@ -0,0 +1,19 @@ +package com.drinkool.models; + +import com.drinkool.entities.BaseEntity; +import jakarta.persistence.*; +import java.time.LocalDateTime; + +@MappedSuperclass +public class ReviewModel extends BaseEntity { + + @Column + public int rating; + + @Column + public String comment; + + @org.hibernate.annotations.CreationTimestamp + @Column(name = "review_date", updatable = false) + protected LocalDateTime reviewDate; +} diff --git a/pom.xml b/pom.xml index f7aa5a0..f9eadfd 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 4.0.0 com.drinkool drinkool - 1.0.0-dev.21 + 1.1.0-dev.1 pom 17 @@ -17,6 +17,7 @@ lib + eatery-service account-service gateway-service