45 lines
1.0 KiB
Java
45 lines
1.0 KiB
Java
package com.drinkool;
|
|
|
|
import com.drinkool.dtos.*;
|
|
import com.drinkool.services.AccountService;
|
|
import io.quarkus.redis.datasource.RedisDataSource;
|
|
import io.smallrye.mutiny.Uni;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.ws.rs.*;
|
|
import jakarta.ws.rs.core.Response;
|
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
|
|
|
@Path("/api/v1/customers")
|
|
public class CustomerGatewayResource {
|
|
|
|
@Inject
|
|
@RestClient
|
|
AccountService accountService;
|
|
|
|
@Inject
|
|
RedisDataSource redisDataSource;
|
|
|
|
@POST
|
|
@Path("/signup")
|
|
public Uni<Response> proxySignup(Signup input) {
|
|
String otpVerifiedKey = "otp:verified:" + input.phone;
|
|
var valueCmd = redisDataSource.value(String.class);
|
|
|
|
if (valueCmd.get(otpVerifiedKey) == null) {
|
|
return Uni.createFrom().item(
|
|
Response.status(Response.Status.FORBIDDEN)
|
|
.entity("Phone not verified")
|
|
.build()
|
|
);
|
|
}
|
|
|
|
return accountService.signup(input);
|
|
}
|
|
|
|
@POST
|
|
@Path("/login")
|
|
public Uni<Response> proxyLogin(Login input) {
|
|
return accountService.login(input);
|
|
}
|
|
}
|