Skip to content

Commit f06af7b

Browse files
updated api urls in frontend
1 parent 352e044 commit f06af7b

File tree

6 files changed

+53
-15
lines changed

6 files changed

+53
-15
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.acme.constants;
2+
3+
import org.apache.hc.client5.http.impl.auth.AuthCacheKeeper;
4+
5+
public enum CheckStatus {
6+
WORKING('W'),
7+
PUBLISHED('P');
8+
9+
private final char code;
10+
11+
CheckStatus(char code) {
12+
this.code = code;
13+
}
14+
15+
public char getCode() {
16+
return code;
17+
}
18+
}

builder-api/src/main/java/org/acme/controller/EligibilityCheckResource.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import jakarta.ws.rs.core.MediaType;
99
import jakarta.ws.rs.core.Response;
1010
import org.acme.auth.AuthUtils;
11+
import org.acme.constants.CheckStatus;
1112
import org.acme.model.domain.EligibilityCheck;
1213
import org.acme.model.dto.SaveDmnRequest;
1314
import org.acme.persistence.EligibilityCheckRepository;
@@ -134,7 +135,7 @@ public Response updateCheckDmn(@Context SecurityIdentity identity, SaveDmnReques
134135
.build();
135136
}
136137
try {
137-
String filePath = storageService.getCheckDmnModelPath(userId, check.getModule(), check.getId(), check.getVersion());
138+
String filePath = storageService.getCheckDmnModelPath(userId, checkId);
138139
storageService.writeStringToStorage(filePath, dmnModel, "application/xml");
139140
Log.info("Saved DMN model of check " + checkId + " to storage");
140141

@@ -174,15 +175,19 @@ public Response getCustomChecks(@Context SecurityIdentity identity, @QueryParam(
174175

175176
@GET
176177
@Path("/custom-checks/{checkId}")
177-
public Response getCustomCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId, @QueryParam("working") Boolean working) {
178+
public Response getCustomCheck(@Context SecurityIdentity identity, @PathParam("checkId") String checkId) {
178179
String userId = AuthUtils.getUserId(identity);
179180
if (userId == null) {
180181
return Response.status(Response.Status.UNAUTHORIZED).build();
181182
}
182183

184+
char statusIndicator = (checkId != null && !checkId.isEmpty())
185+
? checkId.charAt(0)
186+
: '\0';
187+
183188
Optional<EligibilityCheck> checkOpt;
184189

185-
if (working != null && working){
190+
if (statusIndicator == CheckStatus.WORKING.getCode()){
186191
Log.info("Fetching working custom check: " + checkId + " User: " + userId);
187192
checkOpt = eligibilityCheckRepository.getWorkingCustomCheck(userId, userId);
188193
} else {

builder-api/src/main/java/org/acme/model/domain/EligibilityCheck.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import org.acme.constants.CheckStatus;
6+
57
import java.util.List;
68

79
@JsonIgnoreProperties(ignoreUnknown = true)
@@ -19,8 +21,13 @@ public class EligibilityCheck {
1921
@JsonProperty("isPublic")
2022
private Boolean isPublic;
2123

22-
public String getId() {
23-
return id;
24+
public String getWorkingId() {
25+
return CheckStatus.WORKING.getCode() + "-" + ownerId + "-" + module + "-" + name;
26+
}
27+
28+
public String getPublishedId() {
29+
return CheckStatus.PUBLISHED.getCode() + "-" + ownerId + "-" + module + "-" + name;
30+
2431
}
2532

2633
public void setId(String id) {

builder-api/src/main/java/org/acme/persistence/GoogleStorageService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public String getScreenerPublishedFormSchemaPath(String screenerId){
140140
}
141141

142142
@Override
143-
public String getCheckDmnModelPath(String module, String checkId, String version){
144-
return "check/" + module + "/" + checkId + "/" + version + "/" + checkId + ".dmn";
143+
public String getCheckDmnModelPath(String userId, String checkId){
144+
return "check/" + userId + "/" + checkId + ".dmn";
145145
}
146146

147147
@Override

builder-api/src/main/java/org/acme/persistence/StorageService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface StorageService {
2424
String getScreenerPublishedFormSchemaPath(String screenerId);
2525

2626

27-
String getCheckDmnModelPath(String module, String checkId, String version);
27+
String getCheckDmnModelPath(String userId, String checkId);
2828

2929
String getCheckDmnModelPath(String userId, String module, String checkId, String version);
3030

builder-frontend/src/api/check.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { EligibilityCheck } from "@/types";
55
const apiUrl = import.meta.env.VITE_API_URL;
66

77
export const fetchPublicChecks = async (): Promise<EligibilityCheck[]> => {
8-
const url = apiUrl + "/check";
8+
const url = apiUrl + "/checks";
99
try {
1010
const response = await authFetch(url, {
1111
method: "GET",
@@ -28,7 +28,7 @@ export const fetchPublicChecks = async (): Promise<EligibilityCheck[]> => {
2828
export const fetchCheck = async (
2929
checkId: string
3030
): Promise<EligibilityCheck> => {
31-
const url = apiUrl + `/check/${checkId}`;
31+
const url = apiUrl + `/checks/${checkId}`;
3232
try {
3333
const response = await authFetch(url, {
3434
method: "GET",
@@ -52,7 +52,7 @@ export const fetchCheck = async (
5252
export const fetchCustomCheck = async (
5353
checkId: string
5454
): Promise<EligibilityCheck> => {
55-
const url = apiUrl + `/account/check/${checkId}`;
55+
const url = apiUrl + `/custom-checks/${checkId}`;
5656
try {
5757
const response = await authFetch(url, {
5858
method: "GET",
@@ -74,7 +74,7 @@ export const fetchCustomCheck = async (
7474
};
7575

7676
export const addCheck = async (check: EligibilityCheck) => {
77-
const url = apiUrl + "/account/check";
77+
const url = apiUrl + "/custom-checks";
7878
try {
7979
const response = await authFetch(url, {
8080
method: "POST",
@@ -97,7 +97,7 @@ export const addCheck = async (check: EligibilityCheck) => {
9797
};
9898

9999
export const updateCheck = async (check: EligibilityCheck) => {
100-
const url = apiUrl + "/account/check";
100+
const url = apiUrl + "/custom-checks";
101101
try {
102102
const response = await authFetch(url, {
103103
method: "PUT",
@@ -142,8 +142,16 @@ export const saveCheckDmn = async (checkId: string, dmnModel: string) => {
142142
}
143143
};
144144

145-
export const fetchUserDefinedChecks = async (): Promise<EligibilityCheck[]> => {
146-
const url = apiUrl + "/account/check";
145+
export const fetchUserDefinedChecks = async (
146+
working: boolean
147+
): Promise<EligibilityCheck[]> => {
148+
let url: string;
149+
if (working) {
150+
url = apiUrl + "/custom-checks?working=true";
151+
} else {
152+
url = apiUrl + "/custom-checks?working=false";
153+
}
154+
147155
try {
148156
const response = await authFetch(url, {
149157
method: "GET",

0 commit comments

Comments
 (0)