chore: update
Java CI with Maven / build-and-test (pull_request) Has been cancelled

This commit is contained in:
TakahashiNg
2026-03-31 11:12:48 +00:00
parent 554e8767d8
commit 0662331aa6
10 changed files with 179 additions and 52 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
[ [
"@semantic-release/exec", "@semantic-release/exec",
{ {
"prepareCmd": "./mvnw versions:set -DnewVersion=${nextRelease.version}", "prepareCmd": "./mvnw versions:set -DnewVersion=${nextRelease.version} && sed -i \"s|\\(image: git.demonkernel.io.vn/foodsurf/[^:]*\\):.*|\\1:${nextRelease.version}|g\" k8s.yaml",
"publishCmd": "if [ \"${branch.name}\" = \"main\" ]; then ./mvnw 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,5 +1,6 @@
package com.drinkool.services; package com.drinkool.services;
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;
@@ -7,14 +8,14 @@ import jakarta.transaction.Transactional;
import jakarta.ws.rs.*; import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*; import jakarta.ws.rs.core.*;
@Path("/api") @Path("")
public class AuthenticationService { public class AuthenticationService {
@Inject @Inject
OtpService otpService; OtpService otpService;
@POST @POST
@Path("/signup") @Path(Url.Signup)
@Transactional @Transactional
public Response signup(Signup input) { public Response signup(Signup input) {
CustomerEntity newCustomer = new CustomerEntity(); CustomerEntity newCustomer = new CustomerEntity();
@@ -25,7 +26,7 @@ public class AuthenticationService {
} }
@POST @POST
@Path("/quickSignup") @Path(Url.QuickSignup)
@Transactional @Transactional
public Response quickSignup(QuickSignup input) { public Response quickSignup(QuickSignup input) {
CustomerEntity newCustomer = new CustomerEntity(); CustomerEntity newCustomer = new CustomerEntity();
@@ -36,7 +37,7 @@ public class AuthenticationService {
} }
@POST @POST
@Path("/login") @Path(Url.Login)
public Response login(Login input) { public Response login(Login input) {
CustomerEntity customer = CustomerEntity.find( CustomerEntity customer = CustomerEntity.find(
"phone", "phone",
@@ -53,18 +54,7 @@ public class AuthenticationService {
} }
@POST @POST
@Path("/sms_otp") @Path(Url.QuickLogin)
public Response smsOtp(SmsOtp input) {
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();
}
@POST
@Path("/quicklogin")
public Response quickLogin(QuickLogin input) { public Response quickLogin(QuickLogin input) {
if (otpService.verifyOtp(input.phone, input.otp)) { if (otpService.verifyOtp(input.phone, input.otp)) {
return Response.accepted().build(); return Response.accepted().build();
@@ -73,4 +63,15 @@ public class AuthenticationService {
.entity("InvalidOTP") .entity("InvalidOTP")
.build(); .build();
} }
@POST
@Path(Url.SmsOtp)
public Response smsOtp(SmsOtp input) {
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();
}
} }
@@ -7,7 +7,6 @@ quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres
quarkus.hibernate-orm.database.generation=update quarkus.hibernate-orm.database.generation=update
# Docker # Docker
## URL của Gitea Registry (thường là gitea.yourdomain.com)
quarkus.container-image.registry=git.demonkernel.io.vn quarkus.container-image.registry=git.demonkernel.io.vn
quarkus.container-image.group=foodsurf quarkus.container-image.group=foodsurf
quarkus.container-image.name=account-service quarkus.container-image.name=account-service
@@ -3,6 +3,7 @@ package com.drinkool.services;
import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
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;
@@ -31,7 +32,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post("/api/signup") .post(Url.Signup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -49,7 +50,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post("/api/quickSignup") .post(Url.QuickSignup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -68,7 +69,7 @@ public class AuthenticationServiceTest {
given() given()
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(signupData) .body(signupData)
.post("/api/signup") .post(Url.Signup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -81,7 +82,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(loginInput) .body(loginInput)
.when() .when()
.post("/api/login") .post(Url.Login)
.then() .then()
.statusCode(202); .statusCode(202);
} }
@@ -97,7 +98,7 @@ public class AuthenticationServiceTest {
given() given()
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(signupData) .body(signupData)
.post("/api/signup") .post(Url.Signup)
.then() .then()
.statusCode(201); .statusCode(201);
@@ -109,7 +110,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(loginInput) .body(loginInput)
.when() .when()
.post("/api/login") .post(Url.Login)
.then() .then()
.statusCode(400); // BadRequestException .statusCode(400); // BadRequestException
} }
@@ -124,7 +125,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post("/api/sms_otp") .post(Url.SmsOtp)
.then() .then()
.statusCode(202); .statusCode(202);
@@ -143,7 +144,7 @@ public class AuthenticationServiceTest {
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post("/api/quicklogin") .post(Url.QuickLogin)
.then() .then()
.statusCode(401); .statusCode(401);
} }
+4 -4
View File
@@ -48,10 +48,6 @@
<artifactId>lib</artifactId> <artifactId>lib</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-jackson</artifactId> <artifactId>quarkus-rest-jackson</artifactId>
@@ -64,6 +60,10 @@
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId> <artifactId>quarkus-rest</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-rest-client-jackson</artifactId> <artifactId>quarkus-rest-client-jackson</artifactId>
@@ -2,7 +2,6 @@ package com.drinkool;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import com.drinkool.services.AccountService; import com.drinkool.services.AccountService;
import io.quarkus.redis.datasource.RedisDataSource;
import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import jakarta.ws.rs.*; import jakarta.ws.rs.*;
@@ -16,28 +15,14 @@ public class CustomerGatewayResource {
@RestClient @RestClient
AccountService accountService; AccountService accountService;
@Inject
RedisDataSource redisDataSource;
@POST @POST
@Path("/signup") @Path(Url.Signup)
public Uni<Response> proxySignup(Signup input) { public Uni<Response> proxySignup(Signup input) {
String otpVerifiedKey = "otp:verified:" + input.phone;
var valueCmd = redisDataSource.value(String.class);
if (valueCmd.get(otpVerifiedKey) == null) {
return Uni.createFrom().item(
Response.status(Response.Status.FORBIDDEN)
.entity("Phone not verified")
.build()
);
}
return accountService.signup(input); return accountService.signup(input);
} }
@POST @POST
@Path("/login") @Path(Url.Login)
public Uni<Response> proxyLogin(Login input) { public Uni<Response> proxyLogin(Login input) {
return accountService.login(input); return accountService.login(input);
} }
@@ -1,5 +1,6 @@
package com.drinkool.services; package com.drinkool.services;
import com.drinkool.Url;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import io.smallrye.mutiny.Uni; import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.*; import jakarta.ws.rs.*;
@@ -7,17 +8,25 @@ 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("/api") @Path("")
public interface AccountService { public interface AccountService {
@POST @POST
@Path("/signup") @Path(Url.Signup)
Uni<Response> signup(Signup input); Uni<Response> signup(Signup input);
@POST @POST
@Path("/quickSignup") @Path(Url.QuickSignup)
Uni<Response> quickSignup(QuickSignup input); Uni<Response> quickSignup(QuickSignup input);
@POST @POST
@Path("/login") @Path(Url.Login)
Uni<Response> login(Login input); Uni<Response> login(Login input);
@POST
@Path(Url.QuickLogin)
Uni<Response> quickLogin(QuickSignup input);
@POST
@Path(Url.SmsOtp)
Uni<Response> smsOtp(SmsOtp input);
} }
@@ -1 +1,7 @@
quarkus.rest-client.account.url=http://localhost:502 # Docker
quarkus.container-image.registry=git.demonkernel.io.vn
quarkus.container-image.group=foodsurf
quarkus.container-image.name=gateway-service
quarkus.container-image.push=true
quarkus.container-image.build=true
quarkus.container-image.builder=docker
+116
View File
@@ -0,0 +1,116 @@
# 1. ACCOUNT SERVICE
apiVersion: apps/v1
kind: Deployment
metadata:
name: account-service
spec:
replicas: 1
selector:
matchLabels:
app: account-service
template:
metadata:
labels:
app: account-service
spec:
containers:
- name: account-service
image: git.demonkernel.io.vn/foodsurf/account-service:latest
ports:
- containerPort: 8080
env:
- name: QUARKUS_REDIS_HOST
value: "redis-service"
---
apiVersion: v1
kind: Service
metadata:
name: account-service
spec:
selector:
app: account-service
ports:
- port: 80
targetPort: 8080
---
# 2. GATEWAY SERVICE
apiVersion: apps/v1
kind: Deployment
metadata:
name: gateway-deploy
spec:
replicas: 1
selector:
matchLabels:
app: gateway
template:
metadata:
labels:
app: gateway
spec:
containers:
- name: gateway
image: git.demonkernel.io.vn/foodsurf/gateway-service:latest
ports:
- containerPort: 8080
env:
- name: QUARKUS_REST_CLIENT_ACCOUNT_URL
value: "http://account-service"
---
apiVersion: v1
kind: Service
metadata:
name: gateway-service
spec:
type: NodePort
selector:
app: gateway
ports:
- port: 80
targetPort: 8080
nodePort: 39080
---
# 3. REDIS
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-deploy
spec:
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis:alpine
ports:
- containerPort: 6379
resources:
limits:
cpu: "100m"
memory: "128Mi"
requests:
cpu: "20m"
memory: "64Mi"
command:
[
"redis-server",
"--maxmemory",
"96mb",
"--maxmemory-policy",
"allkeys-lru",
]
---
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
selector:
app: redis
ports:
- port: 6379
+10
View File
@@ -0,0 +1,10 @@
package com.drinkool;
public class Url {
public static final String Signup = "/signup";
public static final String QuickSignup = "/quick_signup";
public static final String Login = "/login";
public static final String QuickLogin = "/quick_login";
public static final String SmsOtp = "/sms_otp";
}