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 \
git \
ca-certificates \
pnpm
pnpm \
docker-cli \
kubectl \
helm
# git trust all directories
RUN git config --global --add safe.directory '*'
+3 -2
View File
@@ -3,7 +3,8 @@
{
"dockerComposeFile": "docker-compose.main.yaml",
"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",
"service": "devcontainer",
@@ -24,5 +25,5 @@
"TESTCONTAINERS_RYUK_DISABLED": "true",
"QUARKUS_DEBUG_HOST": "0.0.0.0"
},
"forwardPorts": [5005]
"forwardPorts": [5005, 8080]
}
@@ -1,5 +1,6 @@
package com.drinkool.services;
import com.drinkool.Jwt;
import com.drinkool.Url;
import com.drinkool.dtos.*;
import com.drinkool.entities.CustomerEntity;
@@ -22,7 +23,10 @@ public class AuthenticationService {
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
@@ -33,7 +37,10 @@ public class AuthenticationService {
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
@@ -44,29 +51,54 @@ public class AuthenticationService {
input.phone
).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(
"InvalidPassword"
);
if (!customer.login(input.password)) return Response.status(
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
@Path(Url.QuickLogin)
public Response quickLogin(QuickLogin input) {
if (otpService.verifyOtp(input.phone, input.otp)) {
return Response.accepted().build();
if (!otpService.verifyOtp(input.phone, input.otp)) {
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();
}
@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ế
@@ -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.build=true
quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest
# Redis
quarkus.redis.hosts=redis://localhost:6379
@@ -1,6 +1,7 @@
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 com.drinkool.Url;
@@ -14,9 +15,9 @@ import org.junit.jupiter.api.Test;
@QuarkusTest
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));
}
@@ -52,6 +53,8 @@ public class AuthenticationServiceTest {
.when()
.post(Url.QuickSignup)
.then()
.header("X-Internal-User-Id", notNullValue())
.header("X-Internal-User-Roles", is("user"))
.statusCode(201);
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.build=true
quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest
+70 -23
View File
@@ -2,25 +2,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: account-service
name: account-deploy
spec:
replicas: 1
selector:
matchLabels:
app: account-service
app: account
template:
metadata:
labels:
app: account-service
app: account
spec:
containers:
- name: account-service
- name: account-pod
image: git.demonkernel.io.vn/foodsurf/account-service:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: QUARKUS_REDIS_HOST
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
kind: Service
@@ -28,7 +59,7 @@ metadata:
name: account-service
spec:
selector:
app: account-service
app: account
ports:
- port: 80
targetPort: 8080
@@ -49,13 +80,29 @@ spec:
app: gateway
spec:
containers:
- name: gateway
- name: gateway-pod
image: git.demonkernel.io.vn/foodsurf/gateway-service:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: QUARKUS_REST_CLIENT_ACCOUNT_URL
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
kind: Service
@@ -68,7 +115,7 @@ spec:
ports:
- port: 80
targetPort: 8080
nodePort: 39080
nodePort: 32080
---
# 3. REDIS
apiVersion: apps/v1
@@ -85,25 +132,25 @@ spec:
app: redis
spec:
containers:
- name: redis
- name: redis-pod
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",
]
resources:
limits:
cpu: "100m"
memory: "128Mi"
requests:
cpu: "20m"
memory: "64Mi"
command:
[
"redis-server",
"--maxmemory",
"96mb",
"--maxmemory-policy",
"allkeys-lru",
]
---
apiVersion: v1
kind: Service
+1
View File
@@ -7,4 +7,5 @@ public class Url {
public static final String Login = "/login";
public static final String QuickLogin = "/quick_login";
public static final String SmsOtp = "/sms_otp";
public static final String Me = "/me";
}