Skip to content
Closed
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
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
NEXT_PUBLIC_API_BASE_URL=http://localhost:8080
NEXT_PUBLIC_MSS_EDITOR_BASE_URL=http://localhost:5173
NEXT_PUBLIC_MSS_API_BASE_URL=http://localhost:5000
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
/.next/
/out/

# yarn
/.yarn/

# production
/build

Expand Down
153 changes: 0 additions & 153 deletions src/api/ToolboxAPI.ts

This file was deleted.

116 changes: 116 additions & 0 deletions src/api/strategy/StrategyAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { MetaSolverStrategyDto } from "./data-model/MetaSolverStrategyDto";
import { MetaSolverStrategyExecutionOutput } from "./data-model/MetaSolverStrategyExecutionOutput";

export class StrategyApi {
baseUrl: string;

constructor(baseUrl: string) {
this.baseUrl = baseUrl;
}

async listStrategies(
problemTypeId: string = ""
): Promise<MetaSolverStrategyDto[]> {
const query = problemTypeId ? "?type=" + problemTypeId : "";

return await fetch(`${this.baseUrl}/strategies` + query)
.then((res) => res.json())
.then((json) => json as MetaSolverStrategyDto[])
.catch((error) => {
console.error("Failed to list strategies", error);
return [];
});
}

listAllStrategies(): Promise<MetaSolverStrategyDto[]> {
return fetch(`${this.baseUrl}/strategies`)
.then((res) => res.json())
.then((json) => json as MetaSolverStrategyDto[])
.catch((error) => {
console.error("Failed to list all strategies", error);
throw error;
});
}

getStrategy(strategyId: string): Promise<MetaSolverStrategyDto> {
return fetch(`${this.baseUrl}/strategies/${strategyId}`)
.then((res) => res.json())
.then((json) => json as MetaSolverStrategyDto)
.catch((error) => {
console.error(`Failed to get strategy ${strategyId}`, error);
throw error;
});
}

createStrategy(payload: {
name: string;
code: string;
}): Promise<MetaSolverStrategyDto> {
return fetch(`${this.baseUrl}/strategies`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
})
.then((res) => res.json())
.then((json) => json as MetaSolverStrategyDto)
.catch((error) => {
console.error("Failed to create strategy", error);
throw error;
});
}

updateStrategy(
strategyId: string,
payload: { name: string; code: string }
): Promise<MetaSolverStrategyDto> {
return fetch(`${this.baseUrl}/strategies/${strategyId}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
})
.then((res) => res.json())
.then((json) => json as MetaSolverStrategyDto)
.catch((error) => {
console.error(`Failed to update strategy ${strategyId}`, error);
throw error;
});
}

deleteStrategy(strategyId: string): Promise<void> {
return fetch(`${this.baseUrl}/strategies/${strategyId}`, {
method: "DELETE",
})
.then((res) => res.json())
.then(() => undefined)
.catch((error) => {
console.error(`Failed to delete strategy ${strategyId}`, error);
throw error;
});
}

executeStrategy(
strategyId: string,
problemId: string
): Promise<MetaSolverStrategyExecutionOutput> {
return fetch(`${this.baseUrl}/strategies/${strategyId}/execute`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ problemId: problemId }),
})
.then((res) => res.json())
.then((json) => json as MetaSolverStrategyExecutionOutput)
.catch((error) => {
console.error(
`Failed to execute strategy ${strategyId} on problem ${problemId}`,
error
);
throw error;
});
}
}

export const baseUrl = () => process.env.NEXT_PUBLIC_MSS_API_BASE_URL;

export const strategyApi = new StrategyApi(baseUrl() || "");

console.log(baseUrl());
6 changes: 6 additions & 0 deletions src/api/strategy/data-model/MetaSolverStrategyDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface MetaSolverStrategyDto {
id: string;
name: string;
code: string;
problemTypeId: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ProblemDto } from "../../toolbox/data-model/ProblemDto";

export interface MetaSolverStrategyExecutionOutput {
result: ProblemDto<any> | undefined;
}
Loading
Loading