Skip to content

Commit

Permalink
Merge pull request #112 from boostcamp-2020/develop
Browse files Browse the repository at this point in the history
3주차 배포
  • Loading branch information
rolled-potatoes authored Dec 4, 2020
2 parents edc9703 + ca1cb5a commit bafccc8
Show file tree
Hide file tree
Showing 223 changed files with 10,076 additions and 1,795 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules

# testing
coverage
storybook-static

# production
build
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Project16-A-Account-Book
## N석봉
> Project16-A-Account-Book
<div>
<img src="https://img.shields.io/badge/React-v17.0.1-blue)"/>
<img src="https://img.shields.io/badge/node-v14.15.1-green"/>
Expand All @@ -7,6 +8,8 @@
<img src="https://img.shields.io/badge/mongoose-v5.10.15-critical"/>
</div>
## 💸 [HOME PAGE](http://118.67.132.37/)
돈은 너가 쓰거라, 관리는 내가 할테니
## 📌 소개
💰 개인 또는 공용으로 이용 할 수 있는 자산관리 서비스 입니다.

Expand Down
4 changes: 4 additions & 0 deletions be/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/preset-typescript", "@babel/preset-env"]
}

14 changes: 8 additions & 6 deletions be/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ module.exports = {
browser: true,
es2021: true,
},
extends: ['airbnb-base', 'plugin:prettier/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.ts'],
},
},
},
extends: ['airbnb-base', 'plugin:prettier/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
'import/no-unresolved': 0,
'no-await-in-loop': 0,
'no-unused-vars': 0,
'no-underscore-dangle': 'off',
'import/extensions': [
'error',
'ignorePackages',
Expand Down
11 changes: 11 additions & 0 deletions be/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
roots: ['<rootDir>/src'],
testMatch: [
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)',
],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testEnvironment: 'node',
};
29 changes: 23 additions & 6 deletions be/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"seed": "cd src && NODE_ENV=SEED ts-node -r tsconfig-paths/register seed.ts",
"unseed": "cd src && NODE_ENV=UNSEED ts-node -r tsconfig-paths/register seed.ts",
"seed-dev": "npm run seed && npm run dev",
"build": "npx webpack"
"build": "npx webpack",
"test": "jest"
},
"husky": {
"hooks": {
Expand All @@ -19,35 +20,51 @@
},
"dependencies": {
"@koa/cors": "^3.1.0",
"@types/koa": "^2.11.6",
"@types/koa__cors": "^3.0.2",
"@types/randomstring": "^1.1.6",
"axios": "^0.21.0",
"dotenv": "^8.2.0",
"eslint-plugin-prettier": "^3.1.4",
"jsonwebtoken": "^8.5.1",
"koa": "^2.13.0",
"koa-bodyparser": "^4.3.0",
"koa-router": "^10.0.0",
"mongoose": "^5.10.15"
"mongoose": "~5.10.15",
"passport-local-mongoose": "^6.0.1",
"randomstring": "^1.1.5"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"@babel/preset-typescript": "^7.12.7",
"@types/jest": "^26.0.16",
"@types/jsonwebtoken": "^8.5.0",
"@types/koa": "^2.11.6",
"@types/koa-bodyparser": "^4.3.0",
"@types/koa-router": "^7.4.1",
"@types/mongoose": "^5.10.1",
"@types/koa__cors": "^3.0.2",
"@types/mongoose": "~5.10.1",
"@types/node": "^14.14.9",
"@typescript-eslint/eslint-plugin": "^4.8.0",
"@typescript-eslint/parser": "^4.8.0",
"babel-jest": "^26.6.3",
"eslint": "^7.13.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.1",
"nodemon": "^2.0.6",
"prettier": "^2.1.2",
"ts-jest": "^26.4.4",
"ts-loader": "^8.0.11",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"tsconfig-paths-webpack-plugin": "^3.3.0",
"typescript": "^4.0.5",
"webpack": "^5.4.0",
"webpack-cli": "^4.2.0"
"webpack-cli": "^4.2.0",
"webpack-node-externals": "^2.5.2"
}
}
8 changes: 7 additions & 1 deletion be/src/.env-template
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ DB_USER=
DB_PASSWORD=
DB_HOST=
DB_DATABASE=
DB_PORT=
DB_PORT=
JWT_SECRET=
GITHUB_ID=
GITHUB_SECRET=
HOST=
BE_PORT=
FE_PORT=
6 changes: 6 additions & 0 deletions be/src/apis/urls/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
github: 'https://github.com/login/oauth/authorize?',
gitCallback: '/login/oauth-callback',
gitAccessToken: 'https://github.com/login/oauth/access_token',
gitUser: 'https://api.github.com/user',
};
28 changes: 19 additions & 9 deletions be/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import Koa from 'koa';
import bodyParser from 'koa-bodyparser';
import routers from 'routers';
import cors from '@koa/cors';
import { connect as dbConnect } from './models';
import { connect as dbConnect } from 'models/database';
import { hostConfig } from 'config';
import Router from './routers';
import { corsOptions } from './config';

const app = new Koa();

dbConnect();
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
err.status = err.status || 500;
ctx.body = err.message;
ctx.status = err.status;
}
});
app.use(cors(corsOptions));

