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 all commits
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions src/controllers/ReviewController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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';
import { ReviewService } from '../services';

const getReviewList = async (req: Request, res: Response): Promise<Response | void> => {
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));
}
};

const createReview = async (req: Request, res: Response): Promise<Response | void> => {
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,
};
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 };
5 changes: 3 additions & 2 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// controller index file
export { };
import ReviewController from './ReviewController';
import SubscribeController from './SubscribeController';

export { ReviewController, SubscribeController };
6 changes: 3 additions & 3 deletions src/interfaces/common/PostBaseResponseDto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import mongoose from "mongoose";
import mongoose from 'mongoose';

export interface PostBaseResponseDto {
_id: mongoose.Schema.Types.ObjectId;
}
_id: mongoose.Schema.Types.ObjectId;
}
4 changes: 2 additions & 2 deletions src/interfaces/period/PeriodInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface PeriodInfo {
option: string;
}
option: string;
}
4 changes: 2 additions & 2 deletions src/interfaces/quantity/QuantityInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface QuantityInfo {
option: string;
};
option: string;
}
3 changes: 3 additions & 0 deletions src/interfaces/review/ReviewCreateDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ReviewInfo } from './ReviewInfo';

export interface ReviewCreateDto extends ReviewInfo {}
14 changes: 7 additions & 7 deletions src/interfaces/review/ReviewInfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface ReviewInfo {
userName: String;
thumbnail?: String;
description: Text;
rates: Number;
packageName: string;
product: String;
}
userName: string;
thumbnail?: string;
description: Text;
rates: number;
packageName: string;
product: string[];
}
10 changes: 10 additions & 0 deletions src/interfaces/review/ReviewResponseDto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 5 additions & 5 deletions src/interfaces/subscribe/SubscribeInfo.ts
Original file line number Diff line number Diff line change
@@ -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;
};
period: PeriodInfo;
quantity: QuantityInfo;
}
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[];
}
20 changes: 20 additions & 0 deletions src/loaders/db.ts
Original file line number Diff line number Diff line change
@@ -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';
Copy link
Contributor

Choose a reason for hiding this comment

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

๋นผ๋จน์€ ๋กœ๋” ์ž˜ ์ฑ™๊ฒจ์ฃผ์…”์„œ ๊ฐ์‚ผ๋‹น~! ๐Ÿ‘


const connectDB = async () => {
try {
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions src/models/Period.ts
Original file line number Diff line number Diff line change
@@ -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<PeriodInfo & mongoose.Document>("Period", PeriodSchema)
export default mongoose.model<PeriodInfo & mongoose.Document>('Period', PeriodSchema);
16 changes: 8 additions & 8 deletions src/models/Quantity.ts
Original file line number Diff line number Diff line change
@@ -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<QuantityInfo & mongoose.Document>("Queantity", QuantitySchema)
export default mongoose.model<QuantityInfo & mongoose.Document>('Quantity', QuantitySchema);
Copy link
Contributor

Choose a reason for hiding this comment

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

๋งˆ์ด ๋ฏธ์Šคํ…Œ์žŒ,,

39 changes: 20 additions & 19 deletions src/models/Review.ts
Original file line number Diff line number Diff line change
@@ -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
thumbnail: {
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: Array,
required: true,
},
},
{ timestamps: true },
);

export default mongoose.model<ReviewInfo & mongoose.Document>("Review", ReviewSchema)
export default mongoose.model<ReviewInfo & mongoose.Document>('Review', ReviewSchema);
30 changes: 15 additions & 15 deletions src/models/Subscribe.ts
Original file line number Diff line number Diff line change
@@ -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<SubscribeInfo & mongoose.Document>("Subscribe", SubscribeSchema)
export default mongoose.model<SubscribeInfo & mongoose.Document>('Subscribe', SubscribeSchema);
5 changes: 5 additions & 0 deletions src/modules/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ const message = {
NOT_FOUND: '์กด์žฌํ•˜์ง€ ์•Š๋Š” ์ž์›',
BAD_REQUEST: '์ž˜๋ชป๋œ ์š”์ฒญ',
INTERNAL_SERVER_ERROR: '์„œ๋ฒ„ ๋‚ด๋ถ€ ์˜ค๋ฅ˜',

READ_MAINPAGE_REVIEW_SUCCESS: '๋ฉ”์ธ ํŽ˜์ด์ง€ ๋ฆฌ๋ทฐ ์กฐํšŒ ์„ฑ๊ณต',
CREATE_REVIEW_SUCCESS: '๋ฆฌ๋ทฐ ๋“ฑ๋ก ์„ฑ๊ณต',

READ_SUBSCRIBE_OPTION_SUCCESS: '๋ผ๋ฉด ๊ตฌ๋… ์˜ต์…˜ ์กฐํšŒ ์„ฑ๊ณต',
};

export default message;
10 changes: 10 additions & 0 deletions src/routes/ReviewRouter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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;
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;
7 changes: 6 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// router index file
import { Router } from 'express';
import ReviewRouter from './ReviewRouter';
import SubScribeRouter from './SubscribeRouter';

const router = Router();
const router: Router = Router();

router.use('/review', ReviewRouter);
router.use('/subscribe', SubScribeRouter);

export default router;
Loading