Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/#39
Browse files Browse the repository at this point in the history
  • Loading branch information
dannaward committed Jul 22, 2022
2 parents aabac63 + cfae55d commit 9a1dcf5
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 87 deletions.
58 changes: 50 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Nori-Server with Express
요즘 누가 롯데월드 가나~? 나는 💚nori-dongsan💚 Server로 간다

## 서비스 한 줄 설명
다양한 장난감 정보를 한눈에! 우리 아이 장난감 대여 비교 플랫폼 nori

<img width="1920" alt="노리핵심기능1" src="https://user-images.githubusercontent.com/51286325/180431000-9feb24da-3151-4808-af73-07afaae704d3.png">

<img width="1920" alt="노리핵심기능2" src="https://user-images.githubusercontent.com/51286325/180431050-51978eb0-dd8a-4041-8668-f1a54bdbad87.png">

<img width="1920" alt="노리핵심기능3" src="https://user-images.githubusercontent.com/51286325/180431090-32590bd2-3fc2-4b4f-845f-c022a11960f2.png">

## Member

#### [구건모](https://github.com/gunom)
Expand All @@ -23,19 +32,52 @@

```markdown
📦 src
┣ 📂 config
┣ 📂 constants
┃ 📂 controllers
┣ 📂 dtos
┣ 📂 entities
┣ 📂 interface
┣ 📂 repository
┣ 📂 routes
┣ 📂 service
┣ 📂 middlewares
┣ 📂 modules
┣ 📂 repositories
┣ 📂 services
┣ 📂 utils
┣ 📜 app.ts
┣ 📜 database.ts
┣ 📜 env.ts
┣ 📜 server.ts
┣ 📜 swagger.json
```

## Dependencies Module
```markdown
"dependencies: {
"aws-sdk": "^2.1178.0",
"body-parser": "^1.20.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"class-validator-jsonschema": "^3.1.1",
"cors": "^2.8.5",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"jsonwebtoken": "^8.5.1",
"morgan": "^1.10.0",
"multer": "^1.4.5-lts.1",
"mysql2": "^2.3.3",
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.8.0",
"routing-controllers-openapi": "^1.8.1",
"slack-node": "^0.1.8",
"swagger-ui-express": "^4.1.4",
"ts-node": "^10.8.2",
"typedi": "^0.8.0",
"typeorm": "^0.2.24",
"typeorm-typedi-extensions": "^0.4.1",
"typescript": "^4.7.4",
"winston": "^3.8.1",
"winston-daily-rotate-file": "^4.7.1"
}
```

## 전체 API 로직 구현 진척도
* erd에 맞는 테이블 세팅 완료
* API 코드 작성 0% -> 2022.07.17일까지 구현 완료 예정
* API 코드 작성 100%

