Skip to content

Commit

Permalink
0.3.0 배포 (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
doputer authored Dec 8, 2022
2 parents 0a9cd19 + 93d7f4e commit d2fb96c
Show file tree
Hide file tree
Showing 110 changed files with 2,864 additions and 610 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h3>모두의 글을 엮어 만드는 나만의 책, 노티클 📒</h3>

<a href="https://glaze-lavender-37c.notion.site/Knoticle-256a16714181452eaf3e288b45c9da3b">Documentation</a><br>
<a href="http://27.96.130.68">Explore Knoticle</a>
<a href="https://www.knoticle.app">Explore Knoticle</a>

</div>

Expand Down
6 changes: 6 additions & 0 deletions backend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] },
{ blankLine: 'always', prev: '*', next: 'return' },
],
'prettier/prettier': ['error', { endOfLine: 'auto' }],
'import/order': [
'error',
Expand Down
2 changes: 0 additions & 2 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ model Article {
book_id Int
scraps Scrap[]
@@fulltext([content])
@@fulltext([title])
@@fulltext([content, title])
}

Expand Down
68 changes: 48 additions & 20 deletions backend/src/apis/articles/articles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const searchArticles = async (req: Request, res: Response) => {

const searchResult = await articlesService.searchArticles({ query, page, take: +take, userId });

res.status(200).send(searchResult);
return res.status(200).send(searchResult);
};

const getArticle = async (req: Request, res: Response) => {
const articleId = Number(req.params.articleId);
const articleData = await articlesService.getArticle(articleId);

res.status(200).send(articleData);
return res.status(200).send(articleData);
};

const createArticle = async (req: Request, res: Response) => {
Expand All @@ -28,58 +28,86 @@ const createArticle = async (req: Request, res: Response) => {
content: article.content,
book_id: article.book_id,
});

// forEach와 async,await을 같이사용하는 것이 맞나? 다른방법은 없나?
scraps.forEach(async (scrap: IScrap) => {
if (scrap.id === 0) {
await scrapsService.createScrap({
order: scrap.order,
is_original: true,
book_id: article.book_id,
article_id: createdArticle.id,
});
} else {
await scrapsService.updateScrapOrder(scrap);
}
});

return res.status(201).send({ createdArticle });
};

const updateArticle = async (req: Request, res: Response) => {
const { article, scraps } = req.body;

const articleId = Number(req.params.articleId);

const modifiedArticle = await articlesService.updateArticle(articleId, {
title: article.title,
content: article.content,
book_id: article.book_id,
});

const result: any[] = [];

scraps.forEach(async (scrap: IScrap) => {
if (scrap.id === 0) {
result.push(
await scrapsService.createScrap({
order: scrap.order,
is_original: true,
book_id: article.book_id,
article_id: createdArticle.id,
})
);
result.push(await scrapsService.updateScrapBookId(articleId, article.book_id, scrap));
} else {
result.push(await scrapsService.updateScraps(scrap));
result.push(await scrapsService.updateScrapOrder(scrap));
}
});
res.status(201).send({ createdArticle, result });

return res.status(201).send({ modifiedArticle, result });
};

const deleteArticle = async (req: Request, res: Response) => {
const articleId = Number(req.params.articleId);

await articlesService.deleteArticle(articleId);

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

const getTemporaryArticle = async (req: Request, res: Response) => {
const userId = Number(req.params.userId);
if (!res.locals.user) return res.status(200).send();

const userId = res.locals.user.id;
const temporaryArticle = await articlesService.getTemporaryArticle(userId);

res.status(200).send({ temporaryArticle });
return res.status(200).send(temporaryArticle);
};

const craeteTemporaryArticle = async (req: Request, res: Response) => {
const { title, content, user_id } = req.body;
const createTemporaryArticle = async (req: Request, res: Response) => {
const { title, content } = req.body;

const userId = res.locals.user.id;

const temporaryArticle = await articlesService.createTemporaryArticle({
title,
content,
user_id,
user_id: userId,
});

res.status(201).send({ temporaryArticle });
return res.status(201).send(temporaryArticle);
res.status(201).send(temporaryArticle);
};

export default {
searchArticles,
getArticle,
createArticle,
updateArticle,
deleteArticle,
getTemporaryArticle,
craeteTemporaryArticle,
createTemporaryArticle,
};
30 changes: 30 additions & 0 deletions backend/src/apis/articles/articles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ const searchArticles = async (searchArticles: SearchArticles) => {
deleted_at: null,
...matchUserCondition,
},
orderBy: {
_relevance: {
fields: ['title', 'content'],
sort: 'desc',
search: `${query}*`,
},
},
take,
skip,
});
Expand Down Expand Up @@ -100,6 +107,7 @@ const createArticle = async (dto: CreateArticle) => {
},
},
});

