feat(eatery-service): init with tests (#3)
Release package / release (push) Has been cancelled
Java CI with Maven / build-and-test (push) Has been cancelled

Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com>
Co-authored-by: gitea-actions <actions-user@noreply.git.demonkernel.io.vn>
Co-authored-by: TranHuuDanh <tranhuudanh@demonkernel.io.vn>
Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2026-03-25 02:08:19 +00:00
parent a2b9de91f5
commit cda46248df
41 changed files with 1401 additions and 97 deletions
@@ -0,0 +1,76 @@
package com.drinkool.services;
import com.drinkool.dtos.*;
import com.drinkool.entities.CustomerEntity;
import jakarta.inject.Inject;
import jakarta.transaction.Transactional;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.*;
@Path("/api")
public class AuthenticationService {
@Inject
OtpService otpService;
@POST
@Path("/signup")
@Transactional
public Response signup(Signup input) {
CustomerEntity newCustomer = new CustomerEntity();
newCustomer.signup(input.name, input.phone, input.password);
return Response.status(Response.Status.CREATED).build();
}
@POST
@Path("/quickSignup")
@Transactional
public Response quickSignup(QuickSignup input) {
CustomerEntity newCustomer = new CustomerEntity();
newCustomer.signup(input.phone);
return Response.status(Response.Status.CREATED).build();
}
@POST
@Path("/login")
public Response login(Login input) {
CustomerEntity customer = CustomerEntity.find(
"phone",
input.phone
).firstResult();
if (customer == null) throw new BadRequestException("InvalidPhoneNumber");
if (!customer.login(input.password)) throw new BadRequestException(
"InvalidPassword"
);
return Response.accepted().build();
}
@POST
@Path("/sms_otp")
public Response smsOtp(SmsOtp input) {
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);
return Response.accepted().build();
}
@POST
@Path("/quicklogin")
public Response quickLogin(QuickLogin input) {
if (otpService.verifyOtp(input.phone, input.otp)) {
return Response.accepted().build();
}
return Response.status(Response.Status.UNAUTHORIZED)
.entity("InvalidOTP")
.build();
}
}