This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@
|
||||
[
|
||||
"@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"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.*;
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -7,14 +8,14 @@ import jakarta.transaction.Transactional;
|
||||
import jakarta.ws.rs.*;
|
||||
import jakarta.ws.rs.core.*;
|
||||
|
||||
@Path("/api")
|
||||
@Path("")
|
||||
public class AuthenticationService {
|
||||
|
||||
@Inject
|
||||
OtpService otpService;
|
||||
|
||||
@POST
|
||||
@Path("/signup")
|
||||
@Path(Url.Signup)
|
||||
@Transactional
|
||||
public Response signup(Signup input) {
|
||||
CustomerEntity newCustomer = new CustomerEntity();
|
||||
@@ -25,7 +26,7 @@ public class AuthenticationService {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/quickSignup")
|
||||
@Path(Url.QuickSignup)
|
||||
@Transactional
|
||||
public Response quickSignup(QuickSignup input) {
|
||||
CustomerEntity newCustomer = new CustomerEntity();
|
||||
@@ -36,7 +37,7 @@ public class AuthenticationService {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/login")
|
||||
@Path(Url.Login)
|
||||
public Response login(Login input) {
|
||||
CustomerEntity customer = CustomerEntity.find(
|
||||
"phone",
|
||||
@@ -53,18 +54,7 @@ public class AuthenticationService {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/sms_otp")
|
||||
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")
|
||||
@Path(Url.QuickLogin)
|
||||
public Response quickLogin(QuickLogin input) {
|
||||
if (otpService.verifyOtp(input.phone, input.otp)) {
|
||||
return Response.accepted().build();
|
||||
@@ -73,4 +63,15 @@ public class AuthenticationService {
|
||||
.entity("InvalidOTP")
|
||||
.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
|
||||
|
||||
# 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
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.drinkool.services;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.*;
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
@@ -31,7 +32,7 @@ public class AuthenticationServiceTest {
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
.when()
|
||||
.post("/api/signup")
|
||||
.post(Url.Signup)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
@@ -49,7 +50,7 @@ public class AuthenticationServiceTest {
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
.when()
|
||||
.post("/api/quickSignup")
|
||||
.post(Url.QuickSignup)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
@@ -68,7 +69,7 @@ public class AuthenticationServiceTest {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(signupData)
|
||||
.post("/api/signup")
|
||||
.post(Url.Signup)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
@@ -81,7 +82,7 @@ public class AuthenticationServiceTest {
|
||||
.contentType(ContentType.JSON)
|
||||
.body(loginInput)
|
||||
.when()
|
||||
.post("/api/login")
|
||||
.post(Url.Login)
|
||||
.then()
|
||||
.statusCode(202);
|
||||
}
|
||||
@@ -97,7 +98,7 @@ public class AuthenticationServiceTest {
|
||||
given()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(signupData)
|
||||
.post("/api/signup")
|
||||
.post(Url.Signup)
|
||||
.then()
|
||||
.statusCode(201);
|
||||
|
||||
@@ -109,7 +110,7 @@ public class AuthenticationServiceTest {
|
||||
.contentType(ContentType.JSON)
|
||||
.body(loginInput)
|
||||
.when()
|
||||
.post("/api/login")
|
||||
.post(Url.Login)
|
||||
.then()
|
||||
.statusCode(400); // BadRequestException
|
||||
}
|
||||
@@ -124,7 +125,7 @@ public class AuthenticationServiceTest {
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
.when()
|
||||
.post("/api/sms_otp")
|
||||
.post(Url.SmsOtp)
|
||||
.then()
|
||||
.statusCode(202);
|
||||
|
||||
@@ -143,7 +144,7 @@ public class AuthenticationServiceTest {
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
.when()
|
||||
.post("/api/quicklogin")
|
||||
.post(Url.QuickLogin)
|
||||
.then()
|
||||
.statusCode(401);
|
||||
}
|
||||
|
||||
@@ -48,10 +48,6 @@
|
||||
<artifactId>lib</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-redis-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-jackson</artifactId>
|
||||
@@ -64,6 +60,10 @@
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-container-image-docker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.quarkus</groupId>
|
||||
<artifactId>quarkus-rest-client-jackson</artifactId>
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.drinkool;
|
||||
|
||||
import com.drinkool.dtos.*;
|
||||
import com.drinkool.services.AccountService;
|
||||
import io.quarkus.redis.datasource.RedisDataSource;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.*;
|
||||
@@ -16,28 +15,14 @@ public class CustomerGatewayResource {
|
||||
@RestClient
|
||||
AccountService accountService;
|
||||
|
||||
@Inject
|
||||
RedisDataSource redisDataSource;
|
||||
|
||||
@POST
|
||||
@Path("/signup")
|
||||
@Path(Url.Signup)
|
||||
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);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/login")
|
||||
@Path(Url.Login)
|
||||
public Uni<Response> proxyLogin(Login input) {
|
||||
return accountService.login(input);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.*;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import jakarta.ws.rs.*;
|
||||
@@ -7,17 +8,25 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
|
||||
|
||||
@RegisterRestClient(configKey = "account")
|
||||
@Path("/api")
|
||||
@Path("")
|
||||
public interface AccountService {
|
||||
@POST
|
||||
@Path("/signup")
|
||||
@Path(Url.Signup)
|
||||
Uni<Response> signup(Signup input);
|
||||
|
||||
@POST
|
||||
@Path("/quickSignup")
|
||||
@Path(Url.QuickSignup)
|
||||
Uni<Response> quickSignup(QuickSignup input);
|
||||
|
||||
@POST
|
||||
@Path("/login")
|
||||
@Path(Url.Login)
|
||||
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
|
||||
|
||||
@@ -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
|
||||
@@ -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";
|
||||
}
|
||||
Reference in New Issue
Block a user