feat: init customer service
This commit is contained in:
+34
-11
@@ -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 \
|
||||
bash \
|
||||
openjdk21-jdk \
|
||||
maven \
|
||||
build-essential \
|
||||
docker-buildx \
|
||||
git \
|
||||
ca-certificates \
|
||||
pnpm \
|
||||
docker-cli \
|
||||
kubectl \
|
||||
helm
|
||||
docker.io \
|
||||
maven \
|
||||
libz-dev
|
||||
|
||||
# git trust all directories
|
||||
# 5. Cấu hình Git
|
||||
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 PATH="${JBANG_DIR}/bin:${PATH}"
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: "21"
|
||||
java-version: "25"
|
||||
|
||||
- name: Cache Maven packages
|
||||
uses: actions/cache@v4
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
<properties>
|
||||
<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.reporting.outputEncoding
|
||||
>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
@@ -20,7 +20,7 @@ public abstract class UserModel extends BaseEntity {
|
||||
public String phone;
|
||||
|
||||
@Column(nullable = false, length = 1024)
|
||||
public String hashedPassword;
|
||||
protected String hashedPassword;
|
||||
|
||||
@Transactional
|
||||
public void signup(String phone) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.Jwt;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.*;
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
@@ -25,7 +26,7 @@ public class AuthenticationService {
|
||||
|
||||
return Response.status(Response.Status.CREATED)
|
||||
.header(Jwt.userId, newCustomer.id.toString())
|
||||
.header(Jwt.role, "customer")
|
||||
.header(Jwt.role, Role.Customer)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -39,7 +40,7 @@ public class AuthenticationService {
|
||||
|
||||
return Response.status(Response.Status.CREATED)
|
||||
.header(Jwt.userId, newCustomer.id.toString())
|
||||
.header(Jwt.role, "customer")
|
||||
.header(Jwt.role, Role.Customer)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -63,7 +64,7 @@ public class AuthenticationService {
|
||||
|
||||
return Response.accepted()
|
||||
.header(Jwt.userId, customer.id.toString())
|
||||
.header(Jwt.role, "customer")
|
||||
.header(Jwt.role, Role.Customer)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -83,7 +84,7 @@ public class AuthenticationService {
|
||||
|
||||
return Response.accepted()
|
||||
.header(Jwt.userId, customer.id.toString())
|
||||
.header(Jwt.role, "customer")
|
||||
.header(Jwt.role, Role.Customer)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package com.drinkool.services;
|
||||
|
||||
import com.drinkool.Jwt;
|
||||
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;
|
||||
import java.util.UUID;
|
||||
|
||||
@Path("")
|
||||
public class CustomerService {
|
||||
@@ -13,7 +14,7 @@ public class CustomerService {
|
||||
@POST
|
||||
@Path(Url.Me)
|
||||
@Transactional
|
||||
public Response me(@HeaderParam(Jwt.userId) String id) {
|
||||
return Response.ok(CustomerEntity.find("id", id)).build();
|
||||
public Response me(@HeaderParam(Jwt.userId) UUID id) {
|
||||
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.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import com.drinkool.Jwt;
|
||||
import com.drinkool.Role;
|
||||
import com.drinkool.Url;
|
||||
import com.drinkool.dtos.*;
|
||||
import com.drinkool.entities.CustomerEntity;
|
||||
@@ -53,8 +55,8 @@ public class AuthenticationServiceTest {
|
||||
.when()
|
||||
.post(Url.QuickSignup)
|
||||
.then()
|
||||
.header("X-Internal-User-Id", notNullValue())
|
||||
.header("X-Internal-User-Roles", is("user"))
|
||||
.header(Jwt.userId, notNullValue())
|
||||
.header(Jwt.role, is(Role.Customer))
|
||||
.statusCode(201);
|
||||
|
||||
assertEquals(1, CustomerEntity.find("phone", phone).count());
|
||||
@@ -124,6 +126,18 @@ public class AuthenticationServiceTest {
|
||||
SmsOtp input = new SmsOtp();
|
||||
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()
|
||||
.contentType(ContentType.JSON)
|
||||
.body(input)
|
||||
@@ -131,9 +145,6 @@ public class AuthenticationServiceTest {
|
||||
.post(Url.SmsOtp)
|
||||
.then()
|
||||
.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
|
||||
|
||||
@@ -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>
|
||||
<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.reporting.outputEncoding
|
||||
>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
+9
-26
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
@@ -17,14 +17,15 @@
|
||||
<packaging>quarkus</packaging>
|
||||
|
||||
<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>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<maven.compiler.release>25</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding
|
||||
>UTF-8</project.reporting.outputEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<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.4</quarkus.platform.version>
|
||||
<skipITs>true</skipITs>
|
||||
<surefire-plugin.version>3.5.4</surefire-plugin.version>
|
||||
@@ -101,8 +102,7 @@
|
||||
<configuration>
|
||||
<argLine>@{argLine}</argLine>
|
||||
<systemPropertyVariables>
|
||||
<java.util.logging.manager
|
||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
@@ -123,28 +123,11 @@
|
||||
<systemPropertyVariables>
|
||||
<native.image.path>
|
||||
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
|
||||
<java.util.logging.manager
|
||||
>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
|
||||
<maven.home>${maven.home}</maven.home>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<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.builder=docker
|
||||
quarkus.container-image.additional-tags=latest
|
||||
|
||||
# Build
|
||||
quarkus.native.container-build=false
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
|
||||
<artifactId>lib</artifactId>
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</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>
|
||||
<packaging>pom</packaging>
|
||||
<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.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||
<quarkus.platform.version>3.32.3</quarkus.platform.version>
|
||||
|
||||
Reference in New Issue
Block a user