Compare commits

..

14 Commits

Author SHA1 Message Date
TakahashiNg 7a7beb16d0 chore: update 2026-04-20 07:21:10 +00:00
TakahashiNg f6218a933c chore: update 2026-04-20 02:39:13 +00:00
TakahashiNg 79a451cceb chore(k8s): update 2026-04-20 01:34:47 +00:00
TakahashiNg 6b600bda40 chore(k8s): update 2026-04-20 01:31:37 +00:00
TakahashiNg 687cb48116 chore(account-service): update configuration 2026-04-20 01:28:41 +00:00
TakahashiNg e381397491 fix: add sms provider 2026-04-19 15:30:20 +00:00
TakahashiNg 5274b408d4 fix: add sms otp protocol
Java CI with Maven / build-and-test (pull_request) Successful in 13m49s
2026-04-19 10:45:31 +00:00
gitea-actions 95ca126670 chore: release [ci skip] 2026-04-19 09:28:51 +00:00
TakahashiNguyen 4811934b84 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
2026-04-19 09:16:26 +00:00
gitea-actions d94117576b chore: release [ci skip] 2026-04-19 02:20:48 +00:00
TakahashiNguyen 24df313c0f fix: response exceptions from sub services (#28)
Release package / release (push) Successful in 13m41s
Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Reviewed-on: #28
2026-04-19 02:06:19 +00:00
gitea-actions 74acb68bbf chore: release [ci skip] 2026-04-18 10:38:36 +00:00
TakahashiNguyen 96171d3ec2 fix: missing required parameters (#27)
Release package / release (push) Successful in 16m8s
Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Reviewed-on: #27
2026-04-18 10:22:18 +00:00
gitea-actions bb8a9c5691 chore: release [ci skip] 2026-04-17 12:12:43 +00:00
36 changed files with 509 additions and 63 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 \
git \
docker-buildx \
locales \
docker-cli \
docker.io \
kubectl \
openjdk-25-jdk-headless \
redis-server \
maven
RUN jbang trust add https://repo1.maven.org/maven2/io/quarkus/quarkus-cli/
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",
"http_proxy": "http://host.docker.internal:3142"
},
"postStartCommand": "redis-server --daemonize yes",
"postCreateCommand": "git config --global --add safe.directory '*'",
"forwardPorts": [5005, 8080]
}
+1 -1
View File
@@ -49,7 +49,7 @@ jobs:
- name: Build and Test all modules
run: |
./mvnw -B install \
-Dquarkus.container-image.push=false
-Dquarkus.container-image.push=false -Pnative
- name: Publish Test Report
uses: dorny/test-reporter@v3
+1
View File
@@ -24,6 +24,7 @@ nb-configuration.xml
# Visual Studio Code
.vscode
.factorypath
*.rdb
# OSX
.DS_Store
+2
View File
@@ -5,5 +5,7 @@
"tabWidth": 2,
"trailingComma": "all",
"useTabs": true,
"xmlSortAttributesByKey": true,
"xmlQuoteAttributes": "double",
"plugins": ["prettier-plugin-java", "@prettier/plugin-xml"]
}
+1 -1
View File
@@ -13,7 +13,7 @@ plugins:
./mvnw versions:set -DnewVersion=${nextRelease.version} &&
sed -i "/-service:/ s|:[^:]*$|:${nextRelease.version}|" k8s.yaml &&
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
- - "@saithodev/semantic-release-gitea"
- giteaUrl: "https://git.demonkernel.io.vn/"
+28
View File
@@ -1,3 +1,31 @@
## [1.5.7](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.6...v1.5.7) (2026-04-19)
### Bug Fixes
* add logout, quick signup and quick login ([#29](https://git.demonkernel.io.vn/FoodSurf/backend/issues/29)) ([4811934](https://git.demonkernel.io.vn/FoodSurf/backend/commit/4811934b84f7684410297a8f7d1f7ff14611a25a))
## [1.5.6](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.5...v1.5.6) (2026-04-19)
### Bug Fixes
* response exceptions from sub services ([#28](https://git.demonkernel.io.vn/FoodSurf/backend/issues/28)) ([24df313](https://git.demonkernel.io.vn/FoodSurf/backend/commit/24df313c0f7effeacd89e537896d7ac9452ec526))
## [1.5.5](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.4...v1.5.5) (2026-04-18)
### Bug Fixes
* missing required parameters ([#27](https://git.demonkernel.io.vn/FoodSurf/backend/issues/27)) ([96171d3](https://git.demonkernel.io.vn/FoodSurf/backend/commit/96171d3ec254f35d4cf8d11ccab53f8922c94412))
## [1.5.4](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.3...v1.5.4) (2026-04-17)
### Bug Fixes
* connect gateway to customer service ([#26](https://git.demonkernel.io.vn/FoodSurf/backend/issues/26)) ([e07ee31](https://git.demonkernel.io.vn/FoodSurf/backend/commit/e07ee318a7985d79689f3dc32fea97bb1051e22a))
## [1.5.3](https://git.demonkernel.io.vn/FoodSurf/backend/compare/v1.5.2...v1.5.3) (2026-04-17)
+23 -4
View File
@@ -9,7 +9,7 @@
<parent>
<groupId>com.drinkool</groupId>
<artifactId>drinkool</artifactId>
<version>1.5.3</version>
<version>1.5.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -17,9 +17,7 @@
<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>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -51,6 +49,11 @@
<artifactId>lib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-mockito</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
@@ -164,4 +167,20 @@
</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>
@@ -0,0 +1,16 @@
package com.drinkool.mapper;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.core.Response;
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();
}
}
@@ -22,10 +22,7 @@ public class AccountService {
.entity("InvalidPhoneNumber")
.build();
String otp = otpService.generateAndSaveOtp(input.phone);
// Ở đây bạn sẽ gọi Kafka để gửi SMS thực tế
System.out.println("OTP cho " + input.phone + " là: " + otp);
otpService.generateAndSaveOtp(input.phone);
return Response.accepted().build();
}
@@ -41,11 +41,7 @@ public class CustomerService extends BaseService<CustomerEntity> {
newCustomer.signup(input.phone);
return Response.status(Response.Status.CREATED)
.header(InternalValue.userId, newCustomer.id.toString())
.header(InternalValue.role, Role.Customer)
.entity(newCustomer)
.build();
return Response.status(Response.Status.CREATED).build();
}
@POST
@@ -1,9 +1,11 @@
package com.drinkool.services;
import com.drinkool.utils.SmsApi;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.redis.datasource.value.ValueCommands;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.Random;
@ApplicationScoped
@@ -11,18 +13,29 @@ public class OtpService {
private final ValueCommands<String, String> countCommands;
@Inject
SmsApi smsApi;
@Inject
public OtpService(RedisDataSource ds) {
this.countCommands = ds.value(String.class);
}
public String generateAndSaveOtp(String phone) {
public void generateAndSaveOtp(String phone) {
String otp = String.format("%06d", new Random().nextInt(1000000));
String key = "otp:" + phone;
countCommands.setex(key, 300, otp);
return otp;
String smsStatus = null;
try {
smsStatus = smsApi.sendSMS(phone, "Mã OTP drinkool của bạn là " + otp);
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("SMS API response: " + smsStatus);
}
}
public boolean verifyOtp(String phone, String inputOtp) {
@@ -0,0 +1,113 @@
package com.drinkool.utils;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.xml.bind.DatatypeConverter;
import java.io.*;
import java.net.*;
import org.eclipse.microprofile.config.inject.ConfigProperty;
@ApplicationScoped
public class SmsApi {
public static final String API_URL = "https://api.speedsms.vn/index.php";
protected String mAccessToken;
protected String mBrandName;
public SmsApi(
@ConfigProperty(name = "sms.api.token") String accessToken
// @ConfigProperty(name = "sms.api.brand") String brandName
) {
this.mAccessToken = accessToken;
this.mBrandName = "";
}
/**
* Get user information
* @param: none
* @return: json string
* */
public String getUserInfo() throws IOException {
URI uri = URI.create(API_URL + "/user/info");
HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
conn.setRequestMethod("GET");
String userCredentials = mAccessToken + ":x";
String basicAuth =
"Basic " +
DatatypeConverter.printBase64Binary(userCredentials.getBytes());
conn.setRequestProperty("Authorization", basicAuth);
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream())
);
String inputLine = "";
StringBuffer buffer = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
buffer.append(inputLine);
}
in.close();
return buffer.toString();
}
/**
* Send SMS
* @param
* @return: json string
* */
public String sendSMS(String to, String content)
throws IOException {
String json =
"{\"to\": [\"" +
to +
"\"], \"content\": \"" +
EncodeNonAsciiCharacters(content) +
"\", \"type\":" +
4 +
", \"brandname\":\"" +
this.mBrandName +
"\"}";
URI uri = URI.create(API_URL + "/sms/send");
HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
conn.setRequestMethod("POST");
String userCredentials = mAccessToken + ":x";
String basicAuth =
"Basic " +
DatatypeConverter.printBase64Binary(userCredentials.getBytes());
conn.setRequestProperty("Authorization", basicAuth);
conn.setRequestProperty("Content-Type", "application/json");
conn.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(json);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(conn.getInputStream())
);
String inputLine = "";
StringBuffer buffer = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
buffer.append(inputLine);
}
in.close();
return buffer.toString();
}
private String EncodeNonAsciiCharacters(String value) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < value.length(); i++) {
char c = value.charAt(i);
int unit = (int) c;
if (unit > 127) {
String hex = String.format("%04x", (int) unit);
String encodedValue = "\\u" + hex;
sb.append(encodedValue);
} else {
sb.append(c);
}
}
return sb.toString();
}
}
@@ -2,7 +2,7 @@
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=postgres
quarkus.datasource.password=password
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/postgres
quarkus.datasource.jdbc.url=jdbc:postgresql://host.docker.internal:5432/postgres
quarkus.hibernate-orm.database.generation=update
@@ -16,7 +16,7 @@ quarkus.container-image.builder=docker
quarkus.container-image.additional-tags=latest
# Redis
quarkus.redis.hosts=redis://localhost:6379
quarkus.redis.hosts=redis://${REDIS_SERVICE_SERVICE_HOST:localhost}:${REDIS_SERVICE_SERVICE_PORT:6379}
# Dependency
@@ -27,4 +27,7 @@ quarkus.index-dependency.lib.artifact-id=lib
quarkus.native.container-build=true
quarkus.native.remote-container-build=true
quarkus.native.additional-build-args=--initialize-at-run-time=com.password4j.AlgorithmFinder,--future-defaults=all
quarkus.native.resources.includes=com/google/i18n/phonenumbers/data/**/*
quarkus.native.resources.includes=com/google/i18n/phonenumbers/data/**/*
# Sms API
sms.api.token=vc6kYQey8nFG7uRe7U4eYB3Iwq2JAiQa
@@ -15,14 +15,16 @@ public class BaseServiceTest {
@Test
public void testMeEndpointWithHeader() {
String phone = Utils.generateRandomPhone();
QuickSignup input = new QuickSignup();
Signup input = new Signup();
input.name = "Test User";
input.phone = phone;
input.password = "password123";
String testUserId = given()
.contentType(ContentType.JSON)
.body(input)
.when()
.post(Role.Customer + Url.QuickSignup)
.post(Role.Customer + Url.Signup)
.then()
.extract()
.header(InternalValue.userId);
@@ -1,16 +1,19 @@
package com.drinkool.services;
import static io.restassured.RestAssured.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import com.drinkool.*;
import com.drinkool.dtos.*;
import com.drinkool.entities.CustomerEntity;
import io.quarkus.test.junit.QuarkusTest;
import com.drinkool.utils.SmsApi;
import io.quarkus.test.junit.*;
import io.restassured.http.ContentType;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import org.junit.jupiter.api.*;
import org.mockito.ArgumentCaptor;
@QuarkusTest
public class CustomerServiceTest {
@@ -18,6 +21,15 @@ public class CustomerServiceTest {
@Inject
OtpService otpService;
SmsApi smsApiMock;
@BeforeEach
public void setup() {
SmsApi mock = mock(SmsApi.class);
QuarkusMock.installMockForType(mock, SmsApi.class);
this.smsApiMock = mock;
}
@Test
void testSignup() {
String phone = Utils.generateRandomPhone();
@@ -50,8 +62,6 @@ public class CustomerServiceTest {
.when()
.post(Role.Customer + Url.QuickSignup)
.then()
.header(InternalValue.userId, notNullValue())
.header(InternalValue.role, is(Role.Customer))
.statusCode(201);
assertEquals(1, CustomerEntity.find("phone", phone).count());
@@ -116,7 +126,7 @@ public class CustomerServiceTest {
}
@Test
public void testQuickLogin_Success() {
public void testQuickLogin_Success() throws IOException {
String phone = Utils.generateRandomPhone();
QuickSignup input = new QuickSignup();
@@ -131,7 +141,18 @@ public class CustomerServiceTest {
QuickLogin payload = new QuickLogin();
payload.phone = phone;
payload.otp = otpService.generateAndSaveOtp(phone);
otpService.generateAndSaveOtp(phone);
ArgumentCaptor<String> contentCaptor = ArgumentCaptor.forClass(
String.class
);
verify(smsApiMock).sendSMS(eq(phone), contentCaptor.capture());
// 4. Trích xuất mã OTP từ nội dung tin nhắn đã bắt được
// Giả sử tin nhắn có định dạng: "... là 123456"
String sentMessage = contentCaptor.getValue();
payload.otp = sentMessage.substring(sentMessage.length() - 6);
given()
.contentType(ContentType.JSON)
@@ -1,11 +1,17 @@
package com.drinkool.services;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import io.quarkus.test.junit.QuarkusTest;
import com.drinkool.utils.SmsApi;
import io.quarkus.redis.datasource.RedisDataSource;
import io.quarkus.test.junit.*;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.Random;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.mockito.ArgumentCaptor;
@QuarkusTest
public class OtpServiceTest {
@@ -13,24 +19,53 @@ public class OtpServiceTest {
@Inject
OtpService otpService;
@Inject
RedisDataSource redisDataSource;
SmsApi smsApiMock;
@BeforeEach
public void setup() {
SmsApi mock = mock(SmsApi.class);
QuarkusMock.installMockForType(mock, SmsApi.class);
this.smsApiMock = mock;
}
// 1. Test case: Tạo và lưu OTP thành công
@Test
public void testGenerateAndSaveOtp() {
String phone =
"+8477" + String.format("%07d", new Random().nextInt(10000000));
String otp = otpService.generateAndSaveOtp(phone);
String redisKey = "otp:" + phone;
assertNotNull(otp, "OTP sinh ra không được null");
assertEquals(6, otp.length(), "OTP phải có độ dài đúng 6 ký tự");
assertTrue(otp.matches("\\d{6}"), "OTP chỉ được chứa các chữ số");
otpService.generateAndSaveOtp(phone);
String otpFromRedis = redisDataSource.value(String.class).get(redisKey);
assertNotNull(otpFromRedis, "Mã OTP phải tồn tại trong Redis");
assertEquals(6, otpFromRedis.length(), "Mã OTP phải có 6 chữ số");
long ttl = redisDataSource.key().ttl(redisKey);
assertTrue(ttl > 0 && ttl <= 300, "TTL của OTP phải hợp lệ");
}
// 2. Test case: Xác thực OTP thành công
@Test
public void testVerifyOtpSuccess() {
public void testVerifyOtpSuccess() throws IOException {
String phone =
"+8477" + String.format("%07d", new Random().nextInt(10000000));
String generatedOtp = otpService.generateAndSaveOtp(phone);
otpService.generateAndSaveOtp(phone);
ArgumentCaptor<String> contentCaptor = ArgumentCaptor.forClass(
String.class
);
verify(smsApiMock).sendSMS(eq(phone), contentCaptor.capture());
// 4. Trích xuất mã OTP từ nội dung tin nhắn đã bắt được
// Giả sử tin nhắn có định dạng: "... là 123456"
String sentMessage = contentCaptor.getValue();
String generatedOtp = sentMessage.substring(sentMessage.length() - 6);
// Xác thực với OTP vừa tạo ra
boolean verifyResult = otpService.verifyOtp(phone, generatedOtp);
@@ -68,10 +103,21 @@ public class OtpServiceTest {
// 5. Test case: Đảm bảo OTP chỉ được sử dụng 1 lần (đã bị xóa sau khi verify thành công bằng lệnh getdel)
@Test
public void testVerifyOtpConsumedAfterSuccess() {
public void testVerifyOtpConsumedAfterSuccess() throws IOException {
String phone =
"+8477" + String.format("%07d", new Random().nextInt(10000000));
String generatedOtp = otpService.generateAndSaveOtp(phone);
otpService.generateAndSaveOtp(phone);
ArgumentCaptor<String> contentCaptor = ArgumentCaptor.forClass(
String.class
);
verify(smsApiMock).sendSMS(eq(phone), contentCaptor.capture());
// 4. Trích xuất mã OTP từ nội dung tin nhắn đã bắt được
// Giả sử tin nhắn có định dạng: "... là 123456"
String sentMessage = contentCaptor.getValue();
String generatedOtp = sentMessage.substring(sentMessage.length() - 6);
// Lần 1: Xác thực thành công
assertTrue(otpService.verifyOtp(phone, generatedOtp));
@@ -8,3 +8,6 @@ quarkus.http.host=0.0.0.0
## Orm
%test.quarkus.hibernate-orm.database.generation=drop-and-create
# Sms API
sms.api.token=your_sms_api_token_here
+17 -4
View File
@@ -9,7 +9,7 @@
<parent>
<groupId>com.drinkool</groupId>
<artifactId>drinkool</artifactId>
<version>1.5.3</version>
<version>1.5.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -17,9 +17,6 @@
<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>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -150,4 +147,20 @@
</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>
+16 -4
View File
@@ -9,7 +9,7 @@
<parent>
<groupId>com.drinkool</groupId>
<artifactId>drinkool</artifactId>
<version>1.5.3</version>
<version>1.5.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
@@ -17,9 +17,6 @@
<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>25</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -142,4 +139,19 @@
</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>
@@ -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();
}
}
@@ -1,17 +1,17 @@
package com.drinkool.controller;
import com.drinkool.Role;
import com.drinkool.Url;
import com.drinkool.*;
import com.drinkool.dtos.*;
import com.drinkool.services.CustomerService;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;
import java.util.*;
import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/api/" + Role.Customer)
public class CustomerController {
public class CustomerController extends BaseController {
@Inject
@RestClient
@@ -29,8 +29,20 @@ public class CustomerController {
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
public Uni<Response> me() {
return accountService.me();
public Uni<Response> me(@HeaderParam(InternalValue.userId) UUID id) {
return accountService.me(id);
}
}
@@ -0,0 +1,25 @@
package com.drinkool.controller;
import com.drinkool.Url;
import com.drinkool.dtos.SmsOtp;
import com.drinkool.services.BaseService;
import io.smallrye.mutiny.Uni;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RestClient;
@Path("/api")
public class IndexController {
@Inject
@RestClient
BaseService baseService;
@POST
@Path(Url.SmsOtp)
public Uni<Response> smsOtp(SmsOtp input) {
return baseService.smsOtp(input);
}
}
@@ -0,0 +1,21 @@
package com.drinkool.mappers;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.Provider;
import org.jboss.resteasy.reactive.ClientWebApplicationException;
@Provider
public class RestClientExceptionMapper
implements ExceptionMapper<ClientWebApplicationException>
{
@Override
public Response toResponse(ClientWebApplicationException exception) {
Response originalResponse = exception.getResponse();
return Response.status(originalResponse.getStatus())
.entity(originalResponse.readEntity(String.class))
.build();
}
}
@@ -0,0 +1,17 @@
package com.drinkool.services;
import com.drinkool.Url;
import com.drinkool.dtos.SmsOtp;
import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient(configKey = "account")
@Path("")
public interface BaseService {
@POST
@Path(Url.SmsOtp)
Uni<Response> smsOtp(SmsOtp input);
}
@@ -1,11 +1,11 @@
package com.drinkool.services;
import com.drinkool.Role;
import com.drinkool.Url;
import com.drinkool.*;
import com.drinkool.dtos.*;
import io.smallrye.mutiny.Uni;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Response;
import java.util.*;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@RegisterRestClient(configKey = "account")
@@ -25,9 +25,9 @@ public interface CustomerService {
@POST
@Path(Url.QuickLogin)
Uni<Response> quickLogin(QuickSignup input);
Uni<Response> quickLogin(QuickLogin input);
@GET
@Path(Url.Me)
Uni<Response> me();
Uni<Response> me(@HeaderParam(InternalValue.userId) UUID id);
}
@@ -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"));
}
}
@@ -2,4 +2,7 @@
quarkus.http.host=0.0.0.0
# JWT
gateway.jwt.secret=1uZk07Hqu1316z9YqrcSGPTTJDhMWU1ZhFSLBrDQvmU=
gateway.jwt.secret=1uZk07Hqu1316z9YqrcSGPTTJDhMWU1ZhFSLBrDQvmU=
# App configuration
quarkus.rest-client.account.url=http://account-service:8080
+9 -4
View File
@@ -15,12 +15,12 @@ spec:
spec:
containers:
- name: account-pod
image: git.demonkernel.io.vn/foodsurf/account-service:1.5.3
image: git.demonkernel.io.vn/foodsurf/account-service:1.5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
env:
- name: QUARKUS_REDIS_HOST
- name: REDIS_SERVICE
value: "redis-service"
- name: QUARKUS_DATASOURCE_PASSWORD
valueFrom:
@@ -37,6 +37,11 @@ spec:
secretKeyRef:
name: postgres-credentials
key: url
- name: SMS_API_TOKEN
valueFrom:
secretKeyRef:
name: sms-api-token
key: value
resources:
requests:
memory: "32Mi"
@@ -73,7 +78,7 @@ spec:
spec:
containers:
- name: eatery-pod
image: git.demonkernel.io.vn/foodsurf/eatery-service:1.5.3
image: git.demonkernel.io.vn/foodsurf/eatery-service:1.5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
@@ -129,7 +134,7 @@ spec:
spec:
containers:
- name: gateway-pod
image: git.demonkernel.io.vn/foodsurf/gateway-service:1.5.3
image: git.demonkernel.io.vn/foodsurf/gateway-service:1.5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
+1 -1
View File
@@ -9,7 +9,7 @@
<parent>
<groupId>com.drinkool</groupId>
<artifactId>drinkool</artifactId>
<version>1.5.3</version>
<version>1.5.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
+1
View File
@@ -8,4 +8,5 @@ public class Url {
public static final String QuickLogin = "/quick_login";
public static final String SmsOtp = "/sms_otp";
public static final String Me = "/me";
public static final String Logout = "/logout";
}
+1 -1
View File
@@ -7,7 +7,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.drinkool</groupId>
<artifactId>drinkool</artifactId>
<version>1.5.3</version>
<version>1.5.7</version>
<packaging>pom</packaging>
<properties>
<maven.compiler.source>25</maven.compiler.source>
+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