Skip to content

Commit fa15af0

Browse files
Copilottikazyq
andcommitted
chore: refine status handling and fallbacks
Co-authored-by: tikazyq <[email protected]>
1 parent b20b607 commit fa15af0

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

packages/ui/src/app/api/projects/[id]/specs/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ import { NextResponse } from 'next/server';
1313
import { getSpecs } from '@/lib/db/service-queries';
1414
import { isDefaultProject } from '@/lib/projects/constants';
1515

16+
const VALID_STATUSES = ['planned', 'in-progress', 'complete', 'archived'];
17+
18+
function isValidStatusFilter(statusParam: string | null): boolean {
19+
if (!statusParam) return true;
20+
return statusParam.split(',').every((s) => VALID_STATUSES.includes(s));
21+
}
22+
1623
export async function GET(
1724
request: Request,
1825
{ params }: { params: Promise<{ id: string }> }
@@ -21,9 +28,7 @@ export async function GET(
2128
const { id } = await params;
2229
const url = new URL(request.url);
2330
const statusParam = url.searchParams.get('status');
24-
const validStatuses = ['planned', 'in-progress', 'complete', 'archived'];
25-
26-
if (statusParam && !statusParam.split(',').every((s) => validStatuses.includes(s))) {
31+
if (!isValidStatusFilter(statusParam)) {
2732
return NextResponse.json(
2833
{ error: 'Invalid status filter', code: 'INVALID_REQUEST' },
2934
{ status: 400 }

rust/leanspec-http/src/handlers/specs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,15 @@ pub async fn get_spec(
190190

191191
// Compute required_by
192192
if let Some(complete) = dep_graph.get_complete_graph(&spec.path) {
193-
detail.required_by = complete
193+
let required_by: Vec<String> = complete
194194
.required_by
195195
.iter()
196196
.map(|s| s.path.clone())
197197
.collect();
198+
detail.required_by = required_by.clone();
198199
detail.relationships = Some(crate::types::SpecRelationships {
199200
depends_on: detail.depends_on.clone(),
200-
required_by: Some(detail.required_by.clone()),
201+
required_by: Some(required_by),
201202
});
202203
}
203204

@@ -233,14 +234,15 @@ pub async fn get_project_spec(
233234

234235
// Compute required_by
235236
if let Some(complete) = dep_graph.get_complete_graph(&spec.path) {
236-
detail.required_by = complete
237+
let required_by: Vec<String> = complete
237238
.required_by
238239
.iter()
239240
.map(|s| s.path.clone())
240241
.collect();
242+
detail.required_by = required_by.clone();
241243
detail.relationships = Some(crate::types::SpecRelationships {
242244
depends_on: detail.depends_on.clone(),
243-
required_by: Some(detail.required_by.clone()),
245+
required_by: Some(required_by),
244246
});
245247
}
246248

rust/leanspec-http/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ fn default_project_path() -> PathBuf {
6666
return PathBuf::from(explicit);
6767
}
6868

69-
// Fall back to the expected specs root if current_dir is unavailable
70-
let mut dir = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("specs"));
69+
// Fall back to the current working directory when resolution fails
70+
let mut dir = std::env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
7171
loop {
7272
if dir.join("specs").exists() {
7373
return dir;

0 commit comments

Comments
 (0)