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 a9dff81
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 172 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
119 changes: 60 additions & 59 deletions apis/product/db/model/product.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import mongoose from 'mongoose';
import mongoosastic from 'mongoosastic';
import dotenv from 'dotenv';

dotenv.config();

const { Schema } = mongoose;
const productSchema = new Schema({
Expand Down Expand Up @@ -123,72 +120,76 @@ const productSchema = new Schema({
timestamps: { createdAt: true, updatedAt: true },
});

productSchema.plugin(mongoosastic, {
hosts: [
`${process.env.ELASTICSEARCH}`,
],
bulk: {
size: 100,
delay: 1000,
},
filter: (doc) => doc.currentStatus === '๋น„๊ณต๊ฐœ',
type: '_doc',
});
const setMongoosastic = () => {
productSchema.plugin(mongoosastic, {
hosts: [
`${process.env.ELASTICSEARCH}`,
],
bulk: {
size: 100,
delay: 1000,
},
filter: (doc) => doc.currentStatus === '๋น„๊ณต๊ฐœ',
type: '_doc',
});

function customSearch(query, options) {
return new Promise((resolve, reject) => {
this.esSearch(query, options, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
function customSearch(query, options) {
return new Promise((resolve, reject) => {
this.esSearch(query, options, (err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
});
}
}

productSchema.static('search', customSearch);
productSchema.static('search', customSearch);

const Product = mongoose.model('Product', productSchema);
const Product = mongoose.model('Product', productSchema);

Product.createMapping({
settings: {
index: {
analysis: {
tokenizer: {
nori_user_dict: {
type: 'nori_tokenizer',
decompound_mode: 'mixed',
user_dictionary: 'userdict_ko.txt',
Product.createMapping({
settings: {
index: {
analysis: {
tokenizer: {
nori_user_dict: {
type: 'nori_tokenizer',
decompound_mode: 'mixed',
user_dictionary: 'userdict_ko.txt',
},
},
},
analyzer: {
korean: {
type: 'custom',
tokenizer: 'nori_user_dict',
filter: [
'nori_readingform', 'lowercase',
'nori_part_of_speech_basic',
],
analyzer: {
korean: {
type: 'custom',
tokenizer: 'nori_user_dict',
filter: [
'nori_readingform', 'lowercase',
'nori_part_of_speech_basic',
],
},
},
},
filter: {
nori_part_of_speech_basic: {
type: 'nori_part_of_speech',
stoptags: [
'E',
'IC',
'J',
'MAG', 'MAJ', 'MM',
'SP', 'SSC', 'SSO', 'SC', 'SE',
'XPN', 'XSA', 'XSN', 'XSV',
'UNA', 'NA', 'VSV',
],
filter: {
nori_part_of_speech_basic: {
type: 'nori_part_of_speech',
stoptags: [
'E',
'IC',
'J',
'MAG', 'MAJ', 'MM',
'SP', 'SSC', 'SSO', 'SC', 'SE',
'XPN', 'XSA', 'XSN', 'XSV',
'UNA', 'NA', 'VSV',
],
},
},
},
},
},
},
}, () => { });
}, () => { });
return Product;
};

const Product = setMongoosastic();
module.exports = Product;
3 changes: 2 additions & 1 deletion apis/product/db/seeds/product.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import model from '../model';
import mock from './20191209.json';

const { product } = model;

require('dotenv').config();
dotenv.config();

mongoose.connect(`${process.env.MONGO_URL}`, {
useNewUrlParser: 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;
Loading

0 comments on commit a9dff81

Please sign in to comment.