feat: init customer service
This commit is contained in:
+35
-12
@@ -1,21 +1,44 @@
|
|||||||
FROM alpine:3.22
|
FROM ubuntu:26.04
|
||||||
|
|
||||||
RUN apk update && apk add --no-cache \
|
# Tránh các câu hỏi tương tác trong quá trình cài đặt
|
||||||
|
ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y ca-certificates && apt-get clean
|
||||||
|
|
||||||
|
RUN sed -i 's|http://archive.ubuntu.com|https://apt.demonkernel.io.vn|g' /etc/apt/sources.list.d/ubuntu.sources && \
|
||||||
|
sed -i 's|http://security.ubuntu.com|https://apt.demonkernel.io.vn|g' /etc/apt/sources.list.d/ubuntu.sources
|
||||||
|
|
||||||
|
# 1. Cài đặt các công cụ cơ bản
|
||||||
|
RUN apt-get update --fix-missing && apt-get install --no-install-recommends --no-install-suggests -y \
|
||||||
curl \
|
curl \
|
||||||
bash \
|
bash \
|
||||||
openjdk21-jdk \
|
build-essential \
|
||||||
maven \
|
docker-buildx \
|
||||||
git \
|
git \
|
||||||
ca-certificates \
|
docker.io \
|
||||||
pnpm \
|
maven \
|
||||||
docker-cli \
|
libz-dev
|
||||||
kubectl \
|
|
||||||
helm
|
# 5. Cấu hình Git
|
||||||
|
|
||||||
# git trust all directories
|
|
||||||
RUN git config --global --add safe.directory '*'
|
RUN git config --global --add safe.directory '*'
|
||||||
|
|
||||||
# Install quarkus
|
# 2. Cài đặt Node.js & PNPM (thay thế cho apk pnpm)
|
||||||
|
RUN curl -fsSL https://get.pnpm.io/install.sh | bash -
|
||||||
|
|
||||||
|
# 3. Cài đặt Kubectl
|
||||||
|
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
|
||||||
|
&& install -m 0755 kubectl /usr/local/bin/kubectl
|
||||||
|
|
||||||
|
# 4. Cài đặt Mandrel 25
|
||||||
|
# Lưu ý: Dùng bản linux-amd64 (glibc) tiêu chuẩn cho Ubuntu
|
||||||
|
ENV JAVA_HOME=/usr/lib/jvm/mandrel
|
||||||
|
ENV GRAALVM_HOME=/usr/lib/jvm/mandrel
|
||||||
|
ENV PATH="${JAVA_HOME}/bin:${PATH}"
|
||||||
|
|
||||||
|
RUN mkdir -p ${JAVA_HOME} && \
|
||||||
|
curl -L https://github.com/graalvm/mandrel/releases/download/mandrel-25.0.2.0-Final/mandrel-java25-linux-amd64-25.0.2.0-Final.tar.gz | tar -xz -C ${JAVA_HOME} --strip-components=1
|
||||||
|
|
||||||
|
# 6. Cài đặt JBang & Quarkus CLI
|
||||||
ENV JBANG_DIR="/root/.jbang"
|
ENV JBANG_DIR="/root/.jbang"
|
||||||
ENV PATH="${JBANG_DIR}/bin:${PATH}"
|
ENV PATH="${JBANG_DIR}/bin:${PATH}"
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ jobs:
|
|||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: "temurin"
|
distribution: "temurin"
|
||||||
java-version: "21"
|
java-version: "25"
|
||||||
|
|
||||||
- name: Cache Maven packages
|
- name: Cache Maven packages
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
||||||
<maven.compiler.release>21</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>
|
||||||
<project.reporting.outputEncoding
|
<project.reporting.outputEncoding
|
||||||
>UTF-8</project.reporting.outputEncoding>
|
>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public abstract class UserModel extends BaseEntity {
|
|||||||
public String phone;
|
public String phone;
|
||||||
|
|
||||||
@Column(nullable = false, length = 1024)
|
@Column(nullable = false, length = 1024)
|
||||||
public String hashedPassword;
|
protected String hashedPassword;
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void signup(String phone) {
|
public void signup(String phone) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.drinkool.services;
|
package com.drinkool.services;
|
||||||
|
|
||||||
import com.drinkool.Jwt;
|
import com.drinkool.Jwt;
|
||||||
|
import com.drinkool.Role;
|
||||||
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;
|
||||||
@@ -25,7 +26,7 @@ public class AuthenticationService {
|
|||||||
|
|
||||||
return Response.status(Response.Status.CREATED)
|
return Response.status(Response.Status.CREATED)
|
||||||
.header(Jwt.userId, newCustomer.id.toString())
|
.header(Jwt.userId, newCustomer.id.toString())
|
||||||
.header(Jwt.role, "customer")
|
.header(Jwt.role, Role.Customer)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ public class AuthenticationService {
|
|||||||
|
|
||||||
return Response.status(Response.Status.CREATED)
|
return Response.status(Response.Status.CREATED)
|
||||||
.header(Jwt.userId, newCustomer.id.toString())
|
.header(Jwt.userId, newCustomer.id.toString())
|
||||||
.header(Jwt.role, "customer")
|
.header(Jwt.role, Role.Customer)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +64,7 @@ public class AuthenticationService {
|
|||||||
|
|
||||||
return Response.accepted()
|
return Response.accepted()
|
||||||
.header(Jwt.userId, customer.id.toString())
|
.header(Jwt.userId, customer.id.toString())
|
||||||
.header(Jwt.role, "customer")
|
.header(Jwt.role, Role.Customer)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +84,7 @@ public class AuthenticationService {
|
|||||||
|
|
||||||
return Response.accepted()
|
return Response.accepted()
|
||||||
.header(Jwt.userId, customer.id.toString())
|
.header(Jwt.userId, customer.id.toString())
|
||||||
.header(Jwt.role, "customer")
|
.header(Jwt.role, Role.Customer)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package com.drinkool.services;
|
package com.drinkool.services;
|
||||||
|
|
||||||
|
import com.drinkool.Jwt;
|
||||||
import com.drinkool.Url;
|
import com.drinkool.Url;
|
||||||
import com.drinkool.entities.CustomerEntity;
|
import com.drinkool.entities.CustomerEntity;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
import jakarta.ws.rs.core.Response;
|
import jakarta.ws.rs.core.Response;
|
||||||
import com.drinkool.Jwt;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Path("")
|
@Path("")
|
||||||
public class CustomerService {
|
public class CustomerService {
|
||||||
@@ -13,7 +14,7 @@ public class CustomerService {
|
|||||||
@POST
|
@POST
|
||||||
@Path(Url.Me)
|
@Path(Url.Me)
|
||||||
@Transactional
|
@Transactional
|
||||||
public Response me(@HeaderParam(Jwt.userId) String id) {
|
public Response me(@HeaderParam(Jwt.userId) UUID id) {
|
||||||
return Response.ok(CustomerEntity.find("id", id)).build();
|
return Response.ok(CustomerEntity.find("id", id).firstResult()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ 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.Jwt;
|
||||||
|
import com.drinkool.Role;
|
||||||
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;
|
||||||
@@ -53,8 +55,8 @@ public class AuthenticationServiceTest {
|
|||||||
.when()
|
.when()
|
||||||
.post(Url.QuickSignup)
|
.post(Url.QuickSignup)
|
||||||
.then()
|
.then()
|
||||||
.header("X-Internal-User-Id", notNullValue())
|
.header(Jwt.userId, notNullValue())
|
||||||
.header("X-Internal-User-Roles", is("user"))
|
.header(Jwt.role, is(Role.Customer))
|
||||||
.statusCode(201);
|
.statusCode(201);
|
||||||
|
|
||||||
assertEquals(1, CustomerEntity.find("phone", phone).count());
|
assertEquals(1, CustomerEntity.find("phone", phone).count());
|
||||||
@@ -124,6 +126,18 @@ public class AuthenticationServiceTest {
|
|||||||
SmsOtp input = new SmsOtp();
|
SmsOtp input = new SmsOtp();
|
||||||
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)
|
||||||
@@ -131,9 +145,6 @@ public class AuthenticationServiceTest {
|
|||||||
.post(Url.SmsOtp)
|
.post(Url.SmsOtp)
|
||||||
.then()
|
.then()
|
||||||
.statusCode(202);
|
.statusCode(202);
|
||||||
|
|
||||||
// Lưu ý: Vì không dùng Mock, code sẽ chạy qua OtpService thật.
|
|
||||||
// Nếu OtpService lưu vào DB, bạn có thể bổ sung Assert tại đây để check OtpEntity.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.drinkool.services;
|
||||||
|
|
||||||
|
import static io.restassured.RestAssured.*;
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
|
||||||
|
import com.drinkool.Jwt;
|
||||||
|
import com.drinkool.Url;
|
||||||
|
import com.drinkool.dtos.QuickSignup;
|
||||||
|
|
||||||
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
|
import io.restassured.http.ContentType;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
@QuarkusTest
|
||||||
|
public class CustomberServiceTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMeEndpointWithHeader() {
|
||||||
|
String phone = AuthenticationServiceTest.generateRandomPhone();
|
||||||
|
QuickSignup input = new QuickSignup();
|
||||||
|
input.phone = phone;
|
||||||
|
|
||||||
|
String testUserId = given()
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.body(input)
|
||||||
|
.when()
|
||||||
|
.post(Url.QuickSignup)
|
||||||
|
.then()
|
||||||
|
.extract()
|
||||||
|
.header(Jwt.userId);
|
||||||
|
|
||||||
|
given()
|
||||||
|
.header(Jwt.userId, testUserId)
|
||||||
|
.contentType(ContentType.JSON)
|
||||||
|
.when()
|
||||||
|
.post(Url.Me)
|
||||||
|
.then()
|
||||||
|
.statusCode(200)
|
||||||
|
.body("id", is(testUserId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMeEndpointWithoutHeader() {
|
||||||
|
given()
|
||||||
|
.when()
|
||||||
|
.post(Url.Me)
|
||||||
|
.then()
|
||||||
|
// Tùy vào logic xử lý của bạn, có thể trả về 200 kèm body null hoặc 400
|
||||||
|
.statusCode(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
<compiler-plugin.version>3.15.0</compiler-plugin.version>
|
||||||
<maven.compiler.release>21</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>
|
||||||
<project.reporting.outputEncoding
|
<project.reporting.outputEncoding
|
||||||
>UTF-8</project.reporting.outputEncoding>
|
>UTF-8</project.reporting.outputEncoding>
|
||||||
|
|||||||
+13
-30
@@ -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>
|
||||||
|
|
||||||
@@ -17,14 +17,15 @@
|
|||||||
<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>21</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>
|
||||||
<project.reporting.outputEncoding
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||||
<quarkus.platform.group-id
|
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||||
>io.quarkus.platform</quarkus.platform.group-id>
|
|
||||||
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
<quarkus.platform.version>3.32.4</quarkus.platform.version>
|
||||||
<skipITs>true</skipITs>
|
<skipITs>true</skipITs>
|
||||||
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
||||||
@@ -101,8 +102,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<argLine>@{argLine}</argLine>
|
<argLine>@{argLine}</argLine>
|
||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<java.util.logging.manager
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
|
||||||
<maven.home>${maven.home}</maven.home>
|
<maven.home>${maven.home}</maven.home>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
@@ -123,28 +123,11 @@
|
|||||||
<systemPropertyVariables>
|
<systemPropertyVariables>
|
||||||
<native.image.path>
|
<native.image.path>
|
||||||
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||||
<java.util.logging.manager
|
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
|
||||||
<maven.home>${maven.home}</maven.home>
|
<maven.home>${maven.home}</maven.home>
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
</project>
|
||||||
<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>
|
|
||||||
@@ -6,3 +6,6 @@ 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
|
quarkus.container-image.additional-tags=latest
|
||||||
|
|
||||||
|
# Build
|
||||||
|
quarkus.native.container-build=false
|
||||||
+2
-2
@@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
<artifactId>lib</artifactId>
|
<artifactId>lib</artifactId>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
<maven.compiler.target>21</maven.compiler.target>
|
<maven.compiler.target>25</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.drinkool;
|
||||||
|
|
||||||
|
public class Jwt {
|
||||||
|
public static final String headerId = "X-Internal-";
|
||||||
|
public static final String userId = headerId + "UserId";
|
||||||
|
public static final String role = headerId + "Role";
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.drinkool;
|
||||||
|
|
||||||
|
public class Role {
|
||||||
|
public static final String Customer = "customer";
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
<version>1.1.0-dev.1</version>
|
<version>1.1.0-dev.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>21</maven.compiler.source>
|
<maven.compiler.source>25</maven.compiler.source>
|
||||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||||
<quarkus.platform.version>3.32.3</quarkus.platform.version>
|
<quarkus.platform.version>3.32.3</quarkus.platform.version>
|
||||||
|
|||||||
Reference in New Issue
Block a user