Problem refrencing

This commit is contained in:
2026-02-07 22:06:08 +01:00
parent 06aabf7f8c
commit a98a481aa4
5 changed files with 33 additions and 18 deletions
+16 -2
View File
@@ -1,7 +1,7 @@
"use server";
import "server-only";
import { ProblemDefinition } from "./types";
import { Problem, ProblemDefinition } from "./types";
const problems: ProblemDefinition[] = [
{
@@ -35,7 +35,7 @@ const problems: ProblemDefinition[] = [
},
];
export async function getProblems() {
export async function getProblems(): Promise<Problem[]> {
return problems.map((def) => ({
id: def.id,
title: def.title,
@@ -44,3 +44,17 @@ export async function getProblems() {
language: def.language,
}));
}
export async function getProblem(id: string): Promise<Problem | undefined> {
const problem = problems.find((p) => p.id === id);
if (!problem) return;
return {
id: problem.id,
title: problem.title,
description: problem.description,
difficulty: problem.difficulty,
language: problem.language,
};
}