Skip to content

Commit

Permalink
[FEAT:#5] 라면 구독 시 옵션 내용 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hyejungg committed May 25, 2022
1 parent 7ebbd7a commit 874bc43
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/controllers/SubscribeController.ts
Original file line number Diff line number Diff line change
@@ -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 };
4 changes: 2 additions & 2 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReviewController from './ReviewController';
import SubscribeController from './SubscribeController';

// controller index file
export { ReviewController };
export { ReviewController, SubscribeController };
7 changes: 7 additions & 0 deletions src/interfaces/subscribe/SubscribeOptionDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PeriodInfo } from '../period/PeriodInfo';
import { QuantityInfo } from '../quantity/QuantityInfo';

export interface SubscribeOptionDto {
deliveryPeriodOptions: PeriodInfo[];
deliveryQuantityOptions: QuantityInfo[];
}
1 change: 1 addition & 0 deletions src/modules/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const message = {
INTERNAL_SERVER_ERROR: '서버 내부 오류',

READ_MAINPAGE_REVIEW_SUCCESS: '메인 페이지 리뷰 조회 성공',
READ_SUBSCRIBE_OPTION_SUCCESS: '라면 구독 옵션 조회 성공',
};

export default message;
8 changes: 8 additions & 0 deletions src/routes/SubscribeRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Router } from 'express';
import { SubscribeController } from '../controllers';

const router: Router = Router();

router.get('/', SubscribeController.getSubscribeOptions);

export default router;
2 changes: 2 additions & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -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;
26 changes: 26 additions & 0 deletions src/services/SubscribeService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SubscribeOptionDto } from '../interfaces/subscribe/SubscribeOptionDto';
import Period from '../models/Period';
import Quantity from '../models/Quantity';

const getSubscribeOptions = async (): Promise<SubscribeOptionDto | null> => {
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 };

0 comments on commit 874bc43

Please sign in to comment.