From 0763514ef658899143d617f4076b70f00ad210dd Mon Sep 17 00:00:00 2001 From: EunSeok Date: Thu, 7 Nov 2024 09:32:44 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat(#5):=EC=A4=91=EA=B0=84=EC=A0=80?= =?UTF-8?q?=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/AxiosInstance.js | 3 ++- src/pages/HealthCare/HealthCare.jsx | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/apis/AxiosInstance.js b/src/apis/AxiosInstance.js index b011ba1..96bd27b 100644 --- a/src/apis/AxiosInstance.js +++ b/src/apis/AxiosInstance.js @@ -5,7 +5,8 @@ const token = tokenString ? JSON.parse(tokenString) : null; const Axios = axios.create({ // eslint-disable-next-line no-undef - baseURL: import.meta.env.VITE_BASE_URL, + baseURL: http.localhost.8080, + // baseURL: import.meta.env.VITE_BASE_URL, withCredentials: true, headers: { Authorization: `Bearer ${token?.loginState?.data?.accessToken}`, diff --git a/src/pages/HealthCare/HealthCare.jsx b/src/pages/HealthCare/HealthCare.jsx index a383f8f..e60f0ad 100644 --- a/src/pages/HealthCare/HealthCare.jsx +++ b/src/pages/HealthCare/HealthCare.jsx @@ -16,12 +16,11 @@ const HealthCare = () => { const [memo, setMemo] = useState(""); const user = localStorage.getItem('userId'); console.log(user) - const petData = () => { axios.get(`https://ureca.store/api/pets`) .then((response) => { setPetId( user === response.data.userId) - console.log('petId :', response.data); + console.log('petId :', "ddd"); }) } From 532148fa0a6bf09d610a8060f2e0c8658dae582e Mon Sep 17 00:00:00 2001 From: EunSeok Date: Thu, 7 Nov 2024 13:24:36 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat(#5):=EC=BA=98=EB=A6=B0=EB=8D=94=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/AxiosInstance.js | 2 +- src/pages/HealthCare/HealthCare.jsx | 88 +++++++++++++++-------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/apis/AxiosInstance.js b/src/apis/AxiosInstance.js index d3f0f46..a98e9ea 100644 --- a/src/apis/AxiosInstance.js +++ b/src/apis/AxiosInstance.js @@ -6,7 +6,7 @@ const token = tokenString ? JSON.parse(tokenString) : null; const Axios = axios.create({ // eslint-disable-next-line no-undef - baseURL: http.localhost.8080, + baseURL: "http://localhost:8080/api", // baseURL: import.meta.env.VITE_BASE_URL, withCredentials: true, diff --git a/src/pages/HealthCare/HealthCare.jsx b/src/pages/HealthCare/HealthCare.jsx index e60f0ad..250c703 100644 --- a/src/pages/HealthCare/HealthCare.jsx +++ b/src/pages/HealthCare/HealthCare.jsx @@ -14,41 +14,56 @@ const HealthCare = () => { healthCare: false, }); const [memo, setMemo] = useState(""); - const user = localStorage.getItem('userId'); - console.log(user) - const petData = () => { + const userId = localStorage.getItem('userId'); + console.log('User:', userId); + const formatDate = (date) => { + if (!date || isNaN(new Date(date).getTime())) { + return ""; + } + return new Date(date).toISOString().split("T")[0]; + }; + + // 펫 데이터 가져오기 + const fetchPetData = () => { axios.get(`https://ureca.store/api/pets`) - .then((response) => { - setPetId( user === response.data.userId) - console.log('petId :', "ddd"); + .then((response) => { + const filteredPets = response.data.filter(data => data.user === parseInt(userId)); + if (filteredPets.length > 0) { + const petId = filteredPets.map(pet => pet.petId)[0]; // petId 추출 + console.log('Filtered pet:', petId); + setPetId(petId); // 상태 업데이트 + } }) + .catch((error) => { + console.error("Error fetching pet data:", error); + }); + }; + + // 건강 기록 데이터 가져오기 + const fetchHealthData = async () => { + try { + const response = await axios.get(`https://ureca.store/api/healths`); + const PetHealthData = response.data.filter(item => item.pet === petId); + console.log('건강',PetHealthData); + + setAppointments(PetHealthData.map(item => ({ + ...item, + date: new Date(item.date), + }))); + console.log('건강 기록:', response.data); + } catch (error) { + console.error("Error :", error); } - + }; useEffect(() => { - const userData = (date) => { - if (!date || isNaN(new Date(date).getTime())) { - return ""; - } - return new Date(date).toISOString().split("T")[0]; - }; - - - - - - // const = async () => { - // try { - // const response = await axios.get(`https://ureca.store/api/healths`); - // setAppointments(response.data.map(item => ({ ...item, date: new Date(item.date) }))); - // console.log('댓글 목록:', response.data); - // } catch (error) { - // console.error("Error fetching data:", error); - // } - // }; - - + fetchPetData(); + fetchHealthData(); + toggleInput(); }, []); + useEffect(() => { + console.log('달력 관리', appointments); + }, [appointments]); const handleDateChange = (date) => { setSelectedDate(date); @@ -58,18 +73,8 @@ const HealthCare = () => { setAppointments([...appointments, { date: selectedDate, type, memo }]); const formData = new FormData(); const formattedDate = formatDate(selectedDate); - const userId = localStorage.getItem('userId'); - - console.log("userId :", userId); try { - // petId 가져오기 - const response = await axios.get(`https://ureca.store/api/pets/pet/${userId}`); - const petId = response.data[0].petId; - console.log("petId :", petId); - - // petId를 포함하여 formData에 추가 formData.append("pet", petId); - // 선택된 타입에 따라 필요한 필드를 formData에 추가 if (type === "병원 방문일") { formData.append("visitedDate", formattedDate); @@ -82,7 +87,7 @@ const HealthCare = () => { console.log("formData 내용:", formData); // formData를 포함하여 POST 요청 전송 - const postResponse = await axios.post("/healths", formData); + const postResponse = await axios.post("https://ureca.store/api/healths", formData); console.log("등록 data : ", postResponse.data); alert("등록 성공"); setMemo(""); @@ -97,9 +102,6 @@ const HealthCare = () => { setShowInput({ ...showInput, [type]: !showInput[type] }); }; - const formatDate = (date) => { - return date.toISOString().split("T")[0]; - }; // 날짜에 따른 캘린더 타일 표시 const tileContent = ({ date, view }) => {