Skip to content
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

즐겨찾기 추가 MSW #149

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/SideBarLeft.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export default function SideBarLeft() {
<ul className="space-y-[.8rem]">
{dday.map((item, index) => {
const today = new Date();
console.log(today);
const dDay = new Date(item.d_day);
const differenceInTime = dDay - today;
const differenceInDays = Math.ceil(
Expand Down
60 changes: 40 additions & 20 deletions src/mocks/handlers/eventHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ let mockEventData = [
},
];

let favorites = [
{
favorite_event_id: 1,
event_id: 1,
event_title: "프로젝트 끝!",
d_day: "2024-12-11",
},
{
favorite_event_id: 2,
event_id: 2,
event_title: "2025년",
d_day: "2025-01-01",
},
];

export const eventHandlers = [
// 이벤트 리스트 가져오기 핸들러
rest.get("/api/calendars/:calendar_id/events", (req, res, ctx) => {
Expand Down Expand Up @@ -175,7 +190,6 @@ export const eventHandlers = [
}),

rest.get("/api/users/:userId/favorite-events", (req, res, ctx) => {
const { userId } = req.params;
const token = req.headers.get("Authorization");

if (!token || token !== "Bearer fake_token") {
Expand All @@ -188,24 +202,30 @@ export const eventHandlers = [
);
}

return res(
ctx.status(200),
ctx.json({
favorite_events: [
{
favorite_event_id: 1,
event_id: 1,
event_title: "프로젝트 끝!",
d_day: "2024-12-11",
},
{
favorite_event_id: 2,
event_id: 2,
event_title: "2025년",
d_day: "2025-01-01",
},
],
}),
);
return res(ctx.status(200), ctx.json(favorites));
}),

rest.post("/api/users/:userId/favorite-events", async (req, res, ctx) => {
const token = req.headers.get("Authorization");
const { event_id } = await req.json();

const newFavorite = {
favorite_event_id: favoriteEvents.length + 1,
event_id: event_id,
event_title: event_title,
d_day: d_day,
};

if (!token || token !== "Bearer fake_token") {
return res(
ctx.status(40),
ctx.json({
error: "인증 실패",
message: "로그인이 필요합니다. 다시 로그인해 주세요.",
}),
);
}

return res(ctx.status(201), ctx.json(newFavorite));
}),
];