5434445a4c
Release package / release (push) Successful in 16m46s
Co-authored-by: TakahashiNg <83152264+TakahashiNguyen@users.noreply.github.com> Reviewed-on: #39
38 lines
956 B
Java
38 lines
956 B
Java
package com.drinkool.services;
|
|
|
|
import com.drinkool.Role;
|
|
import com.drinkool.Url;
|
|
import com.drinkool.dtos.SmsOtp;
|
|
import com.drinkool.entities.ManagerEntity;
|
|
import com.drinkool.models.UserModel;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.ws.rs.*;
|
|
import jakarta.ws.rs.core.Response;
|
|
|
|
@Path("/")
|
|
public class AccountService {
|
|
|
|
@Inject
|
|
OtpService otpService;
|
|
|
|
@POST
|
|
@Path(Url.SmsOtp)
|
|
public Response smsOtp(SmsOtp input) {
|
|
UserModel customer = UserModel.find("phone", input.phone).firstResult();
|
|
|
|
if (customer == null) return Response.status(Response.Status.BAD_REQUEST)
|
|
.entity("InvalidPhoneNumber")
|
|
.build();
|
|
|
|
if (
|
|
ManagerEntity.find("phone", input.phone).firstResult() != null
|
|
) return Response.accepted().entity(Role.Manager).build();
|
|
|
|
String otp = otpService.generateAndSaveOtp(input.phone);
|
|
|
|
System.out.println("OTP cho " + input.phone + " là: " + otp);
|
|
|
|
return Response.accepted().entity(Role.Customer).build();
|
|
}
|
|
}
|