Skip to content

Commit

Permalink
Merge pull request #238 from tmddus2/feature/231117-login
Browse files Browse the repository at this point in the history
Refactor: ResponseDto ์ถ”๊ฐ€ ๋ฐ ์ฝ”๋“œ์ปจ๋ฒค์…˜ ์ ์šฉ
  • Loading branch information
platinouss authored Dec 9, 2023
2 parents 00b2d50 + 721d5e3 commit c098181
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 8 deletions.
12 changes: 7 additions & 5 deletions backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res, UseGuards } from '@nestjs/common';
import { ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ApiBody, ApiHeader, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Response } from 'express';
import { CustomAuthGuard } from './auth.guard';
import { AuthService } from './auth.service';
import { SignInDto } from './dto/auth.signin.dto';
import { SignUpDto } from './dto/auth.signup.dto';
import { ResponseSignInDto } from './dto/response-signin.dto';
import { SignInDto } from './dto/sign-in.dto';
import { SignUpDto } from './dto/sign-up.dto';

@ApiTags('auth')
@Controller('auth')
Expand All @@ -25,17 +26,18 @@ export class AuthController {

@Post('/signin')
@ApiBody({ type: SignInDto })
@ApiResponse({ status: 200 })
@ApiResponse({ status: 200, type: ResponseSignInDto })
@ApiResponse({ status: 404, description: 'ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.' })
async signIn(@Body() signInDto: SignInDto, @Res() res: Response) {
const user = this.authService.findUserByEmail(signInDto.email);
if (!user) {
throw new HttpException('ํ•ด๋‹น ์‚ฌ์šฉ์ž๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.', HttpStatus.NOT_FOUND);
}
const result = await this.authService.signIn(signInDto);
return res.status(HttpStatus.OK).send({ token: result });
return res.status(HttpStatus.OK).send(new ResponseSignInDto(result));
}

@ApiHeader({ name: 'Authorization' })
@UseGuards(CustomAuthGuard)
@Get('profile')
getProfile(@Req() req: any) {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { JwtService } from '@nestjs/jwt';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { User } from 'src/user/user.schema';
import { SignUpDto } from './dto/auth.signup.dto';
import { SignInDto } from './dto/auth.signin.dto';
import { ConfigService } from '@nestjs/config';
import { decryptPassword, encryptPassword } from 'src/utils/GenerateUtils';
import { SignUpDto } from './dto/sign-up.dto';
import { SignInDto } from './dto/sign-in.dto';

@Injectable()
export class AuthService {
Expand Down
10 changes: 10 additions & 0 deletions backend/src/auth/dto/response-signin.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';

export class ResponseSignInDto {
@ApiProperty()
token: string;

constructor(token: string) {
this.token = token;
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Body, Controller, Get, HttpException, HttpStatus, Post, Req, Res, UseGu
import { Response } from 'express';
import { UserService } from './user.service';
import { UserInfoDto } from '../auth/dto/userInfo.dto';
import { UserUpdateDto } from './dto/user.update.dto';
import { ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CustomAuthGuard } from 'src/auth/auth.guard';
import { UserUpdateDto } from './dto/update-user.dto';

@ApiTags('profile')
@Controller('/profile')
Expand Down

0 comments on commit c098181

Please sign in to comment.