Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sjsjmine129 committed Jan 24, 2024
1 parent 918ac62 commit acd978c
Show file tree
Hide file tree
Showing 180 changed files with 11,590 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/deploy_to_lambda.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy to AWS Lambda

on:
push:
branches:
- main
- develop

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "18"

- name: Package Lambda function
run: zip -r lambda.zip .

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Deploy to Lambda tikkle_dev
if: github.ref == 'refs/heads/develop'
run: |
aws lambda update-function-code --function-name tikkle_dev --zip-file fileb://lambda.zip
- name: Deploy to Lambda tikkle
if: github.ref == 'refs/heads/main'
run: |
aws lambda update-function-code --function-name tikkle --zip-file fileb://lambda.zip
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/README.TOOLKIT.md
/reqs/
/.aws-sam/
/.vscode/
/samconfig.toml
/template.yaml
/.DS_Store
tikkle-c9666-firebase-adminsdk-knplx-fcb6d4f595.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/*
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 200
}
31 changes: 31 additions & 0 deletions actinoFunnelLogger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { ActionFunnelLogManager } = require("./features/ActionFunnelLogManager");
const { DBManager } = require("./db");
exports.actionFunnelLogger = async (req, res, next) => {
const db = new DBManager();
await db.openTransaction();
try {
const user_id = req.id;

const funnel_log_manager = await ActionFunnelLogManager.createActionFunnelLogManager({ user_id, db });

// console.error(req.path);
// console.error(req.method);
// console.error(req.route);
if (req.route == "/post_product_list") {
if (req.body.search == null || req.body.search == undefined || req.body.search == "") {
await funnel_log_manager.logControllInterface(req.route);
} else {
await funnel_log_manager.logControllInterface("/post_product_search");
}
} else {
await funnel_log_manager.logControllInterface(req.route);
}
await db.commitTransaction();
} catch (error) {
await db.rollbackTransaction();
//return invalid when token is invalid
console.error(`🚨 error -> ⚡️ actionFunnelLogger : 🐞${error}`);
}

next();
};
49 changes: 49 additions & 0 deletions authtoken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { checkToken } = require("token.js");

exports.authtoken = async (req, res, next) => {
const headers = req.headers;
const authorization = headers.authorization;
const [accessToken, refreshToken] = authorization.split(",");

//-------- check token & get user id --------------------------------------------------------------------------------------//

let tokenCheck;
let returnBody;
let id;

try {
tokenCheck = await checkToken(accessToken, refreshToken);
returnBody = JSON.parse(tokenCheck.body);
id = returnBody.tokenData.id;
} catch (error) {
//return invalid when token is invalid
console.log("authtoken 에서 에러가 발생했습니다.");
const return_body = {
success: false,
detail_code: "99",
message: "login again",
returnToken: null,
};
return res.status(401).send(return_body);
}

//return invalid when token is invalid
if (tokenCheck.statusCode !== 200) {
console.log("authtoken 에서 에러가 발생했습니다.");
const return_body = {
success: false,
detail_code: "99",
message: "login again",
returnToken: null,
};
return res.status(401).send(return_body);
}

const returnToken = returnBody.accessToken;

//-------- sucess result --------------------------------------------------------------------------------------//

req.id = id;
req.returnToken = returnToken;
next();
};
86 changes: 86 additions & 0 deletions db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const mysql = require("mysql2/promise");
const { getDatabaseCredentials } = require("db.js");

class DBManager {
/**
* @description 트랜잭션을 열고, connection을 반환한다.
* @returns {Promise<Connection>}
* @memberof DBManager
* @example
* const db = new DBManager();
* await db.openTransaction();
* try {
* const result = await db.executeQuery(sql, params);
* await db.commitTransaction();
* }
* catch(err) {
* await db.rollbackTransaction();
* }
*/
async openTransaction() {
const credentials = await getDatabaseCredentials();
console.log(credentials);
this.connection = await mysql.createConnection(credentials);
await this.connection.beginTransaction();
}
/**
* @description 쿼리를 실행한다.
* @returns {Promise<Connection>}
* @memberof DBManager
* @example
* const db = new DBManager();
* await db.openTransaction();
* try {
* const result = await db.executeQuery(sql, params);
* await db.commitTransaction();
* }
* catch(err) {
* await db.rollbackTransaction();
* }
*/
async executeQuery(sql, params) {
const [rows] = await this.connection.execute(sql, params);
return rows;
}
/**
* @description 트랜잭션을 커밋하고, connection을 종료한다.
* @returns {Promise<Connection>}
* @memberof DBManager
* @example
* const db = new DBManager();
* await db.openTransaction();
* try {
* const result = await db.executeQuery(sql, params);
* await db.commitTransaction();
* }
* catch(err) {
* await db.rollbackTransaction();
* }
*/
async commitTransaction() {
console.log("commit");
await this.connection.commit();
await this.connection.end();
}
/**
* @description 트랜잭션을 롤백하고, connection을 종료한다.
* @returns {Promise<Connection>}
* @memberof DBManager
* @example
* const db = new DBManager();
* await db.openTransaction();
* try {
* const result = await db.executeQuery(sql, params);
* await db.commitTransaction();
* }
* catch(err) {
* await db.rollbackTransaction();
* }
*/
async rollbackTransaction() {
await this.connection.rollback();
await this.connection.end();
}
}

