Skip to content

Commit

Permalink
feat: #36 Emotion & Posting 연동 및 Swagger 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoiYongWon committed Dec 7, 2022
1 parent 407fbb2 commit 7c8d5e3
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 130 deletions.
52 changes: 45 additions & 7 deletions src/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
Patch,
Post,
} from '@nestjs/common';
import { ApiBearerAuth, ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiCreatedResponse,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
import { RolesGuard } from 'src/auth/guards/roles.guard';
import { Roles } from 'src/libs/decorators/roles.decorator';
Expand Down Expand Up @@ -45,6 +50,9 @@ export class AdminController {
) {}

@Get('/all')
@ApiOperation({
summary: '모든 어드민을 조회합니다.',
})
@Roles([Role.Admin])
async login(@Request() req) {
return await this.adminService.findAll();
Expand All @@ -54,13 +62,19 @@ export class AdminController {

// 생성
@Post('/user')
@ApiOperation({
summary: '새로운 유저를 생성합니다.',
})
@Roles([Role.Admin])
async createUser(@Body() createUserData: RequestCreateUserDto) {
return await this.userService.create(createUserData);
}

// 조회
@Get('/user/all')
@ApiOperation({
summary: '모든 유저를 조회합니다.',
})
@ApiCreatedResponse({
status: 200,
type: ResponseReadAllUserDto,
Expand All @@ -72,17 +86,22 @@ export class AdminController {
}

@Get('/user')
@ApiOperation({
summary: '특정 유저를 조회합니다.',
})
@ApiCreatedResponse({ status: 200, type: ResponseReadUserDto })
@Roles([Role.Admin])
async getUser(@Query('user_id') userID: string) {
return await this.userService.findOne(userID);
}

@Get('/userAT')
@ApiOperation({
summary: '특정 유저의 access_token을 얻을 수 있습니다.',
})
@ApiCreatedResponse({
status: 200,
type: ResponseGetUserATDto,
description: '해당 유저의 access_token을 얻을수있습니다.',
})
@Roles([Role.Admin])
async getUserAT(@Query('user_id') userID: string) {
Expand All @@ -91,13 +110,19 @@ export class AdminController {

// 수정
@Patch('/user')
@ApiOperation({
summary: '특정 유저 정보를 수정합니다.',
})
@Roles([Role.Admin])
async patchUser(@Body() body: RequestUpdateUserDto) {
return await this.userService.update(body.user_id, body);
}

// 삭제
@Delete('/user')
@ApiOperation({
summary: '특정 유저를 삭제합니다.',
})
@Roles([Role.Admin])
async removeUser(@Body() body: RequestDeleteUserDto) {
return await this.userService.delete(body.user_id);
Expand All @@ -106,10 +131,12 @@ export class AdminController {
/* Friends 제어 */

@Get('/friends/all')
@ApiOperation({
summary: '모든 친구 관계를 조회합니다.',
})
@ApiCreatedResponse({
status: 200,
type: ResponseGetAllFriendByAdminDto,
description: '모든 친구 요청 목록을 조회합니다.',
isArray: true,
})
@Roles([Role.Admin])
Expand All @@ -118,9 +145,11 @@ export class AdminController {
}

@Patch('/friends')
@ApiOperation({
summary: '친구 관계를 수정합니다.',
})
@ApiCreatedResponse({
status: 200,
description: '친구 목록에서 관계를 수정합니다.',
})
@Roles([Role.Admin])
async updateFriendRelation(@Body() body: RequestUpdateFriendRelationDto) {
Expand All @@ -131,9 +160,11 @@ export class AdminController {
}

@Delete('/friends')
@ApiOperation({
summary: '특정 친구 관계를 삭제합니다.',
})
@ApiCreatedResponse({
status: 200,
description: '특정 친구 관계를 삭제합니다.',
})
@Roles([Role.Admin])
async deleteFriendRelation(@Body() body: RequestUpdateFriendRelationDto) {
Expand All @@ -143,10 +174,12 @@ export class AdminController {
/* Posting 제어 */

@Get('/post/all')
@ApiOperation({
summary: '모든 우연 목록을 조회합니다.',
})
@ApiCreatedResponse({
status: 200,
type: ResponseGetAllPostDto,
description: '모든 우연 목록을 조회합니다.',
isArray: true,
})
@Roles([Role.Admin])
Expand All @@ -155,16 +188,21 @@ export class AdminController {
}

@Patch('/post')
@ApiOperation({
summary: '특정 우연을 수정합니다.',
})
@ApiCreatedResponse({
status: 200,
description: '특정 우연을 수정합니다.',
})
@Roles([Role.Admin])
async updatePost(@Body() body: RequestUpdatePostDto) {
return await this.postingService.updatePost_Admin(body);
}

@Delete('/post')
@ApiOperation({
summary: '특정 우연을 삭제합니다.',
})
@ApiCreatedResponse({
status: 200,
description: '특정 우연을 삭제합니다.',
Expand Down
20 changes: 5 additions & 15 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
import {
Controller,
Request,
Get,
Logger,
Post,
UseGuards,
} from '@nestjs/common';
import { Controller, Get } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { AppService } from './app.service';
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get('healthcheck')
@ApiOperation({
summary: 'healthcheck url 입니다.',
})
healthCheck(): string {
return this.appService.getHealthCheck();
}

@Get()
getHello(): string {
Logger.log(`${process.env.DB_URL}`);
return this.appService.getHello();
}
}
37 changes: 23 additions & 14 deletions src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@nestjs/common';
import { LocalAuthGuard } from './guards/local-auth.guard';
import { AuthService } from './auth.service';
import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { ResponseAdminLoginDto } from './dto/ResponseAdminLogin.dto';
import { KakaoAuthGuard } from './guards/kakao-auth.guard';
import { ResponseUserLoginDto } from './dto/ResponseUserLogin.dto';
Expand All @@ -21,12 +21,13 @@ import { Response } from 'express';
@ApiTags('auth')
@Controller('auth')
export class AuthController {
constructor(
private authService: AuthService
) {}
constructor(private authService: AuthService) {}

@ApiOperation({
summary: '어드민 로그인',
})
@Post('/admin')
@ApiCreatedResponse({ status: 200, type: ResponseAdminLoginDto , description: "어드민 로그인"})
@ApiCreatedResponse({ status: 200, type: ResponseAdminLoginDto })
@UseGuards(LocalAuthGuard)
async login(
@Request() req,
Expand All @@ -37,19 +38,27 @@ export class AuthController {
}

@Get('/kakao')
@ApiCreatedResponse({ status: 200, type: ResponseUserLoginDto, description: "유저 카카오 소셜로그인"})
@ApiOperation({
summary: '유저 카카오 소셜 로그인.',
})
@ApiCreatedResponse({ status: 200, type: ResponseUserLoginDto })
@UseGuards(KakaoAuthGuard)
async kakaoLogin(){
return HttpStatus.OK
async kakaoLogin() {
return HttpStatus.OK;
}

@Get('/kakao/oauth')
@ApiOperation({
summary: '카카오 Redirect URL.',
})
@UseGuards(KakaoAuthGuard)
async kakaoRedirect(@Req() req, @Res() res: Response){
if(req.user.email == null){
return HttpStatus.NOT_ACCEPTABLE
}
const result = await this.authService.userLogin(req.user)
res.redirect(`${process.env.CLIENT_URL}/auth/kakao/redirect?access_token=${result.access_token}`)
async kakaoRedirect(@Req() req, @Res() res: Response) {
if (req.user.email == null) {
return HttpStatus.NOT_ACCEPTABLE;
}
const result = await this.authService.userLogin(req.user);
res.redirect(
`${process.env.CLIENT_URL}/auth/kakao/redirect?access_token=${result.access_token}`,
);
}
}
6 changes: 3 additions & 3 deletions src/emotion/dto/RequestAddEmotion.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';

export class RequestAddEmotionDto {

@ApiProperty()
post_id: string;

@ApiProperty()
@ApiProperty({
description: '(0: 좋아요, 1: 멋져요, 2: 슬퍼요)',
})
emotion_type: number;

}
Loading

0 comments on commit 7c8d5e3

Please sign in to comment.