[API 명세서](https://happy-elephant-0ba.notion.site/API-066af5edeae34f01b3a6c098ac95cda6)
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"license": "MIT",
"scripts": {
"dev": "nodemon --watch 'src/**/*' --exec ts-node src/server.ts",
"start": "node dist/server.js",
"build": "tsc",
"start": "ts-node dist/server.js",
"build": "tsc && node dist/server.js",
"postinstall": "npm run build",
"test": "jest --coverage --verbose",
"test:clear": "jest --clearCache"
Expand Down
66 changes: 25 additions & 41 deletions src/controllers/AuthController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,57 +57,41 @@ export class AuthController {
const createUserDto = new CreateUserDto(snsId, email, provider);

try {
const user = await this.authService.validateUserBySnsId(
let user = await this.authService.validateUserBySnsId(
createUserDto.snsId
);

// 이미 가입이 된 유저일 때
if (user) {
let responseUserDto: ResponseUserDto = {
accessToken: generateAccessToken(user),
refreshToken: generateRefreshToken(user),
isSignup: false,
};
await this.authService.saveRefreshToken(
user,
responseUserDto.refreshToken
);

// 회원가입을 완료한 유저인지 확인
if (user.nickname) {
responseUserDto.isSignup = true;
}

return res
.status(statusCode.OK)
.send(
util.success(statusCode.OK, message.LOGIN_SUCCESS, responseUserDto)
);
} else {
// 신규 가입 유저
if (!user) {
const newUser = await this.userService.create(createUserDto);
if (!newUser) {
if (!newUser)
return res
.status(statusCode.DB_ERROR)
.send(util.fail(statusCode.DB_ERROR, message.CREATE_USER_FAIL));

user = await this.authService.validateUserBySnsId(createUserDto.snsId);
if (!user) {
return res
.status(statusCode.DB_ERROR)
.send(util.fail(statusCode.DB_ERROR, message.NONEXIST_USER));
}
}

const responseUserDto: ResponseUserDto = {
accessToken: generateAccessToken(newUser),
refreshToken: generateRefreshToken(newUser),
isSignup: false,
};
await this.authService.saveRefreshToken(
newUser,
responseUserDto.refreshToken
);
const responseUserDto: ResponseUserDto = {
accessToken: generateAccessToken(user),
refreshToken: generateRefreshToken(user),
isSignup: user?.nickname ? true : false,
};

return res
.status(statusCode.OK)
.send(
util.success(statusCode.OK, message.LOGIN_SUCCESS, responseUserDto)
);
}
await this.authService.saveRefreshToken(
user,
responseUserDto.refreshToken
);

return res
.status(statusCode.OK)
.send(
util.success(statusCode.OK, message.LOGIN_SUCCESS, responseUserDto)
);
} catch (error) {
logger.error(error);
console.log(error);
Expand Down
9 changes: 5 additions & 4 deletions src/controllers/BoardController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ export class BoardController {
statusCode: '200',
})
public async getList(
@Res() res: Response,
@QueryParam('page') page: number
@Res() res: Response
): Promise<Response> {
try {
const boards = await this.boardService.getList(page);
const boards = await this.boardService.getList();
return res
.status(statusCode.CREATED)
.send(
Expand Down Expand Up @@ -198,7 +197,7 @@ export class BoardController {
@Param('boardId') boardId: number,
@UploadedFiles('imageList') files?: Express.Multer.File[]
) {
const { title, content } = req.body;
const { title, content, category } = req.body;
try {
const boardPutDto = new BoardPutDto();
boardPutDto.boardId = boardId;
Expand All @@ -207,6 +206,8 @@ export class BoardController {
else boardPutDto.title = board!.title;
if (content) boardPutDto.content = content;
else boardPutDto.content = board!.content;
if (category) boardPutDto.section = category
else boardPutDto.section = board!.section

await this.boardService.put(boardPutDto);
if (files) {
Expand Down
9 changes: 3 additions & 6 deletions src/controllers/ToyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ export class ToyController {
statusCode: '200',
})
public async searchAndFilter(
@QueryParam('page') page: number,
@Req()
req: Request,
@Res() res: Response
): Promise<Response> {
const { categoryId } = req.params;
const offSet = page;
const searchAndFilterDto: SearchAndFilterDto = req.query;

try {
const searchAndFilterList = await this.toyService.searchAndFilter(
offSet,
categoryId,
searchAndFilterDto
);
Expand Down Expand Up @@ -75,17 +72,17 @@ export class ToyController {
statusCode: '200',
})
public async searchAndFilterNonCategory(
@QueryParam('page') page: number,
// @QueryParam('page') page: number,
@Req() req: Request,
@Res() res: Response
): Promise<Response> {
const offSet = page;
// const offSet = page;
const searchAndFilterDto: SearchAndFilterDto = req.query;

try {
const searchAndFilterList =
await this.toyService.searchAndFilterNonCategory(
offSet,
// offSet,
searchAndFilterDto
);

Expand Down
1 change: 1 addition & 0 deletions src/dtos/BoardDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class BoardDto {

export class BoardPutDto {
boardId: number;
section?: string;
content?: string;
title?: string;
}
Expand Down
7 changes: 4 additions & 3 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const env = {
app: {
port: Number(process.env.PORT) || 8080,
apiPrefix: process.env.API_PREFIX || '/api',
ec2Instance: process.env.INSTANCE,
jwtAccessSecret: process.env.JWT_SECRET_ACCESS_KEY,
jwtRefreshSecret: process.env.JWT_SECRET_REFRESH_KEY,
},
Expand All @@ -33,9 +34,9 @@ export const env = {
s3: {
accessKey: process.env.AWS_ACCESS_KEY,
secretKey: process.env.AWS_SECRET_KEY,
bucketName: process.env.BUCKET_NAME
bucketName: process.env.BUCKET_NAME,
},
slack: {
webhookUrl: process.env.SLACK_WEBHOOK
}
webhookUrl: process.env.SLACK_WEBHOOK,
},
};
5 changes: 2 additions & 3 deletions src/services/BoardService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ export class BoardService {
/**
* 게시판 목록 조회
*/
public async getList(page: number): Promise<BoardDto[]> {
public async getList(): Promise<BoardDto[]> {
const boards = await this.boardRepository.find({
skip: (page - 1) * 10,
take: 10,
relations: ['user', 'boardComments', 'boardImages'],
});

Expand Down Expand Up @@ -85,6 +83,7 @@ export class BoardService {
await this.boardRepository.update(boardPutDto.boardId, {
content: boardPutDto.content,
title: boardPutDto.title,
section: boardPutDto.section
});
} catch (err) {
logger.error(err);
Expand Down
8 changes: 4 additions & 4 deletions src/services/HomeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export class HomeService {
public async fetchList(): Promise<ResponseHomeDto> {
let homeToys = new ResponseHomeDto();

homeToys.trending = await this.fetchToys([1193, 1269, 1028]);
homeToys.trending = await this.fetchToys([3017, 2769, 2881]);
homeToys.theme = await this.fetchThemes();
homeToys.noriPick = await this.fetchToys([1233, 1431, 1339, 1276]);
homeToys.senses = await this.fetchToys([1081, 1356, 1311, 1308]);
homeToys.smart = await this.fetchToys([1032, 1191, 1159, 1169]);
homeToys.noriPick = await this.fetchToys([2733, 2878, 2971, 2776]);
homeToys.senses = await this.fetchToys([2767, 2989, 2943, 2941]);
homeToys.smart = await this.fetchToys([2889, 2826, 2789, 2804]);

return homeToys;
}
Expand Down
Loading

0 comments on commit 9a1dcf5

Please sign in to comment.