-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: handling new api response (#69)
- Loading branch information
Showing
7 changed files
with
119 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { NextResponse } from "next/server"; | ||
|
||
import { fetchData } from "@/lib/api"; | ||
import { mockFetch } from "@/lib/mock-fetch"; | ||
import type { | ||
RawApiRecommendation, | ||
RecommendationRequest, | ||
RecommendationResponse, | ||
} from "@/types/api-types"; | ||
|
||
export async function POST(request: Request) { | ||
const body = (await request.json()) as RecommendationRequest; | ||
|
||
const data = await fetchData<RawApiRecommendation>("/recommend/invoke", { | ||
if (process.env.NODE_ENV === "development") { | ||
const response = await mockFetch("/api/recommend"); | ||
return NextResponse.json(await response.json()); | ||
} | ||
|
||
const data = await fetchData<RecommendationResponse>("/recommend/invoke", { | ||
body: JSON.stringify(body), | ||
method: "POST", | ||
}); | ||
|
||
const result: RecommendationResponse = { | ||
faculty: data.output.faculty, | ||
question: data.output.question, | ||
recommendation: data.output.recommendation, | ||
}; | ||
return NextResponse.json(result); | ||
return NextResponse.json(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,6 @@ export async function mockFetch( | |
} as Response; | ||
|
||
resolve(response); | ||
}, 10_000); | ||
}, 3000); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters