Skip to content

Commit

Permalink
refactor: group by controller category
Browse files Browse the repository at this point in the history
- ๊ธฐ์กด CROUD์—์„œ ํ…Œ์ด๋ธ” ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์—,
๋ฐ์ดํ„ฐ๋ฅผ ์“ฐ๊ณ , ์ฝ๊ณ , ์‚ญ์ œ, ์ˆ˜์ •ํ•˜๋Š” ์ปจํŠธ๋กค๋Ÿฌ์™€ ๋‹จ์ˆœํ•œ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค
๋Š” ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ๋ถ„๋ฆฌ (ํŒ€์›์˜๊ฒฌ)
- elasitc search๋Š” ๋น„๋™๊ธฐ ์ด๋ฒคํŠธ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ •์ƒ์ ์œผ๋กœ ํ…Œ์ŠคํŠธ๊ฐ€
๋˜์ง€ ์•Š๊ณ , ์ถ”ํ›„ ์ˆ˜์ • ์˜ˆ์ •
- close #29
  • Loading branch information
kgpyo committed Dec 9, 2019
1 parent bc0257a commit bc0822a
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 114 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/server-api-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
echo "##[set-output name=list;]$(echo $(git remote -v) | cut -d' ' -f2) ${{ steps.BaseRef.outputs.branch }} $GITHUB_REPOSITORY"
id: Arguments
- name: Decrypt Environment and Send Data
- name: Decrypt Environment and build
env:
LARGE_SECRET_PASSPHRASE: ${{ secrets.PRIVATEKEY }}
host: ${{ secrets[steps.HostName.outputs.host] }}
Expand All @@ -44,15 +44,9 @@ jobs:
else
touch ../../.env
fi
- name: copy file via ssh password
uses: appleboy/scp-action@master
with:
host: ${{ secrets[steps.HostName.outputs.host] }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
source: ".env"
target: "~/"
yarn build
cd ../../
sshpass -p$passowrd scp -P $port -o StrictHostKeyChecking=no . $username@$password:~/
- name: deploy to server
uses: appleboy/ssh-action@master
env:
Expand Down
1 change: 1 addition & 0 deletions apis/product/db/model/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const productSchema = new Schema({
timestamps: { createdAt: true, updatedAt: true },
});


productSchema.plugin(mongoosastic, {
hosts: [
`${process.env.ELASTICSEARCH}`,
Expand Down
2 changes: 0 additions & 2 deletions apis/product/db/seeds/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import mock from './20191209.json';

const { product } = model;

require('dotenv').config();

mongoose.connect(`${process.env.MONGO_URL}`, {
useNewUrlParser: true,
useUnifiedTopology: true,
Expand Down
Binary file modified apis/product/env.ssl
Binary file not shown.
2 changes: 1 addition & 1 deletion apis/product/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"scripts": {
"test": "jest --runInBand",
"test": "jest --runInBand --setupFiles dotenv/config --forceExit",
"precommit": "lint-staged && yarn test",
"dev:start": "babel-node bin/www.js",
"build": "babel ./ -d build --copy-files '*.json'",
Expand Down
12 changes: 0 additions & 12 deletions apis/product/routes/controller/deleteProduct.js

This file was deleted.

29 changes: 0 additions & 29 deletions apis/product/routes/controller/getProductInfo.js

This file was deleted.

8 changes: 8 additions & 0 deletions apis/product/routes/controller/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getProductSchemaByKey } from '../../core';

const getProductSchemaController = (req, res) => {
const list = getProductSchemaByKey('category').enumValues;
res.json(list);
};

export default getProductSchemaController;
14 changes: 0 additions & 14 deletions apis/product/routes/controller/modifyProduct.js

This file was deleted.

18 changes: 0 additions & 18 deletions apis/product/routes/controller/productListLookup.js

This file was deleted.

77 changes: 77 additions & 0 deletions apis/product/routes/controller/products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
removeProduct,
getProducts,
getElasticSearchResults,
updateProduct,
insertProduct,
} from '../../core';

export const deleteProductController = async ({ params: { id } }, res, next) => {
try {
const result = await removeProduct(id, res.locals.userId);
res.json(result);
} catch (e) {
next(e);
}
};

export const getProductListController = async (req, res, next) => {
if (res.locals.filter) {
res.locals.query = {
bool: {
must: res.locals.filter,
},
};
delete res.locals.filter;
}
try {
const list = await getElasticSearchResults(res.locals);
res.json(list);
} catch (e) {
next({ status: 400, message: e.toString() });
}
};

export const findProductByIdController = async ({ params: { id } }, res, next) => {
try {
const result = await getProducts(1, 1, { _id: id });
res.json(result);
} catch (e) {
next({ status: 400, message: e.toString() });
}
};

export const modifyProductController = async (req, res, next) => {
const { body, params: { id } } = req;
const { locals: { userId } } = res;
try {
const result = await updateProduct(id, userId, body);
res.json(result);
} catch (e) {
next({ status: 400, message: e.toString() });
}
};

export const productListLookupController = async (req, res, next) => {
const {
options = {},
sort = { order: -1, createAt: 1 },
page = 1,
limits = 10,
} = res.lcoals;
try {
const result = await getProducts(options, sort, page, limits);
res.json(result);
} catch (e) {
next({ status: 400, message: e.toString() });
}
};

export const writeProductCotroller = async ({ body }, res, next) => {
try {
const result = await insertProduct(body);
res.json(result);
} catch (e) {
next({ status: 400, message: e.toString() });
}
};
12 changes: 0 additions & 12 deletions apis/product/routes/controller/writeProduct.js

This file was deleted.

7 changes: 2 additions & 5 deletions apis/product/routes/info.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import express from 'express';
import { getProductSchemaByKey } from '../core';
import getProductSchemaController from './controller/info';

const router = express.Router();

router.get('/category', (req, res) => {
const list = getProductSchemaByKey('category').enumValues;
res.json(list);
});
router.get('/category', getProductSchemaController);

export default router;
11 changes: 7 additions & 4 deletions apis/product/routes/product.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import express from 'express';
import modifyProductController from './controller/modifyProduct';
import deleteProductController from './controller/deleteProduct';
import writeProductCotroller from './controller/writeProduct';
import isLoggedInUser from '../services/user';
import { getProductListController, findProductByIdController } from './controller/getProductInfo';
import queryAnalysisMiddleware from './middleware/listView';
import {
modifyProductController,
deleteProductController,
writeProductCotroller,
getProductListController,
findProductByIdController,
} from './controller/products';

const router = express.Router();

Expand Down
5 changes: 1 addition & 4 deletions apis/product/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ fi
PM2INSTALL=$(npm ls -g --depth=0 | grep -w -o pm2)
if [ "pm2" != "$PM2INSTALL" ]; then
npm install -g pm2
pm2 start ./build/bin/www --name server
fi

yarn build
cd ./build
pm2 start ./bin/www --name server
4 changes: 1 addition & 3 deletions apis/product/tests/unit.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/* eslint-disable no-underscore-dangle */
// https://www.mockaroo.com/
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import model from '../db/model';
import mockData from '../db/seeds/20191129.json';
import mockData from '../db/seeds/20191209.json';
import message from '../core/message';
import * as Core from '../core';
import CODE from '../core/code';

const Product = model.product;

dotenv.config();
jest.setTimeout(10000);

beforeAll(async () => {
Expand Down

0 comments on commit bc0822a

Please sign in to comment.