Skip to content

Commit

Permalink
Merge pull request 즐겨찾기 추가 MSW
Browse files Browse the repository at this point in the history
즐겨찾기 추가 MSW
  • Loading branch information
cxaosdev authored Dec 5, 2024
2 parents fc3e56a + 5bd0768 commit 8bd7e84
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 20 deletions.
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 @@ -15,6 +15,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 @@ -178,7 +193,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 @@ -191,24 +205,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));
}),
];

0 comments on commit 8bd7e84

Please sign in to comment.