Skip to content
Open
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
7,716 changes: 7,716 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@typescript-eslint/eslint-plugin": "^8.35.0",
"@typescript-eslint/parser": "^8.35.0",
"@vitejs/plugin-react-swc": "^3.5.0",
"@vitest/coverage-v8": "^2.0.3",
"@vitest/coverage-v8": "^3.2.4",
"@vitest/ui": "^3.2.4",
"concurrently": "^8.2.2",
"eslint": "^9.30.0",
Expand Down
97 changes: 39 additions & 58 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added public/repeat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 69 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ app.post('/api/events', async (req, res) => {

app.put('/api/events/:id', async (req, res) => {
const events = await getEvents();
const { id } = req.params;
const id = req.params.id;
const eventIndex = events.events.findIndex((event) => event.id === id);
if (eventIndex > -1) {
const newEvents = [...events.events];
Expand All @@ -59,7 +59,7 @@ app.put('/api/events/:id', async (req, res) => {

app.delete('/api/events/:id', async (req, res) => {
const events = await getEvents();
const { id } = req.params;
const id = req.params.id;

fs.writeFileSync(
`${__dirname}/src/__mocks__/response/realEvents.json`,
Expand All @@ -71,6 +71,73 @@ app.delete('/api/events/:id', async (req, res) => {
res.status(204).send();
});

app.post('/api/events-list', async (req, res) => {
const events = await getEvents();
const repeatId = randomUUID();

const newEvents = req.body.map((event) => {
const isRepeatEvent = event.repeat.type !== 'none';
return {
id: randomUUID(),
...event,
repeat: {
...event.repeat,
id: isRepeatEvent ? repeatId : undefined,
},
};
});

fs.writeFileSync(
`${__dirname}/src/__mocks__/response/realEvents.json`,
JSON.stringify({
events: [...events.events, ...newEvents],
})
);

res.status(201).json(newEvents);
});

app.put('/api/events-list', async (req, res) => {
const events = await getEvents();
let isUpdated = false;

const newEvents = [...events.events];
req.body.events.forEach((event) => {
const eventIndex = events.events.findIndex((target) => target.id === event.id);
if (eventIndex > -1) {
isUpdated = true;
newEvents[eventIndex] = { ...events.events[eventIndex], ...event };
}
});

if (isUpdated) {
fs.writeFileSync(
`${__dirname}/src/__mocks__/response/realEvents.json`,
JSON.stringify({
events: newEvents,
})
);

res.json(events.events);
} else {
res.status(404).send('Event not found');
}
});

app.delete('/api/events-list', async (req, res) => {
const events = await getEvents();
const newEvents = events.events.filter((event) => !req.body.eventIds.includes(event.id)); // ? ids를 전달하면 해당 아이디를 기준으로 events에서 제거

fs.writeFileSync(
`${__dirname}/src/__mocks__/response/realEvents.json`,
JSON.stringify({
events: newEvents,
})
);

res.status(204).send();
});

app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});
Loading
Loading