forked from codesquad-members-2024/be-airdnb
-
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.
authInstance 는 자동으로 헤더에 토큰 포함
- Loading branch information
Showing
5 changed files
with
115 additions
and
74 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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { authInstance } from "./axiosInstance"; | ||
|
||
export const fetchBookings = async (token) => { | ||
try { | ||
const response = await authInstance.get("/booking/my-bookings", {}); | ||
return response.data; | ||
} catch (error) { | ||
console.error("Error fetching bookings:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const fetchPricing = async ( | ||
accommodationId, | ||
checkIn, | ||
checkOut, | ||
headCount | ||
) => { | ||
try { | ||
const response = await authInstance.get("/booking", { | ||
params: { | ||
accommodationId, | ||
checkIn, | ||
checkOut, | ||
headCount, | ||
}, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
console.error("Error fetching pricing:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const handleBooking = async ( | ||
accommodationId, | ||
checkIn, | ||
checkOut, | ||
headCount | ||
) => { | ||
const bookingData = { | ||
accommodationId, | ||
checkIn, | ||
checkOut, | ||
headCount, | ||
}; | ||
|
||
try { | ||
const response = await authInstance.post("/booking", bookingData, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}); | ||
|
||
if (response.status !== 201) { | ||
throw new Error("Network response was not created"); | ||
} | ||
|
||
return response.data; | ||
} catch (error) { | ||
console.error("Error booking accommodation:", error); | ||
throw error; | ||
} | ||
}; |
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