fix: add logout, quick signup and quick login (#29)
Release package / release (push) Successful in 12m31s

Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Reviewed-on: #29
This commit was merged in pull request #29.
This commit is contained in:
2026-04-19 09:16:26 +00:00
parent d94117576b
commit 4811934b84
23 changed files with 167 additions and 26 deletions
+8
View File
@@ -20,11 +20,19 @@ RUN apt-get update && apt-get install -y ca-certificates && apt-get clean
RUN apt-get update --fix-missing && apt-get install --no-install-recommends --no-install-suggests -y \ RUN apt-get update --fix-missing && apt-get install --no-install-recommends --no-install-suggests -y \
git \ git \
docker-buildx \ docker-buildx \
locales \
docker-cli \ docker-cli \
docker.io \ docker.io \
kubectl \ kubectl \
openjdk-25-jdk-headless \ openjdk-25-jdk-headless \
redis-server \
maven maven
RUN jbang trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/ RUN jbang trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/
RUN jbang app install --fresh --force quarkus@quarkusio RUN jbang app install --fresh --force quarkus@quarkusio
# Fix Locale
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
+1
View File
@@ -32,6 +32,7 @@
"QUARKUS_DEBUG_HOST": "0.0.0.0", "QUARKUS_DEBUG_HOST": "0.0.0.0",
"http_proxy": "http://host.docker.internal:3142" "http_proxy": "http://host.docker.internal:3142"
}, },
"postStartCommand": "redis-server --daemonize yes",
"postCreateCommand": "git config --global --add safe.directory '*'", "postCreateCommand": "git config --global --add safe.directory '*'",
"forwardPorts": [5005, 8080] "forwardPorts": [5005, 8080]
} }
+1 -1
View File
@@ -49,7 +49,7 @@ jobs:
- name: Build and Test all modules - name: Build and Test all modules
run: | run: |
./mvnw -B install \ ./mvnw -B install \
-Dquarkus.container-image.push=false -Dquarkus.container-image.push=false -Pnative
- name: Publish Test Report - name: Publish Test Report
uses: dorny/test-reporter@v3 uses: dorny/test-reporter@v3
+1
View File
@@ -24,6 +24,7 @@ nb-configuration.xml
# Visual Studio Code # Visual Studio Code
.vscode .vscode
.factorypath .factorypath
*.rdb
# OSX # OSX
.DS_Store .DS_Store
+1 -1
View File
@@ -13,7 +13,7 @@ plugins:
./mvnw versions:set -DnewVersion=${nextRelease.version} && ./mvnw versions:set -DnewVersion=${nextRelease.version} &&
sed -i "/-service:/ s|:[^:]*$|:${nextRelease.version}|" k8s.yaml && sed -i "/-service:/ s|:[^:]*$|:${nextRelease.version}|" k8s.yaml &&
if [ "${branch.name}" = "main" ]; then if [ "${branch.name}" = "main" ]; then
./mvnw package -B -Dquarkus.container-image.tag=${nextRelease.version} -DskipTests ./mvnw package -B -Pnative -Dquarkus.container-image.tag=${nextRelease.version} -DskipTests
fi fi
- - "@saithodev/semantic-release-gitea" - - "@saithodev/semantic-release-gitea"
- giteaUrl: "https://git.demonkernel.io.vn/" - giteaUrl: "https://git.demonkernel.io.vn/"
+17 -3
View File
@@ -17,9 +17,7 @@
<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>25</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>
@@ -164,4 +162,20 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </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> </project>
@@ -0,0 +1,16 @@
package com.drinkool.mapper;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.BadRequestException;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;
public class ExceptionHandlersMapper {
@ServerExceptionMapper
public Response mapBadRequestException(BadRequestException x) {
return Response.status(Response.Status.BAD_REQUEST)
.entity(x.getMessage())
.type("text/plain")
.build();
}
}
@@ -42,9 +42,6 @@ public class CustomerService extends BaseService<CustomerEntity> {
newCustomer.signup(input.phone); newCustomer.signup(input.phone);
return Response.status(Response.Status.CREATED) return Response.status(Response.Status.CREATED)
.header(InternalValue.userId, newCustomer.id.toString())
.header(InternalValue.role, Role.Customer)
.entity(newCustomer)
.build(); .build();
} }
@@ -15,14 +15,16 @@ public class BaseServiceTest {
@Test @Test
public void testMeEndpointWithHeader() { public void testMeEndpointWithHeader() {
String phone = Utils.generateRandomPhone(); String phone = Utils.generateRandomPhone();
QuickSignup input = new QuickSignup(); Signup input = new Signup();
input.name = "Test User";
input.phone = phone; input.phone = phone;
input.password = "password123";
String testUserId = given() String testUserId = given()
.contentType(ContentType.JSON) .contentType(ContentType.JSON)
.body(input) .body(input)
.when() .when()
.post(Role.Customer + Url.QuickSignup) .post(Role.Customer + Url.Signup)
.then() .then()
.extract() .extract()
.header(InternalValue.userId); .header(InternalValue.userId);
@@ -50,8 +50,6 @@ public class CustomerServiceTest {
.when() .when()
.post(Role.Customer + Url.QuickSignup) .post(Role.Customer + Url.QuickSignup)
.then() .then()
.header(InternalValue.userId, notNullValue())
.header(InternalValue.role, is(Role.Customer))
.statusCode(201); .statusCode(201);
assertEquals(1, CustomerEntity.find("phone", phone).count()); assertEquals(1, CustomerEntity.find("phone", phone).count());
-5
View File
@@ -1,5 +0,0 @@
mvn package -DskipTests -Dquarkus.container-image.push=false \
-Dquarkus.container-image.registry=git.demonkernel.io.vn \
-Dquarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG \
-Dquarkus.rest-client.logging.scope=full \
-Dquarkus.rest-client.logging.body-limit=1024
+16 -3
View File
@@ -17,9 +17,6 @@
<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>25</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>
@@ -150,4 +147,20 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </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> </project>
+15 -3
View File
@@ -17,9 +17,6 @@
<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>25</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>
@@ -142,4 +139,19 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </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> </project>
@@ -0,0 +1,26 @@
package com.drinkool.controller;
import com.drinkool.InternalValue;
import com.drinkool.Url;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.NewCookie;
import org.jboss.resteasy.reactive.RestResponse;
public abstract class BaseController {
@POST
@Path(Url.Logout)
public RestResponse<Void> logout() {
NewCookie cookie = new NewCookie.Builder(InternalValue.cookieName)
.secure(true)
.maxAge(0)
.path("/")
.httpOnly(true)
.build();
return RestResponse.ResponseBuilder.<Void>noContent()
.cookie(cookie)
.build();
}
}
@@ -11,7 +11,7 @@ import java.util.*;
import org.eclipse.microprofile.rest.client.inject.RestClient; import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/api/" + Role.Customer) @Path("/api/" + Role.Customer)
public class CustomerController { public class CustomerController extends BaseController {
@Inject @Inject
@RestClient @RestClient
@@ -29,6 +29,18 @@ public class CustomerController {
return accountService.login(input); return accountService.login(input);
} }
@POST
@Path(Url.QuickSignup)
public Uni<Response> proxyQuickSignup(QuickSignup input) {
return accountService.quickSignup(input);
}
@POST()
@Path(Url.QuickLogin)
public Uni<Response> proxyQuickLogin(QuickLogin input) {
return accountService.quickLogin(input);
}
@GET @GET
public Uni<Response> me(@HeaderParam(InternalValue.userId) UUID id) { public Uni<Response> me(@HeaderParam(InternalValue.userId) UUID id) {
return accountService.me(id); return accountService.me(id);
@@ -25,7 +25,7 @@ public interface CustomerService {
@POST @POST
@Path(Url.QuickLogin) @Path(Url.QuickLogin)
Uni<Response> quickLogin(QuickSignup input); Uni<Response> quickLogin(QuickLogin input);
@GET @GET
@Path(Url.Me) @Path(Url.Me)
@@ -0,0 +1,24 @@
package com.drinkool.controller;
import static io.restassured.RestAssured.*;
import static org.hamcrest.CoreMatchers.*;
import com.drinkool.*;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@QuarkusTest
public class BaseControllerTest {
@Test
public void testLogoutShouldClearCookie() {
given()
.when()
.post("/api/" + Role.Customer + Url.Logout)
.then()
.statusCode(204)
.header("Set-Cookie", containsString(InternalValue.cookieName))
.header("Set-Cookie", containsString("Max-Age=0"))
.header("Set-Cookie", containsString("HttpOnly"));
}
}
@@ -3,3 +3,6 @@ quarkus.http.host=0.0.0.0
# JWT # JWT
gateway.jwt.secret=1uZk07Hqu1316z9YqrcSGPTTJDhMWU1ZhFSLBrDQvmU= gateway.jwt.secret=1uZk07Hqu1316z9YqrcSGPTTJDhMWU1ZhFSLBrDQvmU=
# App configuration
quarkus.rest-client.account.url=http://account-service:8080
+1
View File
@@ -8,4 +8,5 @@ public class Url {
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"; public static final String Me = "/me";
public static final String Logout = "/logout";
} }
+3
View File
@@ -0,0 +1,3 @@
mvn clean package -DskipTests -Pnative \
-Dquarkus.container-image.push=false \
-Dquarkus.container-image.registry=git.demonkernel.io.vn
+3
View File
@@ -0,0 +1,3 @@
mvn clean install -DskipTests \
-Dquarkus.container-image.build=false \
-Dquarkus.container-image.push=false
+11
View File
@@ -0,0 +1,11 @@
#!/bin/bash
CURRENT_DIR=$(pwd)
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
cd "$SCRIPT_DIR/.."
kubectl delete all --all -n drinkool-backend
kubectl apply -f k8s.yaml -n drinkool-backend
cd "$CURRENT_DIR"
+1
View File
@@ -0,0 +1 @@
mvn clean package -Dquarkus.container-image.push=false -Dquarkus.container-image.build=false