File size: 932 Bytes
177cf9f
 
 
 
 
 
31f39f8
177cf9f
31f39f8
177cf9f
 
 
 
 
 
 
 
 
 
 
 
e383749
177cf9f
 
 
 
 
 
 
 
31f39f8
 
177cf9f
 
31f39f8
177cf9f
31f39f8
 
177cf9f
31f39f8
 
177cf9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
export interface StoryCard {
  uid: string;
  name: string;
  slug: string;
  poster: string;
  year: number;
  location: string[];
  media_type: string;
  awards: string[];
  link: string;
  description: string;
}

export interface LandingStory {
  uid: string;
  name: string;
  slug: string;
  poster: string;
  year: number;
  media_type: string;
  awards_count: number;
  link: string;
}

export async function fetchStories(): Promise<LandingStory[]> {
  const resp = await fetch("/api/stories");
  const data = await resp.json();
  return data.stories;
}

export async function searchStories(query: string): Promise<StoryCard[]> {
  const resp = await fetch("/api/search", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ query }),
  });
  if (!resp.ok) {
    throw new Error(`Search failed: ${resp.status}`);
  }
  const data = await resp.json();
  return data.stories;
}