Skip to content

Commit

Permalink
0.3.2 배포 (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
doputer authored Dec 9, 2022
2 parents 4cb14a3 + 227888a commit 953500c
Show file tree
Hide file tree
Showing 33 changed files with 399 additions and 209 deletions.
60 changes: 30 additions & 30 deletions backend/package-lock.json

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

4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lint": "eslint ."
},
"dependencies": {
"@prisma/client": "^4.7.0",
"@prisma/client": "^4.7.1",
"aws-sdk": "^2.1259.0",
"axios": "^1.1.3",
"bcrypt": "^5.1.0",
Expand Down Expand Up @@ -38,7 +38,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"prisma": "^4.7.0",
"prisma": "^4.7.1",
"ts-node": "^10.9.1",
"tsc-watch": "^5.0.3",
"tsconfig-paths": "^4.1.0",
Expand Down
99 changes: 48 additions & 51 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
provider = "prisma-client-js"
previewFeatures = ["fullTextSearch", "fullTextIndex"]
}

Expand All @@ -12,77 +9,77 @@ datasource db {
}

model User {
id Int @id @default(autoincrement())
username String @db.VarChar(20)
password String @db.VarChar(100)
nickname String @db.VarChar(20) @unique
description String @db.VarChar(100)
profile_image String @db.VarChar(255) @default("https://kr.object.ncloudstorage.com/j027/522da4f3-c9d7-403d-a98f-2b09cabefc47.png")
provider String @db.VarChar(20)
created_at DateTime @default(now())
deleted_at DateTime?
books Book[]
bookmarks Bookmark[]
id Int @id @default(autoincrement())
username String @db.VarChar(20)
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)
provider String @db.VarChar(20)
created_at DateTime @default(now())
deleted_at DateTime?
books Book[]
bookmarks Bookmark[]
temporary_article TemporaryArticle?
token Token?
token Token?
}

model Book {
id Int @id @default(autoincrement())
thumbnail_image String @db.VarChar(255) @default("https://kr.object.ncloudstorage.com/j027/3947d647-f26e-43cc-9834-82d59703cd9c.png")
title String @db.VarChar(50)
created_at DateTime @default(now())
deleted_at DateTime?
user User @relation(fields: [user_id], references: [id])
user_id Int
articles Article[]
scraps Scrap[]
bookmarks Bookmark[]
id Int @id @default(autoincrement())
thumbnail_image String @default("https://kr.object.ncloudstorage.com/j027/3947d647-f26e-43cc-9834-82d59703cd9c.png") @db.VarChar(255)
title String @db.VarChar(50)
created_at DateTime @default(now())
deleted_at DateTime?
user User @relation(fields: [user_id], references: [id])
user_id Int
articles Article[]
scraps Scrap[]
bookmarks Bookmark[]
@@fulltext([title])
@@fulltext([title], map: "title")
}

model Article {
id Int @id @default(autoincrement())
title String @db.VarChar(50)
content String @db.Text
created_at DateTime @default(now())
id Int @id @default(autoincrement())
title String @db.VarChar(100)
content String @db.Text
created_at DateTime @default(now())
deleted_at DateTime?
book Book @relation(fields: [book_id], references: [id])
book_id Int
scraps Scrap[]
book Book @relation(fields: [book_id], references: [id])
book_id Int
scraps Scrap[]
@@fulltext([content, title])
@@fulltext([title, content], map: "title_content")
}

model Scrap {
id Int @id @default(autoincrement())
order Int
id Int @id @default(autoincrement())
order Int
is_original Boolean
article Article @relation(fields: [article_id], references: [id])
article_id Int
book Book @relation(fields: [book_id], references: [id])
book_id Int
article Article @relation(fields: [article_id], references: [id])
article_id Int
book Book @relation(fields: [book_id], references: [id])
book_id Int
}

model Bookmark {
id Int @id @default(autoincrement())
user User @relation(fields: [user_id], references: [id])
id Int @id @default(autoincrement())
user User @relation(fields: [user_id], references: [id])
user_id Int
book Book @relation(fields: [book_id], references: [id])
book Book @relation(fields: [book_id], references: [id])
book_id Int
}

