Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyejung #7

Merged
merged 8 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—๋Ÿฌ ๋กœ์ง ์ฒ˜๋ฆฌ ์ข‹์•„์š”

return null;
}

const subscribeOptionList = {
deliveryPeriodOptions: periodOptions,
deliveryQuantityOptions: quantityOptions,
};

return subscribeOptionList;
} catch (error) {
console.log(error);
throw error;
}
};

export default { getSubscribeOptions };