Skip to content

Commit

Permalink
Merge pull request #248 from team-peekabook/develop
Browse files Browse the repository at this point in the history
v1.2.0 배포
  • Loading branch information
yeseul106 authored May 16, 2024
2 parents c0dd5fd + 0ad55ab commit 502754b
Show file tree
Hide file tree
Showing 23 changed files with 4,386 additions and 583 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ dist

#mac os DS_Store
.DS_Store

# firebase key
new-peekabook-firebase-adminsdk-ke3ck-2c155d0a19.json
2,905 changes: 2,767 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"test": "yarn mocha ./test/* -r ts-node/register -exit"
},
"dependencies": {
"@aws-sdk/abort-controller": "^3.374.0",
"@aws-sdk/client-s3": "^3.304.0",
"@prisma/client": "^5.4.2",
"axios": "^1.3.4",
"dayjs": "^1.11.7",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"express-validator": "^6.15.0",
"firebase-admin": "^12.1.0",
"jsonwebtoken": "^9.0.0",
"multer": "^1.4.5-lts.1",
"multer-s3": "^3.0.1",
Expand Down
3 changes: 2 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ model User {
social_id String? @db.VarChar(50)
refresh_token String? @db.VarChar(500)
email String? @db.VarChar(100)
fcm_token String? @db.VarChar(500)
Alarm_Alarm_receiverIdToUser Alarm[] @relation("Alarm_receiverIdToUser")
Alarm_Alarm_senderIdToUser Alarm[] @relation("Alarm_senderIdToUser")
Block_Block_userIdToUser Block[] @relation("Block_userIdToUser")
Expand Down Expand Up @@ -133,4 +134,4 @@ model Version {
imageUrl String? @db.VarChar(500)
text String? @db.VarChar(255)
iosForceVersion String? @db.VarChar(255)
}
}
10 changes: 10 additions & 0 deletions src/config/pushConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// pushConfig.ts
const admin = require("firebase-admin");

admin.initializeApp({
credential: admin.credential.cert(
require("../../new-peekabook-firebase-adminsdk-ke3ck-2c155d0a19.json")
),
});

export default admin;
9 changes: 4 additions & 5 deletions src/constants/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default {
SIGNIN_FAIL: "로그인 실패",
ALREADY_NICKNAME: "이미 사용중인 닉네임입니다.",


// 유저
READ_USER_SUCCESS: "유저 조회 성공",
READ_USER_FAIL: "유저 조회 실패",
Expand All @@ -33,7 +32,6 @@ export default {
CREATE_IMAGE_SUCCESS: "이미지 저장 성공",
CREATE_IMAGE_FAIL: "이미지 저장 실패",


// 토큰
CREATE_TOKEN_SUCCESS: "토큰 재발급 성공",
EXPIRED_TOKEN: "토큰이 만료되었습니다.",
Expand All @@ -57,6 +55,7 @@ export default {
READ_BOOKSHELF_FAIL: "책장 불러오기 실패",
READ_FRIEND_BOOKSHELF_SUCCESS: "친구 책장 불러오기 성공",
READ_FRIEND_BOOKSHELF_FAIL: "친구 책장 불러오기 실패",
SUCCESS_CHECK_BOOKSHELF_DUPLICATE: "책 등록 시, 중복 체크 성공",

// 서버 내 오류
INTERNAL_SERVER_ERROR: "서버 내 오류",
Expand Down Expand Up @@ -90,6 +89,8 @@ export default {
// 추천
FAIL_GET_RECOMMEND: "추천 책 조회 실패",
SUCCESS_GET_RECOMMEND: "추천 책 조회 성공",
FAIL_DELETE_RECOMMEND: "추천 책 삭제 실패",
SUCCESS_DELETE_RECOMMEND: "추천 책 삭제 성공",

//pick
FAIL_PATCH_PICK: "책 pick 수정 실패",
Expand All @@ -109,6 +110,4 @@ export default {
REASON_FOUR: "닉네임 신고",
REASON_FIVE: "기타",
REPORT_NO_USER: "존재하지 않은 사용자입니다.",


};
};
8 changes: 6 additions & 2 deletions src/controller/authController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ const signIn = async (req: Request, res: Response) => {
.header("accessToken")
?.split(" ")
.reverse()[0] as string;
const { socialPlatform } = req.body;
const { socialPlatform, fcmToken } = req.body;

if (socialPlatform === null || socialPlatform === undefined) {
return res.status(sc.BAD_REQUEST).send(fail(sc.BAD_REQUEST, rm.NULL_VALUE));
}

try {
const data = await authService.signIn(socialToken, socialPlatform);
const data = await authService.signIn(
socialToken,
socialPlatform,
fcmToken
);

if (data === rm.INVALID_SOCIAL_TOKEN) {
return res
Expand Down
35 changes: 35 additions & 0 deletions src/controller/bookshelfController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { rm, sc } from "../constants";
import { fail, success } from "../constants/response";
import { BookshelfCreateDTO } from "../interfaces/bookshelf/BookshelfCreateDTO";
import { BookshelfUpdateDTO } from "../interfaces/bookshelf/BookshelfUpdateDTO";
import { BookshelfDuplicateReqDTO } from "../interfaces/bookshelf/BookshelfDuplicateReqDTO";
import { slackErrorMessage } from "../modules/slack/slackErrorMessage";
import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook";
import { bookshelfService } from "../service";
Expand Down Expand Up @@ -266,13 +267,47 @@ const getFriendBookshelf = async (req: Request, res: Response) => {
}
};

/**
* @route POST /bookshelf/duplicate
* @desc 책 등록 시, 중복된 책인지 확인하기
*/
const checkDuplicateBook = async (req: Request, res: Response) => {
const bookshelfDuplicateReqDTO: BookshelfDuplicateReqDTO = req.body;
const userId = req.body.userId;

try {
const data = await bookshelfService.checkDuplicateBook(
bookshelfDuplicateReqDTO,
+userId
);

return res
.status(sc.OK)
.send(success(sc.OK, rm.SUCCESS_CHECK_BOOKSHELF_DUPLICATE, data));
} catch (error) {
const errorMessage = slackErrorMessage(
req.method.toUpperCase(),
req.originalUrl,
error,
req.statusCode
);

sendWebhookErrorMessage(errorMessage);

res
.status(sc.INTERNAL_SERVER_ERROR)
.send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR));
}
};

const bookshelfController = {
createMyBook,
getBookById,
deleteMyBook,
updateMyBook,
getMyBookshelf,
getFriendBookshelf,
checkDuplicateBook,
};

export default bookshelfController;
2 changes: 1 addition & 1 deletion src/controller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ export { default as bookshelfController } from "./bookshelfController";
export { default as pickController } from "./pickController";
export { default as alarmController } from "./alarmController";
export { default as userController } from "./userController";
export { default as mypageController } from "./mypageController";
export { default as mypageController } from "./mypageController";
30 changes: 25 additions & 5 deletions src/controller/recommendController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import { sendWebhookErrorMessage } from "../modules/slack/slackWebhook";
//* 추천 책 조회하기
const getRecommend = async (req: Request, res: Response) => {
const userId = req.body.userId;
if (!userId) {
return res
.status(sc.BAD_REQUEST)
.send(fail(sc.BAD_REQUEST, rm.BAD_REQUEST));
}

try {
const data = await recommendService.getRecommend(+userId);
Expand Down Expand Up @@ -41,8 +36,33 @@ const getRecommend = async (req: Request, res: Response) => {
}
};

//* 추천 책 삭제하기
const deleteRecommend = async (req: Request, res: Response) => {
const { recommendId } = req.params;

try {
const data = await recommendService.deleteRecommend(+recommendId);

return res.status(sc.OK).send(success(sc.OK, rm.SUCCESS_DELETE_RECOMMEND));
} catch (error) {
const errorMessage = slackErrorMessage(
req.method.toUpperCase(),
req.originalUrl,
error,
req.statusCode
);

sendWebhookErrorMessage(errorMessage);

res
.status(sc.INTERNAL_SERVER_ERROR)
.send(fail(sc.INTERNAL_SERVER_ERROR, rm.INTERNAL_SERVER_ERROR));
}
};

const recommendController = {
getRecommend,
deleteRecommend,
};

export default recommendController;
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ app.use("/", router); // use -> 모든 요청

//* HTTP method - GET
app.get("/", (req: Request, res: Response, next: NextFunction) => {
res.send("Peekabook Server!");
res.send("Peekabook Server!");
});

app.listen(PORT, () => {
console.log(`
console.log(`
#############################################
🛡️ Server listening on port: ${PORT} 🛡️
#############################################
`);
});

export default app;
export default app;
12 changes: 6 additions & 6 deletions src/interfaces/auth/SignUpReqDTO.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface SignUpReqDTO {
profileImage: string|null,
nickname: string|null,
intro: string|null,
social_platform: string;
social_id: string;
}
profileImage: string | null;
nickname: string | null;
intro: string | null;
social_platform: string;
social_id: string;
}
5 changes: 5 additions & 0 deletions src/interfaces/bookshelf/BookshelfDuplicateReqDTO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface BookshelfDuplicateReqDTO {
bookTitle: string;
author: string;
publisher: string;
}
35 changes: 35 additions & 0 deletions src/modules/pushNotificationMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
type ApnsPriority = {
"apns-priority": string;
};

type PushMessage = {
token: string;
notification: {
title: string;
body: string;
};
apns: {
headers: ApnsPriority;
};
};

export const createPushMessage = (
token: string,
title: string,
body: string
): PushMessage => {
const pushMessage = {
token: token,
notification: {
title: title,
body: body,
},
apns: {
headers: {
"apns-priority": "5",
},
},
};

return pushMessage;
};
5 changes: 4 additions & 1 deletion src/router/bookshelfRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ router.get("/", auth, bookshelfController.getMyBookshelf);
//* 친구 책장 조회하기 GET /bookshelf/friend/:friendId
router.get("/friend/:friendId", auth, bookshelfController.getFriendBookshelf);

export default router;
//* 책 등록 시, 중복 체크 POST /bookshelf/duplicate
router.post("/duplicate", auth, bookshelfController.checkDuplicateBook);

export default router;
2 changes: 1 addition & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ router.use("/auth", authRouter);
router.use("/user", userRouter);
router.use("/mypage", mypageRouter);

export default router;
export default router;
3 changes: 2 additions & 1 deletion src/router/recommendRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ const router: Router = Router();

//* 책추천 전체 조회하기 GET - /recommend
router.get("/", auth, recommendController.getRecommend);
router.delete("/:recommendId", auth, recommendController.deleteRecommend);

export default router;
export default router;
Loading

0 comments on commit 502754b

Please sign in to comment.