|
| 1 | +package org.acme.controller; |
| 2 | + |
| 3 | +import io.quarkus.logging.Log; |
| 4 | +import io.quarkus.security.identity.SecurityIdentity; |
| 5 | +import jakarta.inject.Inject; |
| 6 | +import jakarta.validation.Validator; |
| 7 | +import jakarta.ws.rs.*; |
| 8 | +import jakarta.ws.rs.core.*; |
| 9 | + |
| 10 | +import org.acme.api.error.ApiError; |
| 11 | +import org.acme.auth.AuthUtils; |
| 12 | +import org.acme.model.dto.Auth.AccountHookResponse; |
| 13 | + |
| 14 | +@Path("/api") |
| 15 | +public class AccountResource { |
| 16 | + |
| 17 | + @Inject |
| 18 | + Validator validator; |
| 19 | + |
| 20 | + @GET |
| 21 | + @Path("/account-hooks") |
| 22 | + public Response getScreeners(@Context SecurityIdentity identity, |
| 23 | + @QueryParam("action") String action) { |
| 24 | + String userId = AuthUtils.getUserId(identity); |
| 25 | + if (userId == null) { |
| 26 | + return Response.status(Response.Status.UNAUTHORIZED) |
| 27 | + .entity(new ApiError(true, "Unauthorized.")).build(); |
| 28 | + } |
| 29 | + |
| 30 | + if (action == null || action.isBlank()) { |
| 31 | + return Response.status(Response.Status.BAD_REQUEST).entity( |
| 32 | + new ApiError(true, "Query parameter 'action' is required.")) |
| 33 | + .build(); |
| 34 | + } |
| 35 | + Log.info("Running account hooks for: " + userId); |
| 36 | + |
| 37 | + if (action.equals("add example screener")) { |
| 38 | + Log.info("***** Adding an exaample screener to the account *****"); |
| 39 | + } |
| 40 | + |
| 41 | + AccountHookResponse responseBody = new AccountHookResponse( |
| 42 | + "add example screener", true); |
| 43 | + |
| 44 | + return Response.ok(responseBody).build(); |
| 45 | + } |
| 46 | +} |
0 commit comments