return article;
};

Expand Down Expand Up @@ -149,10 +157,32 @@ const createTemporaryArticle = async (dto: CreateTemporaryArticle) => {
return temporaryArticle;
};

const updateArticle = async (articleId: number, dto: CreateArticle) => {
const { title, content, book_id } = dto;

const article = await prisma.article.update({
where: {
id: articleId,
},
data: {
title,
content,
book: {
connect: {
id: book_id,
},
},
},
});

return article;
};

export default {
searchArticles,
getArticle,
createArticle,
updateArticle,
deleteArticle,
getTemporaryArticle,
createTemporaryArticle,
Expand Down
11 changes: 6 additions & 5 deletions backend/src/apis/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const signIn = async (req: Request, res: Response) => {
res.cookie('access_token', accessToken, { httpOnly: true });
res.cookie('refresh_token', refreshToken, { httpOnly: true });

res.status(200).send({ id: user.id, nickname: user.nickname });
return res.status(200).send({ id: user.id, nickname: user.nickname });
};

const signInGithub = async (req: Request, res: Response) => {
Expand All @@ -41,7 +41,7 @@ const signInGithub = async (req: Request, res: Response) => {
res.cookie('access_token', accessToken, { httpOnly: true });
res.cookie('refresh_token', refreshToken, { httpOnly: true });

res.status(200).send({ id: githubUser.id, nickname: githubUser.nickname });
return res.status(200).send({ id: githubUser.id, nickname: githubUser.nickname });
};

const signUp = async (req: Request, res: Response) => {
Expand All @@ -51,7 +51,7 @@ const signUp = async (req: Request, res: Response) => {

await authService.signUpLocalUser(username, password, nickname);

res.status(201).send();
return res.status(201).send();
};

const checkSignInStatus = async (req: Request, res: Response) => {
Expand All @@ -62,14 +62,15 @@ const checkSignInStatus = async (req: Request, res: Response) => {

return res.status(200).send({ id: user.id, nickname: user.nickname });
}
res.status(200).send({ id: 0, nickname: '' });

return res.status(200).send({ id: 0, nickname: '' });
};

const signOut = async (req: Request, res: Response) => {
res.clearCookie('access_token');
res.clearCookie('refresh_token');

res.status(200).send({ id: 0, nickname: '' });
return res.status(200).send({ id: 0, nickname: '' });
};

export default {
Expand Down
12 changes: 12 additions & 0 deletions backend/src/apis/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const getGithubAccessToken = async (code: string) => {
},
}
);

return data.access_token;
};

Expand All @@ -60,6 +61,7 @@ const getUserByLocalDB = async (provider_id: string) => {
nickname: true,
},
});

return user;
};

Expand All @@ -72,6 +74,11 @@ const signUpGithubUser = async (username: string, provider_id: string) => {
provider: 'github',
password: '',
description: `안녕하세요 ${nickname}입니다.`,
books: {
create: {
title: '새로운 책',
},
},
},
});

Expand Down Expand Up @@ -129,6 +136,11 @@ const signUpLocalUser = async (username: string, password: string, nickname: str
provider: 'local',
password: encryptedPassword,
description: `안녕하세요 ${nickname}입니다.`,
books: {
create: {
title: '새로운 책',
},
},
},
});
};
Expand Down
7 changes: 5 additions & 2 deletions backend/src/apis/bookmarks/bookmarks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ const createBookmark = async (req: Request, res: Response) => {
const userId = res.locals.user.id;

const bookmarkId = await bookmarksService.createBookmark(Number(userId), Number(book_id));
res.status(200).send({ bookmarkId });

return res.status(200).send({ bookmarkId });
};

const deleteBookmark = async (req: Request, res: Response) => {
const bookmarkId = Number(req.params.bookmarkId);

await bookmarksService.deleteBookmark(bookmarkId);
res.status(200).send();

return res.status(200).send();
};

export default {
Expand Down
1 change: 1 addition & 0 deletions backend/src/apis/bookmarks/bookmarks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const createBookmark = async (user_id: number, book_id: number) => {
book_id,
},
});

return id;
};

Expand Down
Loading

0 comments on commit d2fb96c

Please sign in to comment.