-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from boostcampwm-2021/dev
version 1.0.0 release
- Loading branch information
Showing
161 changed files
with
6,503 additions
and
21,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const PAGE_LIMIT = 10; | ||
const UPLOAD_LIMIT = 8; | ||
|
||
export { PAGE_LIMIT, UPLOAD_LIMIT }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { IsInt, IsNotEmpty, IsNumberString, IsOptional, IsPositive } from 'class-validator'; | ||
export class CursorPaginationDto { | ||
@IsOptional() | ||
@ApiProperty({ required: false }) | ||
lastId?: number; | ||
|
||
@ApiProperty() | ||
@IsNotEmpty() | ||
limit: number; | ||
@IsOptional() | ||
@IsNumberString() | ||
limit?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { IsOptional } from 'class-validator'; | ||
|
||
export class PaginationQueryDto { | ||
@IsNotEmpty() | ||
@IsOptional() | ||
@ApiProperty() | ||
skip: number; | ||
skip?: number; | ||
|
||
@IsNotEmpty() | ||
@IsOptional() | ||
@ApiProperty() | ||
take: number; | ||
take?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
ExceptionFilter, | ||
Catch, | ||
ArgumentsHost, | ||
HttpException, | ||
HttpStatus, | ||
NotFoundException, | ||
BadRequestException, | ||
UnauthorizedException, | ||
} from '@nestjs/common'; | ||
import { TypeORMError } from 'typeorm'; | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
@Catch() | ||
export class AllExceptionsFilter implements ExceptionFilter { | ||
catch(exception: any, host: ArgumentsHost) { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse(); | ||
const request = ctx.getRequest(); | ||
let message = ''; | ||
let status = 200; | ||
process.env.NODE_ENV === 'dev' && console.log(exception); | ||
if (exception instanceof HttpException) { | ||
status = exception.getStatus(); | ||
message = (exception as any).response.message; | ||
} else if (exception instanceof TypeORMError) { | ||
message = 'DB ์ ๋ฌ์ ๋๋ค.'; | ||
status = HttpStatus.SERVICE_UNAVAILABLE; | ||
} else { | ||
status = HttpStatus.INTERNAL_SERVER_ERROR; | ||
message = 'internal server error'; | ||
} | ||
response.status(status).json({ | ||
statusCode: status, | ||
timestamp: new Date().toISOString(), | ||
path: request.url, | ||
message, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { PipeTransform, Injectable, ArgumentMetadata, BadRequestException } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class ParseOptionalStringPipe implements PipeTransform<string | undefined> { | ||
transform(value: string | undefined, metadata: ArgumentMetadata): string | undefined { | ||
if (!['string', 'undefined'].includes(typeof value)) throw new BadRequestException(); | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config(); | ||
|
||
export const loggerEnv = process.env.NODE_ENV === 'dev' ? 'dev' : 'combined'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { DocumentBuilder } from '@nestjs/swagger'; | ||
|
||
export const SwaggerConfig = new DocumentBuilder() | ||
.setTitle(`PingPing's Friends`) | ||
.setDescription(`The PingPing's friends API description`) | ||
.setVersion('0.1.0') | ||
.addBearerAuth( | ||
{ type: 'http', scheme: 'bearer', bearerFormat: 'JWT', in: 'Header' }, | ||
'access-token' | ||
) | ||
.addCookieAuth('auth-cookie', { | ||
type: 'http', | ||
in: 'Header', | ||
scheme: 'Bearer', | ||
}) | ||
.addTag('pingpings') | ||
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: "3" | ||
services: | ||
db: | ||
image: mysql:5.7.36 | ||
restart: always | ||
command: --lower_case_table_names=1 # ๋์๋ฌธ์ ๊ตฌ๋ถ | ||
container_name: testdb-root | ||
ports: | ||
- "3308:3306" # (์ปจํ ์ด๋ ์ธ๋ถ:์ปจํ ์ด๋ ๋ด๋ถ) | ||
environment: # -e ์ต์ | ||
- MYSQL_DATABASE=sns | ||
- MYSQL_ROOT_PASSWORD=1234 | ||
- TZ=Asia/Seoul | ||
|
||
command: # ๋ช ๋ น์ด ์คํ | ||
- --character-set-server=utf8mb4 | ||
- --collation-server=utf8mb4_unicode_ci | ||
volumes: | ||
- testdb-root-volume:/var/lib/mysql | ||
volumes: | ||
testdb-root-volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import csv | ||
from datetime import datetime | ||
from numpy.core.numeric import False_ | ||
import pandas as pd | ||
from faker import Faker | ||
import data_config | ||
fake = Faker('ko_kr') | ||
|
||
|
||
def get_species_data(): | ||
sound = ['์์', '์บ์บ', '๋ฅ๋ฅ', '์ถ์ด', '์ดํฅ', | ||
"Error!Error", "๊ตฌ๊ตฌ", "๋ฐฅ๋ฐฅ", "ํํ", "ํคํค"] | ||
data = [(sound[fake.pyint(min_value=0, max_value=9)], fake.unique.town()) | ||
for _ in range(100)] | ||
|
||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/species_data.csv") | ||
|
||
|
||
def get_habitat_data(): | ||
|
||
data = [(fake.unique.city(), data_config.color[fake.pyint(min_value=0, max_value=13)], i) | ||
for i in range(50)] | ||
|
||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/habitat_data.csv") | ||
|
||
|
||
def get_user_data(): | ||
|
||
data = [(f"test{i}", data_config.pwd, fake.name(), 1, fake.pyint(min_value=1, max_value=1), i) | ||
for i in range(1, 10000)] | ||
|
||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/user_data.csv") | ||
|
||
|
||
def get_contents_data(): | ||
|
||
data = [(data_config.img_url_arr[fake.pyint(min_value=0, max_value=317)], 'image/webp') | ||
for _ in range(500000)] | ||
|
||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/contents_data.csv") | ||
|
||
|
||
def get_post_data(): | ||
# fake.date_time_between(start_date="-3y", end_date="now") | ||
data = [(fake.bs(), fake.bs(), fake.pyint(min_value=1, max_value=9000), fake.pyint(min_value=1, max_value=49), | ||
fake.date_time_between(start_date="-3y", end_date="now")) | ||
for _ in range(50000)] | ||
data += [(fake.bs(), fake.bs(), fake.pyint(min_value=1, max_value=9000), 1, | ||
fake.date_time_between(start_date="-3y", end_date="now")) | ||
for _ in range(50000)] | ||
data += [(fake.bs(), fake.bs(), fake.pyint(min_value=1, max_value=9000), 1, | ||
fake.date_time_between(start_date="-7d", end_date="now")) | ||
for _ in range(50000)] | ||
data += [(fake.bs(), fake.bs(), fake.pyint(min_value=1, max_value=9000), fake.pyint(min_value=1, max_value=49), | ||
fake.date_time_between(start_date="-7d", end_date="now")) | ||
for _ in range(50000)] | ||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/post_data.csv") | ||
|
||
|
||
def get_post_contents_data(): | ||
# fake.date_time_between(start_date="-3y", end_date="now") | ||
# ๊ฒ์๊ธ๋น ์ด๋ฏธ์ง ์ถ๊ฐ ๋๋ค | ||
data = [(i, i) | ||
for i in range(1, 200001)] | ||
data += [(i-200000, i) | ||
for i in range(200001, 400000)] | ||
data += [(i-400000, i) | ||
for i in range(400001, 500000)] | ||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/post_contents_data.csv", index=False) | ||
|
||
|
||
def get_comments_data(): | ||
# fake.date_time_between(start_date="-3y", end_date="now") | ||
data = [(fake.date_time_between(start_date="-7d", end_date="now"), fake.bs(), fake.pyint(min_value=1, max_value=199999), fake.pyint(min_value=1, max_value=9998)) | ||
for i in range(1, 500000)] | ||
data += [(fake.date_time_between(start_date="-3y", end_date="now"), fake.bs(), fake.pyint(min_value=1, max_value=199999), fake.pyint(min_value=1, max_value=9998)) | ||
for i in range(1, 500000)] | ||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/comments_data.csv") | ||
|
||
|
||
def get_heart_data(): | ||
# fake.date_time_between(start_date="-3y", end_date="now") | ||
data = [(fake.pyint(min_value=1, max_value=9998), fake.pyint(min_value=1, max_value=199999)) | ||
for i in range(1, 2000000)] | ||
data += [(fake.pyint(min_value=1, max_value=9998), fake.pyint(min_value=99999, max_value=149999)) | ||
for i in range(1, 1000000)] | ||
df = pd.DataFrame(data) | ||
df.to_csv("./db/data_csv/heart_data.csv", index=False) | ||
|
||
|
||
# datetime.datetime(2020, 8, 16, 21, 3, 18) | ||
# get_species_data() | ||
# get_habitat_data() | ||
# get_user_data()# 1~9998 | ||
# get_contents_data() # 1~499999 / 1~9999์ ์ ์ ์์์ฌ์ฉ | ||
# get_post_data() # 1~199,999 | ||
# get_post_contents_data() # 1~499999 | ||
# get_comments_data() # 1~9,999,997 | ||
get_heart_data() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable, NestMiddleware } from '@nestjs/common'; | ||
|
||
import { Request, Response } from 'express'; | ||
import { AppLoggingService } from './logger.service'; | ||
|
||
@Injectable() | ||
export class LoggerMiddleware implements NestMiddleware { | ||
constructor() {} | ||
|
||
use(req: Request, res: Response, next: Function) { | ||
const loggerService = new AppLoggingService(req.url.slice(1).split('/')[0]); | ||
const tempUrl = req.method + ' ' + req.url.split('?')[0]; | ||
const _headers = JSON.stringify(req.headers ? req.headers : {}); | ||
const _query = JSON.stringify(req.query ? req.query : {}); | ||
const _body = JSON.stringify(req.body ? req.body : {}); | ||
const _url = JSON.stringify(tempUrl ? tempUrl : {}); | ||
|
||
loggerService.log(`${_url} ${_headers} ${_query} ${_body}`.replace(/\\/, '')); | ||
next(); | ||
} | ||
} |
Oops, something went wrong.