app.use(bodyParser());
app.use(cors());
app.use(routers.routes());
app.use((ctx: Koa.Context) => {
ctx.body = 'hello, Koa!';
});
app.use(Router.routes());
app.use(Router.allowedMethods());

app.listen(4000, () => {
console.log('Listening to port 4000');
app.listen(hostConfig.backPort, () => {
console.log(`Listening to port ${hostConfig.backPort}`);
});
29 changes: 28 additions & 1 deletion be/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Context } from 'koa';
import dotenv from 'dotenv';

dotenv.config();
Expand All @@ -11,10 +12,36 @@ const dbConfig = {
port: process.env.DB_PORT,
};

export const hostConfig = {
url: process.env.HOST,
backPort: process.env.BE_PORT,
frontPort: process.env.FE_PORT,
};

export const jwtConfig = {
jwtSecret: process.env.JWT_SECRET || 'jwt_secret',
};

export const githubConfig = {
githubId: process.env.GITHUB_ID,
githubSecret: process.env.GITHUB_SECRET,
};

export const getDbUri = () => {
const localUri = `mongodb://${dbConfig.user}:${dbConfig.password}@${dbConfig.host}:${dbConfig.port}/${dbConfig.database}`;
const srvUri = `mongodb+srv://${dbConfig.user}:${dbConfig.password}@${dbConfig.host}/${dbConfig.database}`;
return dbConfig.port ? localUri : srvUri;
};

export default {};
export const getHostUrl = () => {
return `${hostConfig.url}:${hostConfig.backPort}`;
};

export const getFrontUrl = () => {
return `${hostConfig.url}:${hostConfig.frontPort}`;
};

export const corsOptions = {
origin: (ctx: Context) => ctx.request.header.origin,
credentials: true,
};
10 changes: 10 additions & 0 deletions be/src/controllers/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Koa from 'koa';
import * as accountService from 'services/account';

export const get = async (ctx: Koa.Context) => {
const res = await accountService.getAccounts();
ctx.status = 200;
ctx.response.body = res;
};

export default { get };
19 changes: 19 additions & 0 deletions be/src/controllers/auth/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Koa from 'koa';
import * as authService from 'services/auth';
import { getFrontUrl } from 'config';

export const githubAuthRequest = async (ctx: Koa.Context) => {
const githubAuthUrl = await authService.getGithubURL();
ctx.status = 200;
ctx.response.body = { githubAuthUrl };
};

export const getGithubAccessToken = async (ctx: Koa.Context) => {
const { code } = ctx.query;
const { token, user } = await authService.getGithubAccessToken(code);
ctx.cookies.set('access_token', token, {
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24,
});
ctx.body = user;
};
38 changes: 38 additions & 0 deletions be/src/controllers/category/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Context } from 'koa';
import {
getCategories,
postCategory,
getCategoryStatistics,
} from 'services/category';

const get = async (ctx: Context) => {
const { accountObjId } = ctx.params;
const categorisedType = await getCategories(accountObjId);
ctx.status = 200;
ctx.body = categorisedType;
};

const getStatisticsInfo = async (ctx: Context) => {
const { startDate, endDate } = ctx.query;
const { accountObjId } = ctx.params;
const statistics = await getCategoryStatistics(
accountObjId,
startDate,
endDate,
);
ctx.body = statistics;
};

const post = async (ctx: Context) => {
const { type, title, color, accountObjId } = ctx.request.body;
const res = await postCategory(type, title, color, accountObjId);
if (res.success) {
ctx.status = 200;
ctx.body = res;
} else {
ctx.status = 401;
ctx.body = res;
}
};

export default { getStatisticsInfo, get, post };
11 changes: 11 additions & 0 deletions be/src/controllers/method/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Context } from 'koa';
import { getMethods } from 'services/method';

const get = async (ctx: Context) => {
const { accountObjId } = ctx.params;
const methods = await getMethods(accountObjId);
ctx.status = 200;
ctx.body = methods;
};

export default { get };
16 changes: 12 additions & 4 deletions be/src/controllers/transaction/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import Koa from 'koa';
import { getTransaction, createTransaction } from 'services/transaction';
import { getTransaction, saveAndAddToAccount } from 'services/transaction';

const get = async (ctx: Koa.Context) => {
const { year, month } = ctx.query;
const res = await getTransaction({ year, month });
const { startDate, endDate } = ctx.query;
const { accountObjId } = ctx.params;
const res = await getTransaction({ startDate, endDate, accountObjId });
ctx.status = 200;
ctx.body = res;
};

const post = async (ctx: Koa.Context) => {
await createTransaction(ctx.request.body);
const { transaction } = ctx.request.body;
const { accountObjId } = ctx.params;
try {
await saveAndAddToAccount(transaction, accountObjId);
} catch (e) {
e.status = 400;
throw e;
}
ctx.status = 201;
ctx.res.end();
};
Expand Down
11 changes: 11 additions & 0 deletions be/src/controllers/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Koa from 'koa';
import * as userService from 'services/user';

export const titleByAccountId = async (ctx: Koa.Context) => {
const { accountId } = ctx.query;
const title = await userService.titleByAccountId(accountId);
ctx.status = 200;
ctx.response.body = title;
};

export default titleByAccountId;
Loading

0 comments on commit bafccc8

Please sign in to comment.