Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a72c9f9e3 | |||
| 942e13ced9 | |||
| 5a0092c711 | |||
| 1229cec774 | |||
| f614d5572d | |||
| 37bf5de999 | |||
| 1f36994661 | |||
| 1af8c04e32 | |||
| 30fc547604 | |||
| dbda2f5491 | |||
| 2ac755ddca | |||
| 4f014e03ca | |||
| 81f58a52bf | |||
| f5b66d9bb8 |
@@ -4,6 +4,7 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- dev-*
|
||||
|
||||
jobs:
|
||||
release:
|
||||
@@ -11,24 +12,6 @@ jobs:
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Calculate and Export Target IP
|
||||
run: |
|
||||
# 1. Lấy IP hiện tại và tính toán IP đích (đổi octet cuối thành .1)
|
||||
RUNNER_IP=$(hostname -I | awk '{print $1}')
|
||||
CALCULATED_IP=$(echo $RUNNER_IP | cut -d'.' -f1-3).1
|
||||
|
||||
# 2. Đưa vào biến môi trường toàn cục của Job
|
||||
echo "TARGET_IP=${CALCULATED_IP}" >> $GITHUB_ENV
|
||||
|
||||
- name: Setup SSH Key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
chmod 700 ~/.ssh
|
||||
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_ed25519
|
||||
chmod 600 ~/.ssh/id_ed25519
|
||||
|
||||
ssh-keyscan -p 222 -t ed25519 $TARGET_IP >> ~/.ssh/known_hosts
|
||||
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
fetch-depth: 0
|
||||
@@ -82,22 +65,21 @@ jobs:
|
||||
GITEA_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
run: |
|
||||
pnpm i
|
||||
pnpm release
|
||||
pnpm format
|
||||
pnpm release
|
||||
|
||||
- name: Commit & Push Changes
|
||||
env:
|
||||
MY_PAT_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
run: |
|
||||
if [ -n "$(git status --porcelain)" ]&& [ "${{ github.ref_name }}" = "main" ]; then
|
||||
if [ -n "$(git status --porcelain)" ]; then
|
||||
git config --global user.name "gitea-actions"
|
||||
git config --global user.email "actions-user@noreply.git.demonkernel.io.vn"
|
||||
|
||||
REPO_NAME="${{ gitea.repository }}"
|
||||
git remote set-url origin https://x-access-token:${MY_PAT_TOKEN}@git.demonkernel.io.vn/${{ github.repository }}.git
|
||||
|
||||
git remote set-url origin ssh://git@$TARGET_IP:222/${REPO_NAME}.git
|
||||
|
||||
git rm -r --cached .
|
||||
git add .
|
||||
git commit -m "chore: release [ci skip]"
|
||||
|
||||
git push
|
||||
git push origin HEAD:${{ github.ref_name }}
|
||||
fi
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
name: Java CI with Maven
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
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 }}
|
||||
+2
-9
@@ -1,12 +1,5 @@
|
||||
{
|
||||
"branches": [
|
||||
"main",
|
||||
{
|
||||
"name": "dev-*",
|
||||
"prerelease": "${name.replace('dev-', '')}",
|
||||
"channel": "${name.replace('dev-', '')}"
|
||||
}
|
||||
],
|
||||
"branches": ["main", { "name": "dev-*", "prerelease": "dev" }],
|
||||
"plugins": [
|
||||
"@semantic-release/commit-analyzer",
|
||||
"@semantic-release/release-notes-generator",
|
||||
@@ -15,7 +8,7 @@
|
||||
"@semantic-release/exec",
|
||||
{
|
||||
"prepareCmd": "./mvnw versions:set -DnewVersion=${nextRelease.version}",
|
||||
"publishCmd": "if [ \"${branch.name}\" = \"main\" ]; then ./mvnw clean package -Dquarkus.container-image.tag=${nextRelease.version} -DskipTests; fi"
|
||||
"publishCmd": "if [ \"${branch.name}\" = \"main\" ]; then ./mvnw package -Dquarkus.container-image.tag=${nextRelease.version} -DskipTests; fi"
|
||||
}
|
||||
],
|
||||
[
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
# [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)
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>com.drinkool</groupId>
|
||||
<artifactId>drinkool</artifactId>
|
||||
<version>1.1.0-dev.1</version>
|
||||
<version>1.0.0-dev.21</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -48,11 +48,6 @@
|
||||
<artifactId>lib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-hibernate-orm-panache</artifactId>
|
||||
@@ -148,8 +143,8 @@
|
||||
<configuration>
|
||||
<argLine>@{argLine}</argLine>
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>
|
||||
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<native.image.path
|
||||
>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager
|
||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
|
||||
@@ -30,7 +30,7 @@ public abstract class UserModel extends BaseEntity {
|
||||
@Transactional
|
||||
public void signup(String name, String phone, String rawPassword) {
|
||||
// Check existed user
|
||||
UserModel existedUser = find("phone", phone).firstResult();
|
||||
UserModel existedUser = UserModel.find("phone", phone).firstResult();
|
||||
|
||||
if (existedUser != null) throw new BadRequestException("ExistedUser");
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# Database
|
||||
# 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/postgres
|
||||
|
||||
# Tự động tạo bảng từ Entity (chỉ dùng cho môi trường dev)
|
||||
quarkus.hibernate-orm.database.generation=update
|
||||
|
||||
# Docker
|
||||
## URL của Gitea Registry (thường là gitea.yourdomain.com)
|
||||
# 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,9 +16,4 @@ quarkus.container-image.build=true
|
||||
quarkus.container-image.builder=docker
|
||||
|
||||
# Redis
|
||||
quarkus.redis.hosts=redis://localhost:6379
|
||||
|
||||
|
||||
# Dependency
|
||||
quarkus.index-dependency.lib.group-id=com.drinkool
|
||||
quarkus.index-dependency.lib.artifact-id=lib
|
||||
quarkus.redis.hosts=redis://localhost:6379
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.drinkool;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@QuarkusTest
|
||||
class CustomerSignupTest {
|
||||
|
||||
@Test
|
||||
// @TestIransaction
|
||||
@Transactional
|
||||
public void testSignupSuccess() {
|
||||
//dang nhap thanh cong
|
||||
CustomerEntity user = new CustomerEntity();
|
||||
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");
|
||||
|
||||
CustomerEntity savedUser = CustomerEntity.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
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.drinkool.models;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
import io.quarkus.test.TestTransaction;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
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
|
||||
@Test
|
||||
@Transactional
|
||||
public void testSignupFailExistedUser() {
|
||||
TestUserEntity existUser = new TestUserEntity();
|
||||
String phone =
|
||||
"+8477" + String.format("%07d", (new Random()).nextInt(10000000));
|
||||
String password = "tungtungtungshahua";
|
||||
existUser.signup("Nguyen Thanh Quy", phone, password);
|
||||
|
||||
CustomerEntity newCustomer = new CustomerEntity();
|
||||
BadRequestException exception = assertThrows(
|
||||
BadRequestException.class,
|
||||
() -> {
|
||||
newCustomer.signup("Nguyen Viet Anh", phone, "02092006Anh");
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals("ExistedUser", exception.getMessage());
|
||||
}
|
||||
|
||||
// 3. Test case: Đăng ký thất bại do số điện thoại sai định dạng
|
||||
@Test
|
||||
@TestTransaction
|
||||
public void testSignupFailInvalidPhoneNumber() {
|
||||
TestUserEntity customer = new TestUserEntity();
|
||||
String invalidPhone = "12345";
|
||||
|
||||
BadRequestException exception = assertThrows(
|
||||
BadRequestException.class,
|
||||
() -> {
|
||||
customer.signup("Lam Vi Hoang", invalidPhone, "Pass123");
|
||||
}
|
||||
);
|
||||
|
||||
assertEquals("InvalidPhoneNumber", exception.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
# 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
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>com.drinkool</groupId>
|
||||
<artifactId>drinkool</artifactId>
|
||||
<version>1.1.0-dev.1</version>
|
||||
<version>1.0.0-dev.21</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -48,11 +48,6 @@
|
||||
<artifactId>lib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-jdbc-h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class EateryInventoryItemEntity extends BaseEntity {
|
||||
|
||||
public double quantity;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "inventory_item_id")
|
||||
public InventoryItemEntity inventoryItem;
|
||||
|
||||
private EateryInventoryItemEntity() {}
|
||||
|
||||
// Create
|
||||
@Transactional
|
||||
public static EateryInventoryItemEntity create(
|
||||
String name,
|
||||
double quantity,
|
||||
String unit
|
||||
) {
|
||||
String itemName = name.toLowerCase();
|
||||
|
||||
InventoryItemEntity item = InventoryItemEntity.find(
|
||||
"name",
|
||||
itemName
|
||||
).firstResult();
|
||||
|
||||
if (item == null || item.unit != unit) {
|
||||
if (unit != null || unit == "") {
|
||||
item = InventoryItemEntity.create(itemName, unit);
|
||||
} else {
|
||||
item = InventoryItemEntity.create(itemName);
|
||||
}
|
||||
}
|
||||
|
||||
EateryInventoryItemEntity eateryInventoryItem =
|
||||
new EateryInventoryItemEntity();
|
||||
|
||||
eateryInventoryItem.quantity = quantity;
|
||||
eateryInventoryItem.inventoryItem = item;
|
||||
|
||||
eateryInventoryItem.persist();
|
||||
|
||||
return eateryInventoryItem;
|
||||
}
|
||||
}
|
||||
@@ -9,25 +9,21 @@ import jakarta.transaction.Transactional;
|
||||
public class InventoryItemEntity extends BaseEntity {
|
||||
|
||||
public String name;
|
||||
public int quantity;
|
||||
public String unit;
|
||||
|
||||
private InventoryItemEntity() {}
|
||||
|
||||
// Create
|
||||
@Transactional
|
||||
public static InventoryItemEntity create(String name, String unit) {
|
||||
InventoryItemEntity item = new InventoryItemEntity();
|
||||
public void add(String name, int quantity, String unit) {
|
||||
this.name = name;
|
||||
this.quantity = quantity;
|
||||
this.unit = unit;
|
||||
|
||||
item.name = name;
|
||||
item.unit = unit;
|
||||
|
||||
item.persist();
|
||||
|
||||
return item;
|
||||
this.persist();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public static InventoryItemEntity create(String name) {
|
||||
return InventoryItemEntity.create(name, "unit");
|
||||
public void add(String name, int quantity) {
|
||||
add(name, quantity, "unit");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class MenuItemEntity extends BaseEntity {
|
||||
|
||||
public String name;
|
||||
public double price;
|
||||
|
||||
// Danh sách các nguyên liệu cấu thành món ăn này
|
||||
@OneToMany(
|
||||
mappedBy = "menuItem",
|
||||
cascade = CascadeType.ALL,
|
||||
orphanRemoval = true
|
||||
)
|
||||
public List<MenuItemIngredientEntity> ingredients = new ArrayList<>();
|
||||
|
||||
private MenuItemEntity() {}
|
||||
|
||||
/**
|
||||
* Thêm nguyên liệu vào món ăn với định lượng cụ thể
|
||||
*/
|
||||
@Transactional
|
||||
public void addIngredient(
|
||||
EateryInventoryItemEntity inventoryItem,
|
||||
double requiredQty
|
||||
) {
|
||||
MenuItemIngredientEntity ingredient = MenuItemIngredientEntity.create(
|
||||
this,
|
||||
inventoryItem,
|
||||
requiredQty
|
||||
);
|
||||
|
||||
this.ingredients.add(ingredient);
|
||||
|
||||
this.persist();
|
||||
}
|
||||
|
||||
/**
|
||||
* Phương thức tiện ích để tạo nhanh Menu Item từ tên
|
||||
*/
|
||||
@Transactional
|
||||
public static MenuItemEntity create(String name, double price) {
|
||||
MenuItemEntity menu = new MenuItemEntity();
|
||||
|
||||
menu.name = name;
|
||||
menu.price = price;
|
||||
|
||||
menu.persist();
|
||||
|
||||
return menu;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "menu_item_ingredients")
|
||||
public class MenuItemIngredientEntity extends BaseEntity {
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "menu_item_id")
|
||||
public MenuItemEntity menuItem;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "inventory_item_id")
|
||||
public EateryInventoryItemEntity inventoryItem;
|
||||
|
||||
public double requiredQuantity;
|
||||
|
||||
private MenuItemIngredientEntity() {}
|
||||
|
||||
public static MenuItemIngredientEntity create(
|
||||
MenuItemEntity menuItem,
|
||||
EateryInventoryItemEntity inventoryItem,
|
||||
double requiredQuantity
|
||||
) {
|
||||
MenuItemIngredientEntity ingredient = new MenuItemIngredientEntity();
|
||||
|
||||
ingredient.menuItem = menuItem;
|
||||
ingredient.inventoryItem = inventoryItem;
|
||||
ingredient.requiredQuantity = requiredQuantity;
|
||||
|
||||
ingredient.persist();
|
||||
|
||||
return ingredient;
|
||||
}
|
||||
}
|
||||
@@ -13,23 +13,16 @@ public class ReviewEntity extends ReviewModel {
|
||||
|
||||
public UUID eateryId;
|
||||
|
||||
private ReviewEntity(ReviewModel input) {
|
||||
super(input);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public static ReviewEntity create(
|
||||
UUID reviewerId,
|
||||
UUID eateryId,
|
||||
ReviewModel reviewInput
|
||||
) {
|
||||
ReviewEntity review = new ReviewEntity(reviewInput);
|
||||
public void receive(UUID reviewerId, UUID eateryId, ReviewModel review) {
|
||||
this.reviewerId = reviewerId;
|
||||
|
||||
review.reviewerId = reviewerId;
|
||||
review.eateryId = eateryId;
|
||||
this.eateryId = eateryId;
|
||||
|
||||
review.persist();
|
||||
this.rating = review.rating;
|
||||
|
||||
return review;
|
||||
this.comment = review.comment;
|
||||
|
||||
this.persist();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ import jakarta.ws.rs.core.Response;
|
||||
public class InventoryService {
|
||||
|
||||
@POST
|
||||
@Path("/create")
|
||||
@Path("/add")
|
||||
@Transactional
|
||||
public Response create(AddInventory input) {
|
||||
InventoryItemEntity.create(input.name, input.unit);
|
||||
public Response add(AddInventory input) {
|
||||
InventoryItemEntity newItem = new InventoryItemEntity();
|
||||
|
||||
newItem.add(input.name, input.quantity, input.unit);
|
||||
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@@ -6,14 +6,16 @@ import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@Path("/api/review")
|
||||
@Path("/api")
|
||||
public class ReviewService {
|
||||
|
||||
@POST
|
||||
@Path("/create")
|
||||
@Path("/leaveReview")
|
||||
@Transactional
|
||||
public Response create(SendReview input) {
|
||||
ReviewEntity.create(input.reviewerId, input.orderId, input.review);
|
||||
public Response leaveReview(SendReview input) {
|
||||
ReviewEntity newReview = new ReviewEntity();
|
||||
|
||||
newReview.receive(input.reviewerId, input.orderId, input.review);
|
||||
|
||||
return Response.status(201).build();
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@QuarkusTest
|
||||
public class EateryInventoryItemEntityTest {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void testAdd_WhenItemExists_ShouldUseExistingItem() {
|
||||
String itemName = "Coca Cola";
|
||||
int quantity = 10;
|
||||
|
||||
InventoryItemEntity.create(itemName);
|
||||
|
||||
EateryInventoryItemEntity eateryItem = EateryInventoryItemEntity.create(
|
||||
itemName,
|
||||
quantity,
|
||||
""
|
||||
);
|
||||
|
||||
EateryInventoryItemEntity savedEntity = EateryInventoryItemEntity.find(
|
||||
"id",
|
||||
eateryItem.id
|
||||
).firstResult();
|
||||
assertNotNull(savedEntity);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void testAdd_WhenItemDoesNotExist_ShouldCreateNewItem() {
|
||||
String itemName = "Pepsi";
|
||||
int quantity = 5;
|
||||
String unit = "Bottle";
|
||||
|
||||
EateryInventoryItemEntity eateryItem = EateryInventoryItemEntity.create(
|
||||
itemName,
|
||||
quantity,
|
||||
unit
|
||||
);
|
||||
|
||||
EateryInventoryItemEntity savedEntity = EateryInventoryItemEntity.find(
|
||||
"id",
|
||||
eateryItem.id
|
||||
).firstResult();
|
||||
assertNotNull(savedEntity);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package com.drinkool.entities;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@QuarkusTest
|
||||
public class MenuItemIngredientEntityTest {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void testCreate_ShouldPersistIngredientSuccessfully() {
|
||||
// 1. Chuẩn bị dữ liệu giả định
|
||||
|
||||
String menuItemName = "Milk Tea";
|
||||
double menuItemPrice = 40;
|
||||
|
||||
MenuItemEntity menuItem = MenuItemEntity.create(
|
||||
menuItemName,
|
||||
menuItemPrice
|
||||
);
|
||||
|
||||
String inventoryItemName = "Water";
|
||||
double inventoryItemQuantity = 10;
|
||||
String inventoryItemUnit = "l";
|
||||
|
||||
EateryInventoryItemEntity inventoryItem = EateryInventoryItemEntity.create(
|
||||
inventoryItemName,
|
||||
inventoryItemQuantity,
|
||||
inventoryItemUnit
|
||||
);
|
||||
|
||||
double requiredQuantity = 0.5;
|
||||
|
||||
// 2. Gọi hàm static create cần test
|
||||
MenuItemIngredientEntity createdIngredient =
|
||||
MenuItemIngredientEntity.create(
|
||||
menuItem,
|
||||
inventoryItem,
|
||||
requiredQuantity
|
||||
);
|
||||
|
||||
// 3. Kiểm tra kết quả
|
||||
assertNotNull(createdIngredient.id, "ID không được null sau khi persist");
|
||||
|
||||
// Truy vấn lại từ Database để đảm bảo dữ liệu đã được lưu đúng
|
||||
MenuItemIngredientEntity savedEntity = MenuItemIngredientEntity.findById(
|
||||
createdIngredient.id
|
||||
);
|
||||
|
||||
assertNotNull(savedEntity);
|
||||
assertEquals(menuItem.id, savedEntity.menuItem.id);
|
||||
assertEquals(inventoryItem.id, savedEntity.inventoryItem.id);
|
||||
assertEquals(requiredQuantity, savedEntity.requiredQuantity);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ 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;
|
||||
|
||||
@@ -15,16 +16,19 @@ 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/create")
|
||||
.post("/api/inventory/add")
|
||||
.then();
|
||||
|
||||
assertEquals(1, InventoryItemEntity.find("name", name).count());
|
||||
|
||||
@@ -27,14 +27,16 @@ public class ReviewServiceTest {
|
||||
SendReview input = new SendReview();
|
||||
input.reviewerId = reviewerId;
|
||||
input.orderId = orderId;
|
||||
ReviewModel reviewModel = new ReviewModel(rating, comment);
|
||||
ReviewModel reviewModel = new ReviewModel();
|
||||
reviewModel.comment = comment;
|
||||
reviewModel.rating = rating;
|
||||
input.review = reviewModel;
|
||||
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
.when()
|
||||
.post("/api/review/create")
|
||||
.post("/api/leaveReview")
|
||||
.then();
|
||||
|
||||
assertEquals(1, ReviewEntity.find("reviewerId", reviewerId).count());
|
||||
|
||||
@@ -1,9 +1,2 @@
|
||||
# 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
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>com.drinkool</groupId>
|
||||
<artifactId>drinkool</artifactId>
|
||||
<version>1.1.0-dev.1</version>
|
||||
<version>1.0.0-dev.21</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
<parent>
|
||||
<groupId>com.drinkool</groupId>
|
||||
<artifactId>drinkool</artifactId>
|
||||
<version>1.1.0-dev.1</version>
|
||||
<version>1.0.0-dev.21</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.drinkool.dtos;
|
||||
|
||||
public class AddInventory {
|
||||
|
||||
public String name;
|
||||
public String unit;
|
||||
public String name;
|
||||
public int quantity;
|
||||
public String unit;
|
||||
}
|
||||
|
||||
@@ -13,18 +13,7 @@ public class ReviewModel extends BaseEntity {
|
||||
@Column
|
||||
public String comment;
|
||||
|
||||
public ReviewModel() {}
|
||||
|
||||
public ReviewModel(int rating, String comment) {
|
||||
this.rating = rating;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public ReviewModel(ReviewModel input) {
|
||||
this(input.rating, input.comment);
|
||||
}
|
||||
|
||||
@org.hibernate.annotations.CreationTimestamp
|
||||
@Column(name = "review_date", updatable = false)
|
||||
public LocalDateTime reviewDate;
|
||||
protected LocalDateTime reviewDate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user