module.exports = { DBManager };
Binary file added events/.DS_Store
Binary file not shown.
12 changes: 12 additions & 0 deletions events/apple_login_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"resource": "/apple_login_test",
"path": "/apple_login_test",
"httpMethod": "POST",
"headers": {
"authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjcsImlhdCI6MTcwMzczMjc5MywiZXhwIjo5MDAwMDAwMDAxNzAzNzMzMDAwLCJpc3MiOiJMaUZvbGkifQ.XKvRcbkWP9a4J-lfDvcZ6O01patJzvuS1n11d4VPtBQ,eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjcsImlhdCI6MTcwMzczMjc5MywiZXhwIjoxNzA2MzI0NzkzLCJpc3MiOiJMaUZvbGkifQ.6Pox2D4qm0ABi_w2AjY8hbkbIDODR8arDi7p9pNs12g"
},
"queryStringParameters": null,
"body": {
"productId": 7
}
}
10 changes: 10 additions & 0 deletions events/auth/get_auth_checkToken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/get_auth_checkToken",
"path": "/get_auth_checkToken",
"httpMethod": "GET",
"headers": {
"authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjcsImlhdCI6MTcwMzczMjc5MywiZXhwIjo5MDAwMDAwMDAxNzAzNzMzMDAwLCJpc3MiOiJMaUZvbGkifQ.XKvRcbkWP9a4J-lfDvcZ6O01patJzvuS1n11d4VPtBQ,eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MjcsImlhdCI6MTcwMzczMjc5MywiZXhwIjoxNzA2MzI0NzkzLCJpc3MiOiJMaUZvbGkifQ.6Pox2D4qm0ABi_w2AjY8hbkbIDODR8arDi7p9pNs12g"
},
"queryStringParameters": null,
"body": {}
}
8 changes: 8 additions & 0 deletions events/auth/get_auth_event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"resource": "/get_auth_event",
"path": "/get_auth_event",
"httpMethod": "GET",
"headers": {},
"queryStringParameters": null,
"body": {}
}
11 changes: 11 additions & 0 deletions events/auth/get_auth_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"resource": "/post_auth_version",
"path": "/post_auth_version",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"os": "ios",
"version": "1.0.12"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_IdDuplicationCheck-Dup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_IdDuplicationCheck",
"path": "/post_auth_IdDuplicationCheck",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"inputId": "sup1214"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_IdDuplicationCheck-long.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_IdDuplicationCheck",
"path": "/post_auth_IdDuplicationCheck",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"inputId": "supasdfasdfsadfsadfsadfsadfsdfasdfsdfsadfasdfsadfarevrbveargaenlbjrelvjnrvjeaborunevjsevnaskjevbaeosijvnsaoevnsejvn1214"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_IdDuplicationCheck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_IdDuplicationCheck",
"path": "/post_auth_IdDuplicationCheck",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"inputId": "su"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_appleLogin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_appleLogin",
"path": "/post_auth_appleLogin",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"apple_id": "000724.0c2036c2d27b4f239826ac8af3fb9de0.0402"
}
}
11 changes: 11 additions & 0 deletions events/auth/post_auth_appleRegister.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"resource": "/post_auth_appleRegister",
"path": "/post_auth_appleRegister",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"apple_id": "000724.0c2036c2d27b4f239826ac8af3fb9de0.0402",
"phone": "01041286666"
}
}
16 changes: 16 additions & 0 deletions events/auth/post_auth_loginKakao.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"resource": "/post_auth_loginKakao",
"path": "/post_auth_loginKakao",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"name": "12eff",
"birthday": "2007-08-22",
"phone": "01044444444",
"gender": "male",
"source_tikkling_id": "34",
"kakao_email": "Ddddd@dddd",
"kakao_image": "https://asdasdasdasd"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_phoneCheck-existNum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_phoneCheck",
"path": "/post_auth_phoneCheck",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"phone": "01011111111"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_phoneCheck-newNum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_phoneCheck",
"path": "/post_auth_phoneCheck",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"phone": "01012347778"
}
}
10 changes: 10 additions & 0 deletions events/auth/post_auth_phoneCheck-wrongFormat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"resource": "/post_auth_phoneCheck",
"path": "/post_auth_phoneCheck",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"phone": "010-1234-7778"
}
}
15 changes: 15 additions & 0 deletions events/auth/post_auth_registerUser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"resource": "/post_auth_registerUser",
"path": "/post_auth_registerUser",
"httpMethod": "POST",
"headers": {},
"queryStringParameters": null,
"body": {
"name": "12e",
"birthday": "2007-08-22",
"nick": "12111",
"phone": "01053783522",
"gender": "male",
"source_tikkling_id": "293"
}
}
Loading

0 comments on commit acd978c

Please sign in to comment.