model TemporaryArticle {
id Int @id @default(autoincrement())
title String @db.VarChar(50)
id Int @id @default(autoincrement())
title String @db.VarChar(50)
content String @db.Text
user User @relation(fields: [user_id], references: [id])
user_id Int @unique
user User @relation(fields: [user_id], references: [id])
user_id Int @unique
}

model Token {
refresh_token String @db.VarChar(200)
user User @relation(fields: [user_id], references: [id])
user_id Int @unique
}
user User @relation(fields: [user_id], references: [id])
user_id Int @unique
}
5 changes: 5 additions & 0 deletions backend/src/apis/articles/articles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SearchArticles } from '@apis/articles/articles.interface';
import articlesService from '@apis/articles/articles.service';
import { IScrap } from '@apis/scraps/scraps.interface';
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;
Expand All @@ -23,6 +24,8 @@ const getArticle = async (req: Request, res: Response) => {
const createArticle = async (req: Request, res: Response) => {
const { article, scraps } = req.body;

if (!article.title.length) throw new Forbidden(Message.ARTICLE_INVALID_TITLE);

const createdArticle = await articlesService.createArticle({
title: article.title,
content: article.content,
Expand All @@ -49,6 +52,8 @@ const createArticle = async (req: Request, res: Response) => {
const updateArticle = async (req: Request, res: Response) => {
const { article, scraps } = req.body;

if (!article.title.length) throw new Forbidden(Message.ARTICLE_INVALID_TITLE);

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

const modifiedArticle = await articlesService.updateArticle(articleId, {
Expand Down
5 changes: 5 additions & 0 deletions backend/src/apis/books/books.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FindBooks, SearchBooks } from '@apis/books/books.interface';
import booksService from '@apis/books/books.service';
import { IScrap } from '@apis/scraps/scraps.interface';
import scrapsService from '@apis/scraps/scraps.service';
import { Forbidden, Message } from '@errors';

const getBook = async (req: Request, res: Response) => {
const { bookId } = req.params;
Expand Down Expand Up @@ -40,6 +41,8 @@ const searchBooks = async (req: Request, res: Response) => {
const createBook = async (req: Request, res: Response) => {
const { title } = req.body;

if (!title.length) throw new Forbidden(Message.BOOK_INVALID_TITLE);

const userId = res.locals.user.id;

const book = await booksService.createBook({ title, userId });
Expand All @@ -52,6 +55,8 @@ const createBook = async (req: Request, res: Response) => {
const updateBook = async (req: Request, res: Response) => {
const { id, title, thumbnail_image, scraps } = req.body;

if (!title.length) throw new Forbidden(Message.BOOK_INVALID_TITLE);

const userId = res.locals.user.id;

const book = await booksService.updateBook({ id, title, thumbnail_image });
Expand Down
3 changes: 3 additions & 0 deletions backend/src/apis/books/books.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const searchBooks = async ({ query, userId, take, page }: SearchBooks) => {
select: {
id: true,
order: true,
is_original: true,
article: {
select: {
id: true,
Expand Down Expand Up @@ -76,7 +77,9 @@ const getBook = async (bookId: number, userId: number) => {
scraps: {
orderBy: { order: 'asc' },
select: {
id: true,
order: true,
is_original: true,
article: {
select: {
id: true,
Expand Down
1 change: 1 addition & 0 deletions backend/src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ router.post('/bookmarks', guard, catchAsync(bookmarksController.createBookmark))
router.delete('/bookmarks/:bookmarkId', catchAsync(bookmarksController.deleteBookmark));

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

Expand Down
13 changes: 12 additions & 1 deletion backend/src/apis/scraps/scraps.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const createScrap = async (req: Request, res: Response) => {
}
});

return res.status(201).send();
return res.status(201).send({ book_id, article_id });
};

const deleteScrap = async (req: Request, res: Response) => {
Expand All @@ -36,8 +36,19 @@ const getScraps = async (req: Request, res: Response) => {
return res.status(200).send(scraps);
};

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

scraps.forEach(async (scrap: IScrap) => {
await scrapsService.updateScrapOrder(scrap);
});

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

export default {
createScrap,
deleteScrap,
getScraps,
updateScrapsOrder,
};
Loading

0 comments on commit 953500c

Please sign in to comment.