From 416e302c1ba58fa9c5c1d055fe3befe00eac2a19 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 25 May 2022 20:50:02 +0900 Subject: [PATCH 1/8] =?UTF-8?q?[CHORE#4]=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/common/PostBaseResponseDto.ts | 6 ++-- src/interfaces/period/PeriodInfo.ts | 4 +-- src/interfaces/quantity/QuantityInfo.ts | 4 +-- src/interfaces/review/ReviewInfo.ts | 14 ++++---- src/models/Period.ts | 16 ++++----- src/models/Quantity.ts | 16 ++++----- src/models/Review.ts | 37 ++++++++++---------- src/models/Subscribe.ts | 30 ++++++++-------- 8 files changed, 64 insertions(+), 63 deletions(-) diff --git a/src/interfaces/common/PostBaseResponseDto.ts b/src/interfaces/common/PostBaseResponseDto.ts index 6af2f99..fb2bb10 100644 --- a/src/interfaces/common/PostBaseResponseDto.ts +++ b/src/interfaces/common/PostBaseResponseDto.ts @@ -1,5 +1,5 @@ -import mongoose from "mongoose"; +import mongoose from 'mongoose'; export interface PostBaseResponseDto { - _id: mongoose.Schema.Types.ObjectId; -} \ No newline at end of file + _id: mongoose.Schema.Types.ObjectId; +} diff --git a/src/interfaces/period/PeriodInfo.ts b/src/interfaces/period/PeriodInfo.ts index db38be7..81adb6e 100644 --- a/src/interfaces/period/PeriodInfo.ts +++ b/src/interfaces/period/PeriodInfo.ts @@ -1,3 +1,3 @@ export interface PeriodInfo { - option: string; -} \ No newline at end of file + option: string; +} diff --git a/src/interfaces/quantity/QuantityInfo.ts b/src/interfaces/quantity/QuantityInfo.ts index a333da3..1c2578e 100644 --- a/src/interfaces/quantity/QuantityInfo.ts +++ b/src/interfaces/quantity/QuantityInfo.ts @@ -1,3 +1,3 @@ export interface QuantityInfo { - option: string; -}; \ No newline at end of file + option: string; +} diff --git a/src/interfaces/review/ReviewInfo.ts b/src/interfaces/review/ReviewInfo.ts index 71e065d..a693a6b 100644 --- a/src/interfaces/review/ReviewInfo.ts +++ b/src/interfaces/review/ReviewInfo.ts @@ -1,8 +1,8 @@ export interface ReviewInfo { - userName: String; - thumbnail?: String; - description: Text; - rates: Number; - packageName: string; - product: String; -} \ No newline at end of file + userName: string; + thumbnail?: string; + description: Text; + rates: number; + packageName: string; + product: string; +} diff --git a/src/models/Period.ts b/src/models/Period.ts index 8cea839..dfe8e30 100644 --- a/src/models/Period.ts +++ b/src/models/Period.ts @@ -1,11 +1,11 @@ -import mongoose from "mongoose"; -import { PeriodInfo } from "../interfaces/period/PeriodInfo"; +import mongoose from 'mongoose'; +import { PeriodInfo } from '../interfaces/period/PeriodInfo'; -const PeriodSchema = new mongoose.Schema ({ - option: { - type: String, - required: true - } +const PeriodSchema = new mongoose.Schema({ + option: { + type: String, + required: true, + }, }); -export default mongoose.model("Period", PeriodSchema) \ No newline at end of file +export default mongoose.model('Period', PeriodSchema); diff --git a/src/models/Quantity.ts b/src/models/Quantity.ts index 32acec6..b199bb7 100644 --- a/src/models/Quantity.ts +++ b/src/models/Quantity.ts @@ -1,11 +1,11 @@ -import mongoose from "mongoose"; -import { QuantityInfo } from "../interfaces/quantity/QuantityInfo"; +import mongoose from 'mongoose'; +import { QuantityInfo } from '../interfaces/quantity/QuantityInfo'; -const QuantitySchema = new mongoose.Schema ({ - option: { - type: String, - required: true - } +const QuantitySchema = new mongoose.Schema({ + option: { + type: String, + required: true, + }, }); -export default mongoose.model("Queantity", QuantitySchema) \ No newline at end of file +export default mongoose.model('Queantity', QuantitySchema); diff --git a/src/models/Review.ts b/src/models/Review.ts index 6a89712..b7cec15 100644 --- a/src/models/Review.ts +++ b/src/models/Review.ts @@ -1,32 +1,33 @@ -import mongoose from "mongoose"; -import { ReviewInfo } from "../interfaces/review/ReviewInfo"; +import mongoose from 'mongoose'; +import { ReviewInfo } from '../interfaces/review/ReviewInfo'; -const ReviewSchema = new mongoose.Schema ({ +const ReviewSchema = new mongoose.Schema( + { userName: { - type: String, - required: true + type: String, + required: true, }, thumbnanil: { - type: String + type: String, }, description: { - type: String, - required: true + type: String, + required: true, }, rates: { - type: Number, - required: true + type: Number, + required: true, }, packageName: { - type: String, - required: true + type: String, + required: true, }, product: { - type: String, - required: true - } -}, -{timestamps: true} + type: String, + required: true, + }, + }, + { timestamps: true }, ); -export default mongoose.model("Review", ReviewSchema) \ No newline at end of file +export default mongoose.model('Review', ReviewSchema); diff --git a/src/models/Subscribe.ts b/src/models/Subscribe.ts index 39cd8a9..ef781d0 100644 --- a/src/models/Subscribe.ts +++ b/src/models/Subscribe.ts @@ -1,19 +1,19 @@ -import mongoose from "mongoose"; -import { SubscribeInfo } from "../interfaces/subscribe/SubscribeInfo"; +import mongoose from 'mongoose'; +import { SubscribeInfo } from '../interfaces/subscribe/SubscribeInfo'; -const SubscribeSchema = new mongoose.Schema ({ - period: { - option: { - type: String, - required: true - } +const SubscribeSchema = new mongoose.Schema({ + period: { + option: { + type: String, + required: true, }, - quantity: { - option: { - type: String, - required: true - } - } + }, + quantity: { + option: { + type: String, + required: true, + }, + }, }); -export default mongoose.model("Subscribe", SubscribeSchema) \ No newline at end of file +export default mongoose.model('Subscribe', SubscribeSchema); From c1ef0f8b5c15459ac14d9b6d79b76109706992f9 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 25 May 2022 21:04:45 +0900 Subject: [PATCH 2/8] =?UTF-8?q?[ADD:#3]=20=EC=BD=94=EB=93=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EC=8B=9C=20=EB=B9=88=20=EC=BB=AC=EB=A0=89=EC=85=98?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/loaders/db.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/loaders/db.ts b/src/loaders/db.ts index 02661ed..3564d45 100644 --- a/src/loaders/db.ts +++ b/src/loaders/db.ts @@ -1,5 +1,9 @@ import mongoose from 'mongoose'; import config from '../config'; +import Period from '../models/Period'; +import Quantity from '../models/Quantity'; +import Review from '../models/Review'; +import Subscribe from '../models/Subscribe'; const connectDB = async () => { try { @@ -15,6 +19,22 @@ const connectDB = async () => { mongoose.set('autoIndex', true); console.log('Mongoose Connected ...'); + + Period.createCollection().then(collection => { + console.log('Period collection is created!!'); + }); + + Quantity.createCollection().then(collection => { + console.log('Quantity collection is created!!'); + }); + + Review.createCollection().then(collection => { + console.log('Review collection is created!!'); + }); + + Subscribe.createCollection().then(collection => { + console.log('Subscribe collection is created!!'); + }); } catch (err: any) { console.error(err.message); process.exit(1); From cb348af285a0c4f415f965801c73d3004b7b9bb7 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 25 May 2022 22:50:25 +0900 Subject: [PATCH 3/8] =?UTF-8?q?[CHORE:#3]=20=EB=A6=AC=EB=B7=B0=20=EC=A4=91?= =?UTF-8?q?=20=EC=83=81=ED=92=88=20=EC=A0=95=EB=B3=B4=20=EB=B0=B0=EC=97=B4?= =?UTF-8?q?=20=ED=98=95=ED=83=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F?= =?UTF-8?q?=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interfaces/review/ReviewInfo.ts | 2 +- src/models/Review.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/interfaces/review/ReviewInfo.ts b/src/interfaces/review/ReviewInfo.ts index a693a6b..1ff1ebb 100644 --- a/src/interfaces/review/ReviewInfo.ts +++ b/src/interfaces/review/ReviewInfo.ts @@ -4,5 +4,5 @@ export interface ReviewInfo { description: Text; rates: number; packageName: string; - product: string; + product: string[]; } diff --git a/src/models/Review.ts b/src/models/Review.ts index b7cec15..71c7ea7 100644 --- a/src/models/Review.ts +++ b/src/models/Review.ts @@ -7,7 +7,7 @@ const ReviewSchema = new mongoose.Schema( type: String, required: true, }, - thumbnanil: { + thumbnail: { type: String, }, description: { @@ -23,7 +23,7 @@ const ReviewSchema = new mongoose.Schema( required: true, }, product: { - type: String, + type: Array, required: true, }, }, From 006fe12c0114ee57f4b28f50def99f9c3ab2a5c7 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 25 May 2022 23:14:07 +0900 Subject: [PATCH 4/8] =?UTF-8?q?[CHORE:#3]=20Quantity=20=EC=BB=AC=EB=A0=89?= =?UTF-8?q?=EC=85=98=EB=AA=85=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/Quantity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models/Quantity.ts b/src/models/Quantity.ts index b199bb7..4307931 100644 --- a/src/models/Quantity.ts +++ b/src/models/Quantity.ts @@ -8,4 +8,4 @@ const QuantitySchema = new mongoose.Schema({ }, }); -export default mongoose.model('Queantity', QuantitySchema); +export default mongoose.model('Quantity', QuantitySchema); From a85cd0a2cf30f8da5c2f66afa389bdb48a5dc44e Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 25 May 2022 23:14:59 +0900 Subject: [PATCH 5/8] =?UTF-8?q?[FEAT:#3]=20=EB=A9=94=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReviewController.ts | 22 +++++++++++++++ src/controllers/index.ts | 5 ++-- src/interfaces/review/ReviewResponseDto.ts | 10 +++++++ src/interfaces/subscribe/SubscribeInfo.ts | 10 +++---- src/modules/responseMessage.ts | 2 ++ src/routes/ReviewRouter.ts | 8 ++++++ src/routes/index.ts | 5 +++- src/services/ReviewService.ts | 33 ++++++++++++++++++++++ src/services/index.ts | 3 +- 9 files changed, 89 insertions(+), 9 deletions(-) create mode 100644 src/controllers/ReviewController.ts create mode 100644 src/interfaces/review/ReviewResponseDto.ts create mode 100644 src/routes/ReviewRouter.ts create mode 100644 src/services/ReviewService.ts diff --git a/src/controllers/ReviewController.ts b/src/controllers/ReviewController.ts new file mode 100644 index 0000000..527a185 --- /dev/null +++ b/src/controllers/ReviewController.ts @@ -0,0 +1,22 @@ +import { Request, Response } from 'express'; +import message from '../modules/responseMessage'; +import statusCode from '../modules/statusCode'; +import util from '../modules/util'; +import { ReviewService } from '../services'; + +const getReviewList = async (req: Request, res: Response): Promise => { + try { + const data = await ReviewService.getReviewList(); + if (!data) { + res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, message.NOT_FOUND)); + } + res.status(statusCode.OK).send(util.success(statusCode.OK, message.READ_MAINPAGE_REVIEW_SUCCESS, data)); + } catch (error) { + console.log(error); + res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, message.INTERNAL_SERVER_ERROR)); + } +}; + +export default { + getReviewList, +}; diff --git a/src/controllers/index.ts b/src/controllers/index.ts index 388066c..343b375 100644 --- a/src/controllers/index.ts +++ b/src/controllers/index.ts @@ -1,3 +1,4 @@ -// controller index file -export { }; +import ReviewController from './ReviewController'; +// controller index file +export { ReviewController }; diff --git a/src/interfaces/review/ReviewResponseDto.ts b/src/interfaces/review/ReviewResponseDto.ts new file mode 100644 index 0000000..1069d29 --- /dev/null +++ b/src/interfaces/review/ReviewResponseDto.ts @@ -0,0 +1,10 @@ +import mongoose from 'mongoose'; + +export interface ReviewResponseDto { + _id: mongoose.Types.ObjectId; + userName: string; + description: Text; + productList: string[]; + reviewDate: string; + thumbnail: string; +} diff --git a/src/interfaces/subscribe/SubscribeInfo.ts b/src/interfaces/subscribe/SubscribeInfo.ts index e1361e7..e81242b 100644 --- a/src/interfaces/subscribe/SubscribeInfo.ts +++ b/src/interfaces/subscribe/SubscribeInfo.ts @@ -1,7 +1,7 @@ -import { PeriodInfo } from "../period/PeriodInfo"; -import { QuantityInfo } from "../quantity/QuantityInfo"; +import { PeriodInfo } from '../period/PeriodInfo'; +import { QuantityInfo } from '../quantity/QuantityInfo'; export interface SubscribeInfo { - period: PeriodInfo; - quantity: QuantityInfo; -}; \ No newline at end of file + period: PeriodInfo; + quantity: QuantityInfo; +} diff --git a/src/modules/responseMessage.ts b/src/modules/responseMessage.ts index bd575b2..167bc39 100644 --- a/src/modules/responseMessage.ts +++ b/src/modules/responseMessage.ts @@ -3,6 +3,8 @@ const message = { NOT_FOUND: '존재하지 않는 자원', BAD_REQUEST: '잘못된 요청', INTERNAL_SERVER_ERROR: '서버 내부 오류', + + READ_MAINPAGE_REVIEW_SUCCESS: '메인 페이지 리뷰 조회 성공', }; export default message; diff --git a/src/routes/ReviewRouter.ts b/src/routes/ReviewRouter.ts new file mode 100644 index 0000000..0029a7d --- /dev/null +++ b/src/routes/ReviewRouter.ts @@ -0,0 +1,8 @@ +import { Router } from 'express'; +import { ReviewController } from '../controllers'; + +const router: Router = Router(); + +router.get('/', ReviewController.getReviewList); + +export default router; diff --git a/src/routes/index.ts b/src/routes/index.ts index ce06ee3..54f99b5 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,6 +1,9 @@ // router index file import { Router } from 'express'; +import ReviewRouter from './ReviewRouter'; -const router = Router(); +const router: Router = Router(); + +router.use('/review', ReviewRouter); export default router; diff --git a/src/services/ReviewService.ts b/src/services/ReviewService.ts new file mode 100644 index 0000000..e0cc8d1 --- /dev/null +++ b/src/services/ReviewService.ts @@ -0,0 +1,33 @@ +import { ReviewResponseDto } from '../interfaces/review/ReviewResponseDto'; +import Review from '../models/Review'; + +const getReviewList = async (): Promise => { + try { + const reviews = await Review.find(); + if (!reviews) { + return null; + } + const mainPageReviews: ReviewResponseDto[] = await Promise.all( + reviews.map((review: any) => { + const result = { + _id: review._id, + userName: review.userName, + thumbnail: review.thumbnail, + description: review.description, + packageName: review.packageName, + productList: review.product, + reviewDate: review.createdAt, + }; + return result; + }), + ); + return mainPageReviews; + } catch (error) { + console.log(error); + throw error; + } +}; + +export default { + getReviewList, +}; diff --git a/src/services/index.ts b/src/services/index.ts index 3209921..5e7cc2b 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -1,3 +1,4 @@ // service index file -export { }; +import ReviewService from './ReviewService'; +export { ReviewService }; From 7ebbd7a36c8f98d2e2b49c05aed3f0c0894cf090 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Wed, 25 May 2022 23:40:08 +0900 Subject: [PATCH 6/8] =?UTF-8?q?[CHORE:#3]=20interface=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B9=88=20=EA=B0=9D=EC=B2=B4=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://typescript-eslint.io/rules/no-empty-interface/ 사용 인터페이스 : SubscribeOptionDto.ts --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 6709dd4..eb0d110 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -20,6 +20,7 @@ "rules": { "prettier/prettier": "error", "@typescript-eslint/no-var-requires": "error", + "@typescript-eslint/no-empty-interface": ["error",{ "allowSingleExtends": true }], "new-cap": ["error", { "capIsNew": false }], "no-prototype-builtins": "off", "no-self-assign": "off", From 874bc4302029edf2cff193349184ba0fb042714c Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 26 May 2022 00:10:23 +0900 Subject: [PATCH 7/8] =?UTF-8?q?[FEAT:#5]=20=EB=9D=BC=EB=A9=B4=20=EA=B5=AC?= =?UTF-8?q?=EB=8F=85=20=EC=8B=9C=20=EC=98=B5=EC=85=98=20=EB=82=B4=EC=9A=A9?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SubscribeController.ts | 20 ++++++++++++++ src/controllers/index.ts | 4 +-- .../subscribe/SubscribeOptionDto.ts | 7 +++++ src/modules/responseMessage.ts | 1 + src/routes/SubscribeRouter.ts | 8 ++++++ src/routes/index.ts | 2 ++ src/services/SubscribeService.ts | 26 +++++++++++++++++++ 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/controllers/SubscribeController.ts create mode 100644 src/interfaces/subscribe/SubscribeOptionDto.ts create mode 100644 src/routes/SubscribeRouter.ts create mode 100644 src/services/SubscribeService.ts diff --git a/src/controllers/SubscribeController.ts b/src/controllers/SubscribeController.ts new file mode 100644 index 0000000..1776f2b --- /dev/null +++ b/src/controllers/SubscribeController.ts @@ -0,0 +1,20 @@ +import { Request, Response } from 'express'; +import message from '../modules/responseMessage'; +import statusCode from '../modules/statusCode'; +import util from '../modules/util'; +import SubscribeService from '../services/SubscribeService'; + +const getSubscribeOptions = async (req: Request, res: Response) => { + try { + const data = await SubscribeService.getSubscribeOptions(); + if (!data) { + res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, message.NOT_FOUND)); + } + res.status(statusCode.OK).send(util.success(statusCode.OK, message.READ_SUBSCRIBE_OPTION_SUCCESS, data)); + } catch (error) { + console.log(error); + res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, message.INTERNAL_SERVER_ERROR)); + } +}; + +export default { getSubscribeOptions }; diff --git a/src/controllers/index.ts b/src/controllers/index.ts index 343b375..2c84a0f 100644 --- a/src/controllers/index.ts +++ b/src/controllers/index.ts @@ -1,4 +1,4 @@ import ReviewController from './ReviewController'; +import SubscribeController from './SubscribeController'; -// controller index file -export { ReviewController }; +export { ReviewController, SubscribeController }; diff --git a/src/interfaces/subscribe/SubscribeOptionDto.ts b/src/interfaces/subscribe/SubscribeOptionDto.ts new file mode 100644 index 0000000..75468a0 --- /dev/null +++ b/src/interfaces/subscribe/SubscribeOptionDto.ts @@ -0,0 +1,7 @@ +import { PeriodInfo } from '../period/PeriodInfo'; +import { QuantityInfo } from '../quantity/QuantityInfo'; + +export interface SubscribeOptionDto { + deliveryPeriodOptions: PeriodInfo[]; + deliveryQuantityOptions: QuantityInfo[]; +} diff --git a/src/modules/responseMessage.ts b/src/modules/responseMessage.ts index 167bc39..3754ac4 100644 --- a/src/modules/responseMessage.ts +++ b/src/modules/responseMessage.ts @@ -5,6 +5,7 @@ const message = { INTERNAL_SERVER_ERROR: '서버 내부 오류', READ_MAINPAGE_REVIEW_SUCCESS: '메인 페이지 리뷰 조회 성공', + READ_SUBSCRIBE_OPTION_SUCCESS: '라면 구독 옵션 조회 성공', }; export default message; diff --git a/src/routes/SubscribeRouter.ts b/src/routes/SubscribeRouter.ts new file mode 100644 index 0000000..be94296 --- /dev/null +++ b/src/routes/SubscribeRouter.ts @@ -0,0 +1,8 @@ +import { Router } from 'express'; +import { SubscribeController } from '../controllers'; + +const router: Router = Router(); + +router.get('/', SubscribeController.getSubscribeOptions); + +export default router; diff --git a/src/routes/index.ts b/src/routes/index.ts index 54f99b5..1aab9ce 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,9 +1,11 @@ // router index file import { Router } from 'express'; import ReviewRouter from './ReviewRouter'; +import SubScribeRouter from './SubscribeRouter'; const router: Router = Router(); router.use('/review', ReviewRouter); +router.use('/subscribe', SubScribeRouter); export default router; diff --git a/src/services/SubscribeService.ts b/src/services/SubscribeService.ts new file mode 100644 index 0000000..1188aac --- /dev/null +++ b/src/services/SubscribeService.ts @@ -0,0 +1,26 @@ +import { SubscribeOptionDto } from '../interfaces/subscribe/SubscribeOptionDto'; +import Period from '../models/Period'; +import Quantity from '../models/Quantity'; + +const getSubscribeOptions = async (): Promise => { + try { + const periodOptions = await Period.find(); + const quantityOptions = await Quantity.find(); + + if (!periodOptions || !quantityOptions) { + return null; + } + + const subscribeOptionList = { + deliveryPeriodOptions: periodOptions, + deliveryQuantityOptions: quantityOptions, + }; + + return subscribeOptionList; + } catch (error) { + console.log(error); + throw error; + } +}; + +export default { getSubscribeOptions }; From f687a93ce7e75b7de6eda9582caac2a5c33f29c5 Mon Sep 17 00:00:00 2001 From: hyejungg Date: Thu, 26 May 2022 00:46:16 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[FEAT:#6]=20=EB=A6=AC=EB=B7=B0=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ReviewController.ts | 22 ++++++++++++++++++++++ src/interfaces/review/ReviewCreateDto.ts | 3 +++ src/modules/responseMessage.ts | 2 ++ src/routes/ReviewRouter.ts | 2 ++ src/services/ReviewService.ts | 19 +++++++++++++++++++ 5 files changed, 48 insertions(+) create mode 100644 src/interfaces/review/ReviewCreateDto.ts diff --git a/src/controllers/ReviewController.ts b/src/controllers/ReviewController.ts index 527a185..4f8d481 100644 --- a/src/controllers/ReviewController.ts +++ b/src/controllers/ReviewController.ts @@ -1,4 +1,6 @@ import { Request, Response } from 'express'; +import { validationResult } from 'express-validator'; +import { ReviewCreateDto } from '../interfaces/review/ReviewCreateDto'; import message from '../modules/responseMessage'; import statusCode from '../modules/statusCode'; import util from '../modules/util'; @@ -17,6 +19,26 @@ const getReviewList = async (req: Request, res: Response): Promise => { + const error = validationResult(req); + if (!error.isEmpty()) { + return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, message.BAD_REQUEST)); + } + + const reviewCreateDto: ReviewCreateDto = req.body; + try { + const data = await ReviewService.createReview(reviewCreateDto); + if (!data) { + res.status(statusCode.NOT_FOUND).send(util.fail(statusCode.NOT_FOUND, message.NOT_FOUND)); + } + res.status(statusCode.CREATED).send(util.success(statusCode.CREATED, message.CREATE_REVIEW_SUCCESS, data)); + } catch (error) { + console.log(error); + res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, message.INTERNAL_SERVER_ERROR)); + } +}; + export default { getReviewList, + createReview, }; diff --git a/src/interfaces/review/ReviewCreateDto.ts b/src/interfaces/review/ReviewCreateDto.ts new file mode 100644 index 0000000..c20dc0a --- /dev/null +++ b/src/interfaces/review/ReviewCreateDto.ts @@ -0,0 +1,3 @@ +import { ReviewInfo } from './ReviewInfo'; + +export interface ReviewCreateDto extends ReviewInfo {} diff --git a/src/modules/responseMessage.ts b/src/modules/responseMessage.ts index 3754ac4..0ece097 100644 --- a/src/modules/responseMessage.ts +++ b/src/modules/responseMessage.ts @@ -5,6 +5,8 @@ const message = { INTERNAL_SERVER_ERROR: '서버 내부 오류', READ_MAINPAGE_REVIEW_SUCCESS: '메인 페이지 리뷰 조회 성공', + CREATE_REVIEW_SUCCESS: '리뷰 등록 성공', + READ_SUBSCRIBE_OPTION_SUCCESS: '라면 구독 옵션 조회 성공', }; diff --git a/src/routes/ReviewRouter.ts b/src/routes/ReviewRouter.ts index 0029a7d..fd6e9b2 100644 --- a/src/routes/ReviewRouter.ts +++ b/src/routes/ReviewRouter.ts @@ -1,8 +1,10 @@ import { Router } from 'express'; +import { body } from 'express-validator'; import { ReviewController } from '../controllers'; const router: Router = Router(); router.get('/', ReviewController.getReviewList); +router.post('/', [body('userName').notEmpty(), body('description').notEmpty(), body('rates').notEmpty(), body('packageName').notEmpty(), body('product').notEmpty()], ReviewController.createReview); export default router; diff --git a/src/services/ReviewService.ts b/src/services/ReviewService.ts index e0cc8d1..6ba313b 100644 --- a/src/services/ReviewService.ts +++ b/src/services/ReviewService.ts @@ -1,3 +1,5 @@ +import { PostBaseResponseDto } from '../interfaces/common/PostBaseResponseDto'; +import { ReviewCreateDto } from '../interfaces/review/ReviewCreateDto'; import { ReviewResponseDto } from '../interfaces/review/ReviewResponseDto'; import Review from '../models/Review'; @@ -28,6 +30,23 @@ const getReviewList = async (): Promise => { } }; +const createReview = async (reviewCreateDto: ReviewCreateDto): Promise => { + try { + const review = new Review(reviewCreateDto); + await review.save(); + + const data = { + _id: review._id, + }; + + return data; + } catch (error) { + console.log(error); + throw error; + } +}; + export default { getReviewList, + createReview, };