-
Notifications
You must be signed in to change notification settings - Fork 1
[refactor, feat] #7 추천 결과 페이지 API 관련 작업 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
91b55b2
feat: env 파일에 base url 저장
hyeonjiroh a681bd5
chore: 로컬 스토리지 유저 아이디 이름 변경
hyeonjiroh d60c3dc
chore: JS 파일을 TS로 변환
hyeonjiroh d8ad86a
feat: API 관련 타입 정의 추가
hyeonjiroh 6798e8d
feat: API 함수 구현
hyeonjiroh bd8dae7
feat: 추천 결과 데이터 불러오는 동안 로딩 화면 표시되도록 변경
hyeonjiroh 3356bf0
refactor: 추천 데이터 불러오는 로직 훅으로 분리
hyeonjiroh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // hooks/useSurveyRecommendation.ts | ||
| import { useEffect, useState } from "react"; | ||
| import { fetchRecommendation } from "@/lib/apis/survey"; | ||
| import { RecommendationRequest, RecommendationResponse } from "@/lib/type"; | ||
|
|
||
| export function useSurveyRecommendation() { | ||
| const [spaceData, setSpaceData] = useState<RecommendationResponse[]>([]); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
| const [error, setError] = useState<null | string>(null); | ||
|
|
||
| useEffect(() => { | ||
| const userId = localStorage.getItem("userId") || ""; | ||
| const onboarding = JSON.parse( | ||
| localStorage.getItem("onboardingAnswers") ?? "[]" | ||
| ); | ||
|
|
||
| const payload: RecommendationRequest = { | ||
| clientId: userId, | ||
| age: Number(onboarding[0]?.substr(0, 2) || 0), | ||
| gender: onboarding[1], | ||
| resident: onboarding[2], | ||
| city: onboarding[3], | ||
| want: onboarding[5], | ||
| mood: onboarding[6], | ||
| }; | ||
|
|
||
| setIsLoading(true); | ||
| setError(null); | ||
|
|
||
| fetchRecommendation(payload) | ||
| .then((data) => { | ||
| setSpaceData(data); | ||
| }) | ||
| .catch((err) => { | ||
| console.error(err); | ||
| setError("추천 정보를 불러오는 데 실패했어요."); | ||
| }) | ||
| .finally(() => { | ||
| setIsLoading(false); | ||
| }); | ||
| }, []); | ||
|
|
||
| return { spaceData, isLoading, error }; | ||
| } |
This file contains hidden or 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
File renamed without changes.
File renamed without changes.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import axios from "@/lib/axiosInstance"; | ||
| import { RecommendationRequest, UpdateRequest } from "../type"; | ||
|
|
||
| // 사용자 설문 결과 요청 | ||
| export async function fetchRecommendation(payload: RecommendationRequest) { | ||
| try { | ||
| const res = await axios.post("/survey/recommendation", payload); | ||
| return res.data; | ||
| } catch (err) { | ||
| console.error("추천 API 실패:", err); | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| // 사용자 설문 결과 만족도 반영 요청 | ||
| export async function updateSatisfactionScore(payload: UpdateRequest) { | ||
| try { | ||
| await axios.post("/survey/update", payload); | ||
| } catch (err) { | ||
| console.error("만족도 API 호출 실패:", err); | ||
| throw err; | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import axios from "axios"; | ||
|
|
||
| const axiosInstance = axios.create({ | ||
| baseURL: process.env.NEXT_PUBLIC_API_URL, | ||
| }); | ||
|
|
||
| export default axiosInstance; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| export interface RecommendationRequest { | ||
| clientId: string; | ||
| age: number; | ||
| gender: "남자" | "여자"; | ||
| resident: "새만금" | "군산" | "김제" | "부안"; | ||
| city: "새만금" | "군산" | "김제" | "부안"; | ||
| want: string; | ||
| mood: string; | ||
| } | ||
|
|
||
| export interface RecommendationResponse { | ||
| title: string; | ||
| position: string; | ||
| category: "FESTIVAL" | "EVENT" | "TOUR" | "CULTURE"; | ||
| image: string; | ||
| url: string; | ||
| } | ||
|
|
||
| export interface UpdateRequest { | ||
| clientId: string; | ||
| satisfactions: number[]; | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 무슨 문법이더라...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional type이요! routing을 prop으로 전달해줘도 되고, 안해줘도 될 때의 타입입니다