fix: better url (#20)
Release package / release (push) Successful in 50m34s

Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Reviewed-on: #20
This commit was merged in pull request #20.
This commit is contained in:
2026-04-12 14:27:37 +00:00
parent 9bf7233436
commit fdcecf8368
27 changed files with 409 additions and 196 deletions
+2 -1
View File
@@ -17,7 +17,8 @@
"redhat.vscode-xml", "redhat.vscode-xml",
"esbenp.prettier-vscode", "esbenp.prettier-vscode",
"PeterSchmalfeldt.explorer-exclude", "PeterSchmalfeldt.explorer-exclude",
"redhat.java" "redhat.java",
"ryanluker.vscode-coverage-gutters"
] ]
} }
}, },
+9 -4
View File
@@ -38,8 +38,13 @@ jobs:
./mvnw -B install \ ./mvnw -B install \
-Dquarkus.container-image.push=false \ -Dquarkus.container-image.push=false \
- name: Publish Test Report - name: Jacoco Report to PR
uses: scacap/action-surefire-report@v1 uses: madrapps/jacoco-report@v1.7.2
if: failure() if: always()
with: with:
github_token: ${{ secrets.ACCESS_TOKEN }} paths: |
./**/jacoco.xml,
token: ${{ secrets.ACCESS_TOKEN }}
min-coverage-overall: 40
min-coverage-changed-files: 60
title: "📊 Báo cáo Độ bao phủ Kiểm thử (Test Coverage)"
+5
View File
@@ -46,6 +46,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.drinkool</groupId> <groupId>com.drinkool</groupId>
<artifactId>lib</artifactId> <artifactId>lib</artifactId>
@@ -1,8 +1,17 @@
package com.drinkool.entities; package com.drinkool.entities;
import com.drinkool.Role;
import com.drinkool.models.UserModel; import com.drinkool.models.UserModel;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.transaction.Transactional;
import java.util.UUID;
@Entity @Entity
@Table(name = "customer") @Table(name = Role.Customer)
public class CustomerEntity extends UserModel {} public class CustomerEntity extends UserModel {
@Transactional
public void signup(String phone) {
this.signup(phone, phone, UUID.randomUUID().toString().substring(0, 32));
}
}
@@ -0,0 +1,27 @@
package com.drinkool.entities;
import com.drinkool.Role;
import com.drinkool.models.UserModel;
import jakarta.persistence.*;
@Entity
@Table(name = Role.Manager)
public class ManagerEntity extends UserModel {
public String eateryName;
public boolean isVerified;
public void signup(
String name,
String phone,
String rawPassword,
String eateryName
) {
this.eateryName = eateryName;
this.isVerified = false;
this.signup(name, phone, rawPassword);
}
}
@@ -7,7 +7,6 @@ import com.password4j.Password;
import jakarta.persistence.*; import jakarta.persistence.*;
import jakarta.transaction.*; import jakarta.transaction.*;
import jakarta.ws.rs.BadRequestException; import jakarta.ws.rs.BadRequestException;
import java.util.UUID;
@Entity @Entity
@Inheritance(strategy = InheritanceType.JOINED) @Inheritance(strategy = InheritanceType.JOINED)
@@ -24,19 +23,12 @@ public abstract class UserModel extends BaseEntity {
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY) @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
public String hashedPassword; public String hashedPassword;
@Transactional
public void signup(String phone) {
this.signup(phone, phone, UUID.randomUUID().toString().substring(0, 32));
}
@Transactional @Transactional
public void signup(String name, String phone, String rawPassword) { public void signup(String name, String phone, String rawPassword) {
// Check existed user UserModel existedUser = UserModel.find("phone", phone).firstResult();
UserModel existedUser = find("phone", phone).firstResult();
if (existedUser != null) throw new BadRequestException("ExistedUser"); if (existedUser != null) throw new BadRequestException("ExistedUser");
// Set user
this.name = name; this.name = name;
if (!PhoneValidator.isValidInternationalPhone(phone)) { if (!PhoneValidator.isValidInternationalPhone(phone)) {
@@ -47,7 +39,6 @@ public abstract class UserModel extends BaseEntity {
this.hashedPassword = Password.hash(rawPassword).withArgon2().getResult(); this.hashedPassword = Password.hash(rawPassword).withArgon2().getResult();
// Save user
this.persist(); this.persist();
} }
@@ -0,0 +1,32 @@
package com.drinkool.services;
import com.drinkool.Url;
import com.drinkool.dtos.SmsOtp;
import com.drinkool.models.UserModel;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;
@Path("")
public class AccountService {
@Inject
OtpService otpService;
@POST
@Path(Url.SmsOtp)
public Response smsOtp(SmsOtp input) {
UserModel customer = UserModel.find("phone", input.phone).firstResult();
if (customer == null) return Response.status(Response.Status.BAD_REQUEST)
.entity("InvalidPhoneNumber")
.build();
String otp = otpService.generateAndSaveOtp(input.phone);
// Ở đây bạn sẽ gọi Kafka để gửi SMS thực tế
System.out.println("OTP cho " + input.phone + " là: " + otp);
return Response.accepted().build();
}
}
@@ -8,9 +8,15 @@ import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import java.util.UUID; import java.util.UUID;
@Path("") public abstract class BaseService {
public class UserService {
private UserModel model;
public BaseService(UserModel model) {
this.model = model;
}
@SuppressWarnings("static-access")
@POST @POST
@Path(Url.Me) @Path(Url.Me)
@Transactional @Transactional
@@ -19,6 +25,6 @@ public class UserService {
.entity("InvalidUserId") .entity("InvalidUserId")
.build(); .build();
return Response.ok(UserModel.find("id", id).firstResult()).build(); return Response.ok(model.find("id", id).firstResult()).build();
} }
} }
@@ -1,8 +1,6 @@
package com.drinkool.services; package com.drinkool.services;
import com.drinkool.InternalValue; import com.drinkool.*;
import com.drinkool.Role;
import com.drinkool.Url;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import com.drinkool.entities.CustomerEntity; import com.drinkool.entities.CustomerEntity;
import jakarta.inject.Inject; import jakarta.inject.Inject;
@@ -10,12 +8,16 @@ import jakarta.transaction.Transactional;
import jakarta.ws.rs.*; import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*; import jakarta.ws.rs.core.*;
@Path("") @Path(Role.Customer)
public class AuthenticationService { public class CustomerService extends BaseService {
@Inject @Inject
OtpService otpService; OtpService otpService;
public CustomerService() {
super(new CustomerEntity());
}
@POST @POST
@Path(Url.Signup) @Path(Url.Signup)
@Transactional @Transactional
@@ -87,24 +89,4 @@ public class AuthenticationService {
.header(InternalValue.role, Role.Customer) .header(InternalValue.role, Role.Customer)
.build(); .build();
} }
@POST
@Path(Url.SmsOtp)
public Response smsOtp(SmsOtp input) {
CustomerEntity customer = CustomerEntity.find(
"phone",
input.phone
).firstResult();
if (customer == null) return Response.status(Response.Status.BAD_REQUEST)
.entity("InvalidPhoneNumber")
.build();
String otp = otpService.generateAndSaveOtp(input.phone);
// đây bạn sẽ gọi Kafka để gửi SMS thực tế
System.out.println("OTP cho " + input.phone + " là: " + otp);
return Response.accepted().build();
}
} }
@@ -0,0 +1,55 @@
package com.drinkool.services;
import com.drinkool.*;
import com.drinkool.dtos.*;
import com.drinkool.entities.ManagerEntity;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*;
@Path(Role.Manager)
public class ManagerService {
@POST
@Path(Url.Signup)
@Transactional
public Response signup(ManagerSignup input) {
ManagerEntity newManager = new ManagerEntity();
newManager.signup(
input.name,
input.phone,
input.password,
input.eateryName
);
return Response.status(Response.Status.CREATED)
.header(InternalValue.userId, newManager.id.toString())
.header(InternalValue.role, Role.Manager)
.build();
}
@POST
@Path(Url.Login)
public Response login(Login input) {
ManagerEntity customer = ManagerEntity.find(
"phone",
input.phone
).firstResult();
if (customer == null) return Response.status(Response.Status.BAD_REQUEST)
.entity("InvalidPhoneNumber")
.build();
if (!customer.login(input.password)) return Response.status(
Response.Status.BAD_REQUEST
)
.entity("InvalidPassword")
.build();
return Response.accepted()
.header(InternalValue.userId, customer.id.toString())
.header(InternalValue.role, Role.Manager)
.build();
}
}
@@ -25,4 +25,4 @@ quarkus.index-dependency.lib.artifact-id=lib
# Build # Build
quarkus.native.container-build=false quarkus.native.container-build=false
quarkus.native.additional-build-args=--initialize-at-run-time=com.password4j.AlgorithmFinder quarkus.native.additional-build-args=--initialize-at-run-time=com.password4j.AlgorithmFinder,--future-defaults=all
@@ -0,0 +1,12 @@
package com.drinkool;
import java.util.Random;
public class Utils {
public static Random random = new Random();
public static String generateRandomPhone() {
return "+8477" + String.format("%07d", random.nextInt(10000000));
}
}
@@ -1,56 +1,29 @@
package com.drinkool.entities; package com.drinkool.entities;
import static org.junit.jupiter.api.Assertions.*;
import com.drinkool.*;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import jakarta.persistence.EntityManager;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;
@QuarkusTest @QuarkusTest
public class CustomerEntityTest { public class CustomerEntityTest {
@Inject
EntityManager entityManager;
@Test @Test
@Transactional @Transactional
public void testCustomerPersistence() { public void testSignupOneParamSuccess() {
// 1. Khởi tạo đúng Entity (CustomerEntity chứ không phải CustomerEntityTest) CustomerEntity user = new CustomerEntity();
CustomerEntity customer = new CustomerEntity(); String phone = Utils.generateRandomPhone();
// Gán đúng biến name, phone và hashedPassword (các trường kế thừa từ UserModel) user.signup(phone);
customer.name = "Nguyen Van A";
customer.phone = "+84987654321";
customer.hashedPassword = "dummy_hashed_password";
// 2. Lưu vào DB assertNotNull(user.id, "ID not null after persist");
entityManager.persist(customer); assertEquals(phone, user.name, "Tên mặc định phải là số điện thoại");
entityManager.flush(); assertEquals(phone, user.phone);
entityManager.clear(); assertNotNull(
user.hashedPassword,
// 3. Truy vấn lại để kiểm tra (Sửa lại class map của query thành CustomerEntity) "Password tự động phải được tạo và hash"
var query = entityManager.createQuery(
"SELECT c FROM CustomerEntity c WHERE c.phone = :phone",
CustomerEntity.class
); );
query.setParameter("phone", "+84987654321");
// Nhận kết quả về đúng kiểu CustomerEntity
CustomerEntity savedCustomer = query.getSingleResult();
// 4. Assert (Kiểm chứng)
Assertions.assertNotNull(savedCustomer, "Customer không được null");
Assertions.assertEquals(
"Nguyen Van A",
savedCustomer.name,
"Tên không khớp"
);
Assertions.assertEquals(
"+84987654321",
savedCustomer.phone,
"Số điện thoại không khớp"
);
Assertions.assertNotNull(savedCustomer.id, "ID chưa được sinh ra");
} }
} }
@@ -44,24 +44,6 @@ public class UserModelTest {
assertNotNull(savedUser, "Phải tìm thấy user trong database"); assertNotNull(savedUser, "Phải tìm thấy user trong database");
} }
// 2. Test case: Đăng ký thành công (chỉ dùng số điện thoại)
@Test
@Transactional
public void testSignupOneParamSuccess() {
TestUserEntity user = new TestUserEntity();
String phone = generateValidPhone();
user.signup(phone);
assertNotNull(user.id, "ID not null after persist");
assertEquals(phone, user.name, "Tên mặc định phải là số điện thoại");
assertEquals(phone, user.phone);
assertNotNull(
user.hashedPassword,
"Password tự động phải được tạo và hash"
);
}
// 3. 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 đã tồn tại
@Test @Test
@Transactional @Transactional
@@ -0,0 +1,40 @@
package com.drinkool.services;
import static io.restassured.RestAssured.*;
import com.drinkool.*;
import com.drinkool.dtos.*;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test;
@QuarkusTest
public class AccountServiceTest {
@Test
void testSmsOtp() {
String phone = Utils.generateRandomPhone();
SmsOtp input = new SmsOtp();
input.phone = phone;
Signup signup = new Signup();
signup.phone = phone;
signup.name = "sms user";
signup.password = "password123";
given()
.contentType(ContentType.JSON)
.body(signup)
.when()
.post(Role.Customer + Url.Signup)
.then();
given()
.contentType(ContentType.JSON)
.body(input)
.when()
.post(Url.SmsOtp)
.then()
.statusCode(202);
}
}
@@ -3,19 +3,18 @@ package com.drinkool.services;
import static io.restassured.RestAssured.*; import static io.restassured.RestAssured.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import com.drinkool.InternalValue; import com.drinkool.*;
import com.drinkool.Url; import com.drinkool.dtos.*;
import com.drinkool.dtos.QuickSignup;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@QuarkusTest @QuarkusTest
public class UserServiceTest { public class BaseServiceTest {
@Test @Test
public void testMeEndpointWithHeader() { public void testMeEndpointWithHeader() {
String phone = AuthenticationServiceTest.generateRandomPhone(); String phone = Utils.generateRandomPhone();
QuickSignup input = new QuickSignup(); QuickSignup input = new QuickSignup();
input.phone = phone; input.phone = phone;
@@ -23,7 +22,7 @@ public class UserServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post(Url.QuickSignup) .post(Role.Customer + Url.QuickSignup)
.then() .then()
.extract() .extract()
.header(InternalValue.userId); .header(InternalValue.userId);
@@ -32,7 +31,7 @@ public class UserServiceTest {
.header(InternalValue.userId, testUserId) .header(InternalValue.userId, testUserId)
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.when() .when()
.post(Url.Me) .post(Role.Customer + Url.Me)
.then() .then()
.statusCode(200) .statusCode(200)
.body("id", is(testUserId)); .body("id", is(testUserId));
@@ -40,6 +39,6 @@ public class UserServiceTest {
@Test @Test
public void testMeEndpointWithoutHeader() { public void testMeEndpointWithoutHeader() {
given().when().post(Url.Me).then().statusCode(400); given().when().post(Role.Customer + Url.Me).then().statusCode(400);
} }
} }
@@ -4,28 +4,23 @@ import static io.restassured.RestAssured.*;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import com.drinkool.InternalValue; import com.drinkool.*;
import com.drinkool.Role;
import com.drinkool.Url;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import com.drinkool.entities.CustomerEntity; import com.drinkool.entities.CustomerEntity;
import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType; import io.restassured.http.ContentType;
import java.util.Random; import jakarta.inject.Inject;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@QuarkusTest @QuarkusTest
public class AuthenticationServiceTest { public class CustomerServiceTest {
public static Random random = new Random(); @Inject
OtpService otpService;
public static String generateRandomPhone() {
return "+8477" + String.format("%07d", random.nextInt(10000000));
}
@Test @Test
void testSignup() { void testSignup() {
String phone = generateRandomPhone(); String phone = Utils.generateRandomPhone();
Signup input = new Signup(); Signup input = new Signup();
input.name = "Test User"; input.name = "Test User";
input.phone = phone; input.phone = phone;
@@ -35,7 +30,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post(Url.Signup) .post(Role.Customer + Url.Signup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -45,7 +40,7 @@ public class AuthenticationServiceTest {
@Test @Test
void testQuickSignup() { void testQuickSignup() {
String phone = generateRandomPhone(); String phone = Utils.generateRandomPhone();
QuickSignup input = new QuickSignup(); QuickSignup input = new QuickSignup();
input.phone = phone; input.phone = phone;
@@ -53,7 +48,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post(Url.QuickSignup) .post(Role.Customer + Url.QuickSignup)
.then() .then()
.header(InternalValue.userId, notNullValue()) .header(InternalValue.userId, notNullValue())
.header(InternalValue.role, is(Role.Customer)) .header(InternalValue.role, is(Role.Customer))
@@ -65,7 +60,7 @@ public class AuthenticationServiceTest {
@Test @Test
void testLoginSuccess() { void testLoginSuccess() {
// BƯỚC 1: Tạo user trước bằng signup // BƯỚC 1: Tạo user trước bằng signup
String phone = generateRandomPhone(); String phone = Utils.generateRandomPhone();
Signup signupData = new Signup(); Signup signupData = new Signup();
signupData.name = "Login User"; signupData.name = "Login User";
signupData.phone = phone; signupData.phone = phone;
@@ -74,7 +69,7 @@ public class AuthenticationServiceTest {
given() given()
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(signupData) .body(signupData)
.post(Url.Signup) .post(Role.Customer + Url.Signup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -87,14 +82,14 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(loginInput) .body(loginInput)
.when() .when()
.post(Url.Login) .post(Role.Customer + Url.Login)
.then() .then()
.statusCode(202); .statusCode(202);
} }
@Test @Test
void testLoginFailWrongPassword() { void testLoginFailWrongPassword() {
String phone = generateRandomPhone(); String phone = Utils.generateRandomPhone();
Signup signupData = new Signup(); Signup signupData = new Signup();
signupData.name = "Wrong Pass User"; signupData.name = "Wrong Pass User";
signupData.phone = phone; signupData.phone = phone;
@@ -103,7 +98,7 @@ public class AuthenticationServiceTest {
given() given()
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(signupData) .body(signupData)
.post(Url.Signup) .post(Role.Customer + Url.Signup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -115,41 +110,41 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(loginInput) .body(loginInput)
.when() .when()
.post(Url.Login) .post(Role.Customer + Url.Login)
.then() .then()
.statusCode(400); // BadRequestException .statusCode(400); // BadRequestException
} }
@Test @Test
void testSmsOtp() { public void testQuickLogin_Success() {
String phone = generateRandomPhone(); String phone = Utils.generateRandomPhone();
SmsOtp input = new SmsOtp();
QuickSignup input = new QuickSignup();
input.phone = phone; input.phone = phone;
Signup signup = new Signup();
signup.phone = phone;
signup.name = "sms user";
signup.password = "password123";
given()
.contentType(ContentType.JSON)
.body(signup)
.when()
.post(Url.Signup)
.then();
given() given()
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post(Url.SmsOtp) .post(Role.Customer + Url.QuickSignup)
.then();
QuickLogin payload = new QuickLogin();
payload.phone = phone;
payload.otp = otpService.generateAndSaveOtp(phone);
given()
.contentType(ContentType.JSON)
.body(payload)
.when()
.post(Role.Customer + Url.QuickLogin)
.then() .then()
.statusCode(202); .statusCode(202);
} }
@Test @Test
void testQuickLoginFailInvalidOtp() { void testQuickLoginFailInvalidOtp() {
String phone = generateRandomPhone(); String phone = Utils.generateRandomPhone();
QuickLogin input = new QuickLogin(); QuickLogin input = new QuickLogin();
input.phone = phone; input.phone = phone;
input.otp = "000000"; // Giả sử này luôn sai chưa được tạo input.otp = "000000"; // Giả sử này luôn sai chưa được tạo
@@ -158,7 +153,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post(Url.QuickLogin) .post(Role.Customer + Url.QuickLogin)
.then() .then()
.statusCode(401); .statusCode(401);
} }
+12 -20
View File
@@ -17,6 +17,9 @@
<packaging>quarkus</packaging> <packaging>quarkus</packaging>
<properties> <properties>
<quarkus.package.jar.enabled>false</quarkus.package.jar.enabled>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
<compiler-plugin.version>3.15.0</compiler-plugin.version> <compiler-plugin.version>3.15.0</compiler-plugin.version>
<maven.compiler.release>25</maven.compiler.release> <maven.compiler.release>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -43,6 +46,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.drinkool</groupId> <groupId>com.drinkool</groupId>
<artifactId>lib</artifactId> <artifactId>lib</artifactId>
@@ -66,10 +74,6 @@
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId> <artifactId>quarkus-jackson</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-messaging-kafka</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId> <artifactId>quarkus-jdbc-postgresql</artifactId>
@@ -86,6 +90,10 @@
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId> <artifactId>quarkus-rest-jackson</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-junit</artifactId> <artifactId>quarkus-junit</artifactId>
@@ -144,20 +152,4 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.jar.enabled>false</quarkus.package.jar.enabled>
<skipITs>false</skipITs>
<quarkus.native.enabled>true</quarkus.native.enabled>
</properties>
</profile>
</profiles>
</project> </project>
@@ -1,6 +1,3 @@
# Kafka
kafka.bootstrap.servers=localhost:9092
# Postgress # Postgress
## Cấu hình Database ## Cấu hình Database
quarkus.datasource.db-kind=postgresql quarkus.datasource.db-kind=postgresql
@@ -11,6 +8,19 @@ 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) ## Tự động tạo bảng từ Entity (chỉ dùng cho môi trường dev)
quarkus.hibernate-orm.database.generation=update quarkus.hibernate-orm.database.generation=update
# Docker
quarkus.container-image.registry=git.demonkernel.io.vn
quarkus.container-image.group=foodsurf
quarkus.container-image.name=eatery-service
quarkus.container-image.push=true
quarkus.container-image.build=true
quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest
# Dependency # Dependency
quarkus.index-dependency.lib.group-id=com.drinkool quarkus.index-dependency.lib.group-id=com.drinkool
quarkus.index-dependency.lib.artifact-id=lib quarkus.index-dependency.lib.artifact-id=lib
# Build
quarkus.native.container-build=false
quarkus.native.additional-build-args=--future-defaults=all
+5
View File
@@ -46,6 +46,11 @@
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.bitbucket.b_c</groupId> <groupId>org.bitbucket.b_c</groupId>
<artifactId>jose4j</artifactId> <artifactId>jose4j</artifactId>
@@ -8,8 +8,8 @@ import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/api/v1/customers") @Path("/api/" + Role.Customer)
public class CustomerGatewayResource { class CustomerGatewayResource {
@Inject @Inject
@RestClient @RestClient
@@ -26,4 +26,9 @@ public class CustomerGatewayResource {
public Uni<Response> proxyLogin(Login input) { public Uni<Response> proxyLogin(Login input) {
return accountService.login(input); return accountService.login(input);
} }
@GET
public Uni<Response> me() {
return accountService.me();
}
} }
@@ -1,5 +1,6 @@
package com.drinkool.services; package com.drinkool.services;
import com.drinkool.Role;
import com.drinkool.Url; import com.drinkool.Url;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.Uni;
@@ -8,7 +9,7 @@ import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient(configKey = "account") @RegisterRestClient(configKey = "account")
@Path("") @Path(Role.Customer)
public interface AccountService { public interface AccountService {
@POST @POST
@Path(Url.Signup) @Path(Url.Signup)
@@ -29,4 +30,7 @@ public interface AccountService {
@POST @POST
@Path(Url.SmsOtp) @Path(Url.SmsOtp)
Uni<Response> smsOtp(SmsOtp input); Uni<Response> smsOtp(SmsOtp input);
@GET
Uni<Response> me();
} }
@@ -8,4 +8,5 @@ quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest quarkus.container-image.additional-tags=latest
# Build # Build
quarkus.native.container-build=false quarkus.native.container-build=false
quarkus.native.additional-build-args=--future-defaults=all
+68 -12
View File
@@ -38,12 +38,12 @@ spec:
name: postgres-credentials name: postgres-credentials
key: url key: url
resources: resources:
limits:
cpu: "500m"
memory: "512Mi"
requests: requests:
cpu: "100m" memory: "32Mi"
memory: "256Mi" cpu: "50m"
limits:
memory: "64Mi"
cpu: "250m"
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@@ -56,7 +56,63 @@ spec:
- port: 80 - port: 80
targetPort: 8080 targetPort: 8080
--- ---
# 2. GATEWAY SERVICE # 2. EATERY SERVICE
apiVersion: apps/v1
kind: Deployment
metadata:
name: eatery-deploy
spec:
replicas: 1
selector:
matchLabels:
app: eatery
template:
metadata:
labels:
app: eatery
spec:
containers:
- name: eatery-pod
image: git.demonkernel.io.vn/foodsurf/eatery-service:1.4.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: QUARKUS_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: QUARKUS_DATASOURCE_USERNAME
valueFrom:
secretKeyRef:
name: postgres-credentials
key: username
- name: QUARKUS_DATASOURCE_JDBC_URL
valueFrom:
secretKeyRef:
name: postgres-credentials
key: url
resources:
requests:
memory: "32Mi"
cpu: "50m"
limits:
memory: "64Mi"
cpu: "250m"
---
apiVersion: v1
kind: Service
metadata:
name: eatery-service
spec:
selector:
app: eatery
ports:
- port: 80
targetPort: 8080
---
# 3. GATEWAY SERVICE
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@@ -86,12 +142,12 @@ spec:
name: jwt-secret name: jwt-secret
key: secret key: secret
resources: resources:
limits:
cpu: "500m"
memory: "512Mi"
requests: requests:
cpu: "100m" memory: "32Mi"
memory: "256Mi" cpu: "50m"
limits:
memory: "64Mi"
cpu: "250m"
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@@ -106,7 +162,7 @@ spec:
targetPort: 8080 targetPort: 8080
nodePort: 32080 nodePort: 32080
--- ---
# 3. REDIS # 4. REDIS
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
+1
View File
@@ -3,4 +3,5 @@ package com.drinkool;
public class Role { public class Role {
public static final String Customer = "customer"; public static final String Customer = "customer";
public static final String Manager = "manager";
} }
@@ -0,0 +1,5 @@
package com.drinkool.dtos;
public class ManagerSignup extends Signup {
public String eateryName;
}
+25 -5
View File
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8"?>
<project <project
xmlns="http://maven.apache.org/POM/4.0.0" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
> >
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.drinkool</groupId> <groupId>com.drinkool</groupId>
@@ -30,6 +30,26 @@
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
<version>${quarkus.platform.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
</project> <build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<quarkus.jacoco.data-file>${maven.multiModuleProjectDirectory}/target/jacoco.exec</quarkus.jacoco.data-file>
<quarkus.jacoco.reuse-data-file>true</quarkus.jacoco.reuse-data-file>
<quarkus.jacoco.report-location>${maven.multiModuleProjectDirectory}/target/coverage</quarkus.jacoco.report-location>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>