chore: update

This commit is contained in:
TakahashiNg
2026-04-06 06:08:23 +00:00
parent 67746a2d06
commit a6be162f40
9 changed files with 148 additions and 40 deletions
+4 -1
View File
@@ -7,7 +7,10 @@ RUN apk update && apk add --no-cache \
maven \ maven \
git \ git \
ca-certificates \ ca-certificates \
pnpm pnpm \
docker-cli \
kubectl \
helm
# git trust all directories # git trust all directories
RUN git config --global --add safe.directory '*' RUN git config --global --add safe.directory '*'
+3 -2
View File
@@ -3,7 +3,8 @@
{ {
"dockerComposeFile": "docker-compose.main.yaml", "dockerComposeFile": "docker-compose.main.yaml",
"mounts": [ "mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
"source=${localEnv:USERPROFILE}/.kube,target=/root/.kube,type=bind"
], ],
"remoteUser": "root", "remoteUser": "root",
"service": "devcontainer", "service": "devcontainer",
@@ -24,5 +25,5 @@
"TESTCONTAINERS_RYUK_DISABLED": "true", "TESTCONTAINERS_RYUK_DISABLED": "true",
"QUARKUS_DEBUG_HOST": "0.0.0.0" "QUARKUS_DEBUG_HOST": "0.0.0.0"
}, },
"forwardPorts": [5005] "forwardPorts": [5005, 8080]
} }
@@ -1,5 +1,6 @@
package com.drinkool.services; package com.drinkool.services;
import com.drinkool.Jwt;
import com.drinkool.Url; import com.drinkool.Url;
import com.drinkool.dtos.*; import com.drinkool.dtos.*;
import com.drinkool.entities.CustomerEntity; import com.drinkool.entities.CustomerEntity;
@@ -22,7 +23,10 @@ public class AuthenticationService {
newCustomer.signup(input.name, input.phone, input.password); newCustomer.signup(input.name, input.phone, input.password);
return Response.status(Response.Status.CREATED).build(); return Response.status(Response.Status.CREATED)
.header(Jwt.userId, newCustomer.id.toString())
.header(Jwt.role, "customer")
.build();
} }
@POST @POST
@@ -33,7 +37,10 @@ public class AuthenticationService {
newCustomer.signup(input.phone); newCustomer.signup(input.phone);
return Response.status(Response.Status.CREATED).build(); return Response.status(Response.Status.CREATED)
.header(Jwt.userId, newCustomer.id.toString())
.header(Jwt.role, "customer")
.build();
} }
@POST @POST
@@ -44,29 +51,54 @@ public class AuthenticationService {
input.phone input.phone
).firstResult(); ).firstResult();
if (customer == null) throw new BadRequestException("InvalidPhoneNumber"); if (customer == null) return Response.status(Response.Status.BAD_REQUEST)
.entity("InvalidPhoneNumber")
.build();
if (!customer.login(input.password)) throw new BadRequestException( if (!customer.login(input.password)) return Response.status(
"InvalidPassword" Response.Status.BAD_REQUEST
); )
.entity("InvalidPassword")
.build();
return Response.accepted().build(); return Response.accepted()
.header(Jwt.userId, customer.id.toString())
.header(Jwt.role, "customer")
.build();
} }
@POST @POST
@Path(Url.QuickLogin) @Path(Url.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.status(Response.Status.UNAUTHORIZED)
.entity("InvalidOTP")
.build();
} }
return Response.status(Response.Status.UNAUTHORIZED)
.entity("InvalidOTP") CustomerEntity customer = CustomerEntity.find(
"phone",
input.phone
).firstResult();
return Response.accepted()
.header(Jwt.userId, customer.id.toString())
.header(Jwt.role, "customer")
.build(); .build();
} }
@POST @POST
@Path(Url.SmsOtp) @Path(Url.SmsOtp)
public Response smsOtp(SmsOtp input) { 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); String otp = otpService.generateAndSaveOtp(input.phone);
// Ở đây bạn sẽ gọi Kafka để gửi SMS thực tế // Ở đây bạn sẽ gọi Kafka để gửi SMS thực tế
@@ -0,0 +1,19 @@
package com.drinkool.services;
import com.drinkool.Url;
import com.drinkool.entities.CustomerEntity;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;
import com.drinkool.Jwt;
@Path("")
public class CustomerService {
@POST
@Path(Url.Me)
@Transactional
public Response me(@HeaderParam(Jwt.userId) String id) {
return Response.ok(CustomerEntity.find("id", id)).build();
}
}
@@ -13,6 +13,7 @@ quarkus.container-image.name=account-service
quarkus.container-image.push=true quarkus.container-image.push=true
quarkus.container-image.build=true quarkus.container-image.build=true
quarkus.container-image.builder=docker quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest
# Redis # Redis
quarkus.redis.hosts=redis://localhost:6379 quarkus.redis.hosts=redis://localhost:6379
@@ -1,6 +1,7 @@
package com.drinkool.services; package com.drinkool.services;
import static io.restassured.RestAssured.given; import static io.restassured.RestAssured.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import com.drinkool.Url; import com.drinkool.Url;
@@ -14,9 +15,9 @@ import org.junit.jupiter.api.Test;
@QuarkusTest @QuarkusTest
public class AuthenticationServiceTest { public class AuthenticationServiceTest {
private Random random = new Random(); public static Random random = new Random();
private String generateRandomPhone() { public static String generateRandomPhone() {
return "+8477" + String.format("%07d", random.nextInt(10000000)); return "+8477" + String.format("%07d", random.nextInt(10000000));
} }
@@ -52,6 +53,8 @@ public class AuthenticationServiceTest {
.when() .when()
.post(Url.QuickSignup) .post(Url.QuickSignup)
.then() .then()
.header("X-Internal-User-Id", notNullValue())
.header("X-Internal-User-Roles", is("user"))
.statusCode(201); .statusCode(201);
assertEquals(1, CustomerEntity.find("phone", phone).count()); assertEquals(1, CustomerEntity.find("phone", phone).count());
@@ -5,3 +5,4 @@ quarkus.container-image.name=gateway-service
quarkus.container-image.push=true quarkus.container-image.push=true
quarkus.container-image.build=true quarkus.container-image.build=true
quarkus.container-image.builder=docker quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest
+70 -23
View File
@@ -2,25 +2,56 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: account-service name: account-deploy
spec: spec:
replicas: 1 replicas: 1
selector: selector:
matchLabels: matchLabels:
app: account-service app: account
template: template:
metadata: metadata:
labels: labels:
app: account-service app: account
spec: spec:
containers: containers:
- name: account-service - name: account-pod
image: git.demonkernel.io.vn/foodsurf/account-service:latest image: git.demonkernel.io.vn/foodsurf/account-service:latest
imagePullPolicy: IfNotPresent
ports: ports:
- containerPort: 8080 - containerPort: 8080
env: env:
- name: QUARKUS_REDIS_HOST - name: QUARKUS_REDIS_HOST
value: "redis-service" value: "redis-service"
- 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:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "100m"
memory: "256Mi"
volumeMounts:
- name: keys-volume
mountPath: "/etc/keys"
readOnly: true
volumes:
- name: keys-volume
secret:
secretName: jwt-keys
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@@ -28,7 +59,7 @@ metadata:
name: account-service name: account-service
spec: spec:
selector: selector:
app: account-service app: account
ports: ports:
- port: 80 - port: 80
targetPort: 8080 targetPort: 8080
@@ -49,13 +80,29 @@ spec:
app: gateway app: gateway
spec: spec:
containers: containers:
- name: gateway - name: gateway-pod
image: git.demonkernel.io.vn/foodsurf/gateway-service:latest image: git.demonkernel.io.vn/foodsurf/gateway-service:latest
imagePullPolicy: IfNotPresent
ports: ports:
- containerPort: 8080 - containerPort: 8080
env: env:
- name: QUARKUS_REST_CLIENT_ACCOUNT_URL - name: QUARKUS_REST_CLIENT_ACCOUNT_URL
value: "http://account-service" value: "http://account-service"
resources:
limits:
cpu: "500m"
memory: "512Mi"
requests:
cpu: "100m"
memory: "256Mi"
volumeMounts:
- name: keys-volume
mountPath: "/etc/keys"
readOnly: true
volumes:
- name: keys-volume
secret:
secretName: jwt-keys
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
@@ -68,7 +115,7 @@ spec:
ports: ports:
- port: 80 - port: 80
targetPort: 8080 targetPort: 8080
nodePort: 39080 nodePort: 32080
--- ---
# 3. REDIS # 3. REDIS
apiVersion: apps/v1 apiVersion: apps/v1
@@ -85,25 +132,25 @@ spec:
app: redis app: redis
spec: spec:
containers: containers:
- name: redis - name: redis-pod
image: redis:alpine image: redis:alpine
ports: ports:
- containerPort: 6379 - containerPort: 6379
resources: resources:
limits: limits:
cpu: "100m" cpu: "100m"
memory: "128Mi" memory: "128Mi"
requests: requests:
cpu: "20m" cpu: "20m"
memory: "64Mi" memory: "64Mi"
command: command:
[ [
"redis-server", "redis-server",
"--maxmemory", "--maxmemory",
"96mb", "96mb",
"--maxmemory-policy", "--maxmemory-policy",
"allkeys-lru", "allkeys-lru",
] ]
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
+1
View File
@@ -7,4 +7,5 @@ public class Url {
public static final String Login = "/login"; public static final String Login = "/login";
public static final String QuickLogin = "/quick_login"; public static final String QuickLogin = "/quick_login";
public static final String SmsOtp = "/sms_otp"; public static final String SmsOtp = "/sms_otp";
public static final String Me = "/me";
} }