Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package org.acme.controller;
import org.acme.model.domain.ScreenerTest;

import io.quarkus.logging.Log;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;

@Path("/api")
public class ScreenerTestResource {

@PUT
@Path("/screenerTest")
public void testScreener(@Context SecurityIdentity identity, ScreenerTest screenerTest) {

// TODO: WRITE LOGIC HERE
Log.info(screenerTest);
}

@GET
@Consumes
@Path("/screenerTest/{screenerTestId}")
public String getScreenerTestResult(@Context SecurityIdentity identity, @PathParam("screenerTestId") String screenerTestId) {
// Write logic here
return "Empty string";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.acme.model.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.util.Map;

@JsonIgnoreProperties(ignoreUnknown = true)
public class ScreenerTest {
Map<String, Object> inputData;
Map<String, Object> resultData;

public Map<String, Object> getInputData() {
return inputData;
}

public void setInputData(Map<String, Object> inputData) {
this.inputData = inputData;
}

public Map<String, Object> getResultData() {
return resultData;
}

public void setResultData(Map<String, Object> resultData) {
this.resultData = resultData;
}
}
48 changes: 48 additions & 0 deletions builder-frontend/src/api/screenerTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { authFetch } from "@/api/auth";

import type { ScreenerTest } from "@/types";

const apiUrl = import.meta.env.VITE_API_URL;

export const getScreenerTestResult = async (screenerTestId) => {
const url = apiUrl + "/screenerTest/" + screenerTestId;
try {
const response = await authFetch(url, {
method: "GET",
headers: {
Accept: "application/json",
},
});

if (!response.ok) {
throw new Error(`Fetch failed with status: ${response.status}`);
}
const data = await response.json();
return data;
} catch (error) {
console.error("Error fetching screener test:", error);
throw error; // rethrow so you can handle it in your component if needed
}
};

export const testScreener = async (testScreenerData: ScreenerTest) => {
const url = apiUrl + "/screenerTest";
try {
const response = await authFetch(url, {
method: "PUT",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify(testScreenerData),
});
console.log("test inserted(?)");

if (!response.ok) {
throw new Error(`Update failed with status: ${response.status}`);
}
} catch (error) {
console.error("Error updating project:", error);
throw error;
}
};
44 changes: 41 additions & 3 deletions builder-frontend/src/components/project/preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import FormRenderer from "./FormRenderer";
import Results from "./Results";

import { evaluateScreener } from "../../../api/screener";
import { testScreener, getScreenerTestResult } from "@/api/screenerTest";

import { PreviewFormData, ScreenerResult } from "./types";

Expand Down Expand Up @@ -35,15 +36,52 @@ const Preview = ({ project, formSchema }) => {
setResultsLoading(false);
};

const handleTest = async (screenerTestData) => {
try {
await testScreener(screenerTestData);
console.log("Clicked!");
} catch (e) {
console.log("Error submitting test screener", e);
}
}

const handleTestResult = async (screenerId) => {
try{
console.log("Clicked!");
await getScreenerTestResult(screenerId);
} catch (e) {
console.log("Error getting test screener result", e);
}
}

return (
// TODO: Make sure to put container as a row and not columns
<div>
<div class="m-4 p-4 border-2 border-gray-200 rounded">
<div class="text-lg text-gray-800 text-md font-bold">Form</div>
<FormRenderer schema={schema} submitForm={handleSubmitForm}/>
</div>
<div class="m-4 p-4 border-2 border-gray-200 rounded">
<div class="text-lg text-gray-800 text-md font-bold">Results</div>
<Results inputData={lastInputDataSent} results={results} resultsLoading={resultsLoading}/>
<div class="flex gap-4 m-4">
<div class="flex-1 p-4 border-2 border-gray-200 rounded">
<div class="text-lg text-gray-800 font-bold">Results</div>
<div class="mb-4">
<button
onClick={handleTest} class="btn-default btn-blue"
>
Add as Test
</button>
</div>
<Results inputData={lastInputDataSent} results={results} resultsLoading={resultsLoading}/>
</div>
<div class="flex-1 p-4 border-2 border-gray-200 rounded">
<div>
<button
onClick={handleTestResult} class="btn-default btn-blue"
>
Run Test
</button>
</div>
</div>
</div>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions builder-frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export interface DateParameter extends BaseParameter {
export interface ScreenerResult {
[key: string]: BenefitResult;
}
export interface ScreenerTest {
inputData: PublishedScreener
outputData: ScreenerResult
}
export interface BenefitResult {
name: string;
result: OptionalBoolean;
Expand Down
Loading