Skip to content

Commit

Permalink
0.5.0 배포 (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
doputer authored Dec 13, 2022
2 parents c9749e7 + 4bc9e23 commit 1319489
Show file tree
Hide file tree
Showing 49 changed files with 555 additions and 202 deletions.
2 changes: 1 addition & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ model User {
password String @db.VarChar(100)
nickname String @unique @db.VarChar(20)
description String @db.VarChar(100)
profile_image String @default("https://kr.object.ncloudstorage.com/j027/522da4f3-c9d7-403d-a98f-2b09cabefc47.png") @db.VarChar(255)
profile_image String @default("https://kr.object.ncloudstorage.com/j027/20e92b3e-af66-4eab-8272-a40ea9212930.png") @db.VarChar(255)
provider String @db.VarChar(20)
created_at DateTime @default(now())
deleted_at DateTime?
Expand Down
18 changes: 14 additions & 4 deletions backend/src/apis/articles/articles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,19 @@ import scrapsService from '@apis/scraps/scraps.service';
import { Forbidden, Message } from '@errors';

const searchArticles = async (req: Request, res: Response) => {
const { query, page, take, userId } = req.query as unknown as SearchArticles;
const { query, page, take, isUsers } = req.query as unknown as SearchArticles;

const searchResult = await articlesService.searchArticles({ query, page, take: +take, userId });
let userId = res.locals.user?.id;

if (!userId) userId = 0;

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

return res.status(200).send(searchResult);
};
Expand Down Expand Up @@ -78,9 +88,9 @@ const updateArticle = async (req: Request, res: Response) => {
const deleteArticle = async (req: Request, res: Response) => {
const articleId = Number(req.params.articleId);

await articlesService.deleteArticle(articleId);
const article = await articlesService.deleteArticle(articleId);

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

const getTemporaryArticle = async (req: Request, res: Response) => {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/apis/articles/articles.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ export interface SearchArticles {
query: string;
page: number;
take: number;
userId: number;
userId?: number;
isUsers?: string;
}

export interface CreateArticle {
Expand Down
23 changes: 13 additions & 10 deletions backend/src/apis/articles/articles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import {
import { prisma } from '@config/orm.config';

const searchArticles = async (searchArticles: SearchArticles) => {
const { query, page, take, userId } = searchArticles;
const { query, page, take, userId, isUsers } = searchArticles;

const skip = (page - 1) * take;

const matchUserCondition = Number(userId)
? {
book: {
user: {
id: Number(userId),
const matchUserCondition =
isUsers === 'true'
? {
book: {
user: {
id: Number(userId),
},
},
},
}
: {};
}
: {};

const articles = await prisma.article.findMany({
select: {
Expand Down Expand Up @@ -112,14 +113,16 @@ const createArticle = async (dto: CreateArticle) => {
};

const deleteArticle = async (articleId: number) => {
await prisma.article.update({
const article = await prisma.article.update({
where: {
id: articleId,
},
data: {
deleted_at: new Date(),
},
});

return article;
};

const getTemporaryArticle = async (userId: number) => {
Expand Down
14 changes: 12 additions & 2 deletions backend/src/apis/books/books.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ const getBooks = async (req: Request, res: Response) => {
};

const searchBooks = async (req: Request, res: Response) => {
const { query, page, take, userId } = req.query as unknown as SearchBooks;
const { query, page, take, isUsers } = req.query as unknown as SearchBooks;

const searchResult = await booksService.searchBooks({ query, userId, take: +take, page });
let userId = res.locals.user?.id;

if (!userId) userId = 0;

const searchResult = await booksService.searchBooks({
query,
isUsers,
userId,
take: +take,
page,
});

return res.status(200).send(searchResult);
};
Expand Down
1 change: 1 addition & 0 deletions backend/src/apis/books/books.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface SearchBooks {
page: number;
take: number;
userId?: number;
isUsers?: string;
}

export interface FindBooks {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/apis/books/books.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FindBooks, SearchBooks, CreateBook } from '@apis/books/books.interface'
import { prisma } from '@config/orm.config';
import { Message, NotFound } from '@errors';

const searchBooks = async ({ query, userId, take, page }: SearchBooks) => {
const searchBooks = async ({ query, userId, isUsers, take, page }: SearchBooks) => {
const skip = (page - 1) * take;

const books = await prisma.book.findMany({
Expand Down Expand Up @@ -40,7 +40,7 @@ const searchBooks = async ({ query, userId, take, page }: SearchBooks) => {
},
where: {
deleted_at: null,
user_id: Number(userId) ? Number(userId) : undefined,
user_id: isUsers === 'true' ? Number(userId) : undefined,
title: {
search: `${query}*`,
},
Expand Down
23 changes: 12 additions & 11 deletions backend/src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import imagesController from '@apis/images/images.controller';
import scrapsController from '@apis/scraps/scraps.controller';
import usersController from '@apis/users/users.controller';
import decoder from '@middlewares/tokenDecoder';
import { tokenErrorHandler } from '@middlewares/tokenErrorHandler';
import guard from '@middlewares/tokenValidator';
import { catchAsync } from '@utils/catch-async';

Expand All @@ -19,34 +20,34 @@ router.post('/auth/signin/local', catchAsync(authController.signIn));
router.post('/auth/signin/github', catchAsync(authController.signInGithub));
router.post('/auth/signup', catchAsync(authController.signUp));
router.get('/auth/signout', catchAsync(authController.signOut));
router.get('/auth', decoder, catchAsync(authController.checkSignInStatus));
router.get('/auth', guard, tokenErrorHandler, catchAsync(authController.checkSignInStatus));

router.get('/articles/temporary', guard, catchAsync(articlesController.getTemporaryArticle));
router.post('/articles/temporary', guard, catchAsync(articlesController.createTemporaryArticle));
router.get('/articles/search', catchAsync(articlesController.searchArticles));
router.get('/articles/search', decoder, catchAsync(articlesController.searchArticles));
router.get('/articles/:articleId', catchAsync(articlesController.getArticle));
router.post('/articles', catchAsync(articlesController.createArticle));
router.patch('/articles/:articleId', catchAsync(articlesController.updateArticle));
router.delete('/articles/:articleId', catchAsync(articlesController.deleteArticle));
router.post('/articles', guard, catchAsync(articlesController.createArticle));
router.patch('/articles/:articleId', guard, catchAsync(articlesController.updateArticle));
router.delete('/articles/:articleId', guard, catchAsync(articlesController.deleteArticle));

router.post('/image', multer().single('image'), catchAsync(imagesController.createImage));
router.post('/image', guard, multer().single('image'), catchAsync(imagesController.createImage));

router.get('/books/search', catchAsync(booksController.searchBooks));
router.get('/books/search', decoder, catchAsync(booksController.searchBooks));
router.get('/books/:bookId', decoder, catchAsync(booksController.getBook));
router.get('/books', decoder, catchAsync(booksController.getBooks));
router.post('/books', guard, catchAsync(booksController.createBook));
router.patch('/books', guard, catchAsync(booksController.updateBook));
router.delete('/books/:bookId', guard, catchAsync(booksController.deleteBook));

router.post('/bookmarks', guard, catchAsync(bookmarksController.createBookmark));
router.delete('/bookmarks/:bookmarkId', catchAsync(bookmarksController.deleteBookmark));
router.delete('/bookmarks/:bookmarkId', guard, catchAsync(bookmarksController.deleteBookmark));

router.get('/scraps', catchAsync(scrapsController.getScraps));
router.patch('/scraps', catchAsync(guard), catchAsync(scrapsController.updateScrapsOrder));
router.post('/scraps', catchAsync(scrapsController.createScrap));
router.patch('/scraps', guard, catchAsync(scrapsController.updateScrapsOrder));
router.post('/scraps', guard, catchAsync(scrapsController.createScrap));
router.delete('/scraps/:scrapId', guard, catchAsync(scrapsController.deleteScrap));

router.get('/users', catchAsync(usersController.getUserProfile));
router.patch('/users/:userId', catchAsync(usersController.editUserProfile));
router.patch('/users/:userId', guard, catchAsync(usersController.editUserProfile));

export default router;
5 changes: 3 additions & 2 deletions backend/src/apis/scraps/scraps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ const createScrap = async (req: Request, res: Response) => {
const deleteScrap = async (req: Request, res: Response) => {
const scrapId = Number(req.params.scrapId);

await scrapsService.deleteScrap(scrapId);
const scrap = await scrapsService.deleteScrap(scrapId);

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

const getScraps = async (req: Request, res: Response) => {
const scraps = await scrapsService.getScraps();

Expand Down
4 changes: 3 additions & 1 deletion backend/src/apis/scraps/scraps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ const updateScrapOrder = async (scraps: IScrap) => {
};

const deleteScrap = async (scrapId: number) => {
await prisma.scrap.delete({
const scrap = await prisma.scrap.delete({
where: {
id: scrapId,
},
});

return scrap;
};

const getScraps = async () => {
Expand Down
7 changes: 7 additions & 0 deletions backend/src/middlewares/tokenErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ErrorRequestHandler } from 'express';

export const tokenErrorHandler: ErrorRequestHandler = (err, req, res, next) => {
if (!err) return next();

return res.status(200).send({ id: 0 });
};
6 changes: 3 additions & 3 deletions frontend/apis/articleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import api from '@utils/api';

interface SearchArticlesApi {
query: string;
userId: number;
isUsers: boolean;
page: number;
take: number;
}
Expand All @@ -11,7 +11,7 @@ export const searchArticlesApi = async (data: SearchArticlesApi) => {
const url = `/api/articles/search`;
const params = {
query: data.query,
userId: data.userId,
isUsers: data.isUsers,
page: data.page,
take: data.take,
};
Expand Down Expand Up @@ -52,7 +52,7 @@ export const modifyArticleApi = async (articleId: number, data: CreateArticleApi
return response.data;
};

export const deleteArticleApi = async (articleId: string) => {
export const deleteArticleApi = async (articleId: number) => {
const url = `/api/articles/${articleId}`;

const response = await api({ url, method: 'DELETE' });
Expand Down
4 changes: 2 additions & 2 deletions frontend/apis/bookApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import api from '@utils/api';

interface SearchBooksApi {
query: string;
userId: number;
isUsers: boolean;
page: number;
take: number;
}
Expand All @@ -12,7 +12,7 @@ export const searchBooksApi = async (data: SearchBooksApi) => {
const url = `/api/books/search`;
const params = {
query: data.query,
userId: data.userId,
isUsers: data.isUsers,
page: data.page,
take: data.take,
};
Expand Down
22 changes: 11 additions & 11 deletions frontend/components/common/Book/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ export const BookWrapper = styled(FlexColumn)`
overflow: hidden;
color: var(--grey-01-color);
aspect-ratio: 280/480;
@media ${(props) => props.theme.tablet} {
width: 100%;
height: auto;
overflow: none;
}
// aspect-ratio: 280/480;
// @media ${(props) => props.theme.tablet} {
// width: 100%;
// height: auto;
// overflow: none;
// }
`;

export const BookThumbnail = styled(Image)`
width: 280px;
min-height: 200px;
object-fit: cover;
aspect-ratio: 280/200;
// aspect-ratio: 280/200;
@media ${(props) => props.theme.tablet} {
width: 100%;
min-height: auto;
}
// @media ${(props) => props.theme.tablet} {
// width: 100%;
// min-height: auto;
// }
`;

export const BookInfoContainer = styled(FlexColumn)`
Expand Down
4 changes: 3 additions & 1 deletion frontend/components/common/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { markdown2html } from '@utils/parser';

import { ContentBody, ContentTitle, ContentWrapper } from './styled';

import 'highlight.js/styles/github.css';
Expand All @@ -13,7 +15,7 @@ export default function Content({ title, content }: ContentProps) {
{title && <ContentTitle>{title}</ContentTitle>}
<ContentBody
dangerouslySetInnerHTML={{
__html: content,
__html: markdown2html(content),
}}
/>
</ContentWrapper>
Expand Down
6 changes: 5 additions & 1 deletion frontend/components/common/Content/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export const ContentBody = styled.div`
p {
img {
width: 100%;
max-width: 720px;
@media ${(props) => props.theme.mobile} {
width: 100%;
}
}
}
Expand Down
10 changes: 1 addition & 9 deletions frontend/components/common/DragDrop/Container/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { useEffect, memo, useCallback } from 'react';
import { memo, useCallback } from 'react';
import { useDrop } from 'react-dnd';

import update from 'immutability-helper';
import { useRecoilState } from 'recoil';

import scrapState from '@atoms/scrap';
import { IScrap } from '@interfaces';

import { ListItem } from '../ListItem';
import ContainerWapper from './styled';
Expand All @@ -15,22 +14,15 @@ const ItemTypes = {
};

export interface ContainerState {
data: IScrap[];
isContentsShown: boolean;
isDeleteBtnShown: boolean;
}
const DragContainer = memo(function Container({
data,
isContentsShown,
isDeleteBtnShown,
}: ContainerState) {
const [scraps, setScraps] = useRecoilState(scrapState);

useEffect(() => {
if (!data) return;
setScraps(data);
}, []);

const findScrap = useCallback(
(id: number) => {
const scrap = scraps.filter((c) => c.article.id === id)[0];
Expand Down
2 changes: 0 additions & 2 deletions frontend/components/common/DragDrop/ListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export const ListItem = memo(function Scrap({
);

const handleMinusBtnClick = () => {
// 원본글이 아니면 스크랩에서만 삭제
// 원본글이면 실제로 삭제
if (isOriginal) {
if (window.confirm('이 글은 원본 글입니다. 정말로 삭제하시겠습니까?')) {
setEditInfo({
Expand Down
Loading

0 comments on commit 1319489

Please sign in to comment.