From 7e4ff947ea06bbc38471d51bd0062d4c74b7c8fd Mon Sep 17 00:00:00 2001 From: asn6878 Date: Tue, 3 Dec 2024 03:26:54 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20admin=20co?= =?UTF-8?q?ntroller,=20service,=20api-docs=20=EB=A9=94=EC=84=9C=EB=93=9C?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20dao=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/admin.api-docs.ts | 135 ------------------ server/src/admin/admin.controller.ts | 24 ++-- server/src/admin/admin.repository.ts | 6 + server/src/admin/admin.service.ts | 15 +- .../admin/api-docs/createAdmin.api-docs.ts | 47 ++++++ .../api-docs/getSessionIdAdmin.api-docs.ts | 60 ++++++++ .../src/admin/api-docs/loginAdmin.api-docs.ts | 40 ++++++ .../admin/api-docs/logoutAdmin.api-docs.ts | 33 +++++ 8 files changed, 203 insertions(+), 157 deletions(-) delete mode 100644 server/src/admin/admin.api-docs.ts create mode 100644 server/src/admin/api-docs/createAdmin.api-docs.ts create mode 100644 server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts create mode 100644 server/src/admin/api-docs/loginAdmin.api-docs.ts create mode 100644 server/src/admin/api-docs/logoutAdmin.api-docs.ts diff --git a/server/src/admin/admin.api-docs.ts b/server/src/admin/admin.api-docs.ts deleted file mode 100644 index d2c73be4..00000000 --- a/server/src/admin/admin.api-docs.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { - ApiBadRequestResponse, - ApiConflictResponse, - ApiCreatedResponse, - ApiOkResponse, - ApiOperation, - ApiUnauthorizedResponse, -} from '@nestjs/swagger'; -import { applyDecorators } from '@nestjs/common'; - -export function ApiPostRegisterAdmin() { - return applyDecorators( - ApiOperation({ - summary: `관리자 회원 가입 API`, - }), - ApiCreatedResponse({ - description: 'Created', - schema: { - properties: { - message: { - type: 'string', - }, - }, - }, - example: { - message: '성공적으로 관리자 계정이 생성되었습니다.', - }, - }), - ApiBadRequestResponse({ - description: 'Bad Request', - example: { - message: '오류 메세지', - }, - }), - ApiConflictResponse({ - description: 'Conflict', - example: { - message: '이미 존재하는 계정입니다.', - }, - }), - ApiUnauthorizedResponse({ - description: 'Unauthorized', - example: { - message: '인증되지 않은 요청입니다.', - }, - }), - ); -} - -export function ApiPostLoginAdmin() { - return applyDecorators( - ApiOperation({ - summary: `관리자 로그인 API`, - }), - ApiOkResponse({ - description: 'Ok', - schema: { - properties: { - message: { - type: 'string', - }, - }, - }, - example: { - message: '로그인이 성공적으로 처리되었습니다.', - }, - }), - ApiBadRequestResponse({ - description: 'Bad Request', - example: { - message: '오류 메세지', - }, - }), - ApiUnauthorizedResponse({ - description: 'Unauthorized', - example: { - message: '아이디 혹은 비밀번호가 잘못되었습니다.', - }, - }), - ); -} - -export function ApiCheckAdminSessionId() { - return applyDecorators( - ApiOperation({ - summary: `관리자 페이지 출력을 위한 sessionId 확인 API`, - }), - ApiOkResponse({ - description: 'Ok', - schema: { - properties: { - message: { - type: 'string', - }, - }, - }, - example: { - message: '정상적인 sessionId입니다.', - }, - }), - ApiUnauthorizedResponse({ - description: 'Unauthorized', - example: { - message: '인증되지 않은 요청입니다.', - }, - }), - ); -} - -export function ApiLogout() { - return applyDecorators( - ApiOperation({ - summary: '관리자 로그아웃 API', - }), - ApiOkResponse({ - description: 'Ok', - schema: { - properties: { - message: { - type: 'string', - }, - }, - }, - example: { - message: '로그아웃이 성공적으로 처리되었습니다.', - }, - }), - ApiUnauthorizedResponse({ - description: 'Unauthorized', - example: { - message: '인증되지 않은 요청입니다.', - }, - }), - ); -} diff --git a/server/src/admin/admin.controller.ts b/server/src/admin/admin.controller.ts index 9d5f0da8..42349965 100644 --- a/server/src/admin/admin.controller.ts +++ b/server/src/admin/admin.controller.ts @@ -15,22 +15,20 @@ import { Request, Response } from 'express'; import { AdminService } from './admin.service'; import { RegisterAdminDto } from './dto/register-admin.dto'; import { ApiTags } from '@nestjs/swagger'; -import { - ApiCheckAdminSessionId, - ApiLogout, - ApiPostLoginAdmin, - ApiPostRegisterAdmin, -} from './admin.api-docs'; import { ApiResponse } from '../common/response/common.response'; import { LoginAdminDto } from './dto/login-admin.dto'; import { CookieAuthGuard } from '../common/guard/auth.guard'; +import { ApiLoginAdmin } from './api-docs/loginAdmin.api-docs'; +import { ApigetSessionIdAdmin } from './api-docs/getSessionIdAdmin.api-docs'; +import { ApiLogoutAdmin } from './api-docs/logoutAdmin.api-docs'; +import { ApiCreateAdmin } from './api-docs/createAdmin.api-docs'; @ApiTags('Admin') @Controller('admin') export class AdminController { constructor(private readonly adminService: AdminService) {} - @ApiPostLoginAdmin() + @ApiLoginAdmin() @Post('/login') @HttpCode(HttpStatus.OK) @UsePipes(ValidationPipe) @@ -45,7 +43,7 @@ export class AdminController { ); } - @ApiLogout() + @ApiLogoutAdmin() @UseGuards(CookieAuthGuard) @Post('/logout') async logoutAdmin( @@ -59,23 +57,23 @@ export class AdminController { ); } - @ApiPostRegisterAdmin() + @ApiCreateAdmin() @UseGuards(CookieAuthGuard) @Post('/register') @UsePipes(ValidationPipe) - async registerAdmin(@Body() registerAdminDto: RegisterAdminDto) { - await this.adminService.registerAdmin(registerAdminDto); + async createAdmin(@Body() registerAdminDto: RegisterAdminDto) { + await this.adminService.createAdmin(registerAdminDto); return ApiResponse.responseWithNoContent( '성공적으로 관리자 계정이 생성되었습니다.', ); } - @ApiCheckAdminSessionId() + @ApigetSessionIdAdmin() @Get('/sessionId') @HttpCode(HttpStatus.OK) @UseGuards(CookieAuthGuard) @UsePipes(new ValidationPipe({ transform: true })) - async checkAdminSessionId() { + async getSessionIdAdmin() { return ApiResponse.responseWithNoContent('정상적인 sessionId 입니다.'); } } diff --git a/server/src/admin/admin.repository.ts b/server/src/admin/admin.repository.ts index ea93393b..1d3a4f3f 100644 --- a/server/src/admin/admin.repository.ts +++ b/server/src/admin/admin.repository.ts @@ -18,4 +18,10 @@ export class AdminRepository extends Repository { await this.save(admin); return admin; } + + async findAdminByLoginId(loginId: string) { + return await this.findOne({ + where: { loginId }, + }); + } } diff --git a/server/src/admin/admin.service.ts b/server/src/admin/admin.service.ts index 3f7993d8..889723ea 100644 --- a/server/src/admin/admin.service.ts +++ b/server/src/admin/admin.service.ts @@ -18,7 +18,7 @@ export class AdminService { private readonly SESSION_TTL = 60 * 60 * 12; constructor( - private readonly loginRepository: AdminRepository, + private readonly adminRepository: AdminRepository, private readonly redisService: RedisService, ) {} @@ -30,9 +30,7 @@ export class AdminService { const cookie = request.cookies['sessionId']; const { loginId, password } = loginAdminDto; - const admin = await this.loginRepository.findOne({ - where: { loginId }, - }); + const admin = await this.adminRepository.findAdminByLoginId(loginId); if (!admin || !(await bcrypt.compare(password, admin.password))) { throw new UnauthorizedException('아이디 혹은 비밀번호가 잘못되었습니다.'); @@ -92,12 +90,11 @@ export class AdminService { response.clearCookie('sessionId'); } - async registerAdmin(registerAdminDto: RegisterAdminDto) { + async createAdmin(registerAdminDto: RegisterAdminDto) { let { loginId, password } = registerAdminDto; - const existingAdmin = await this.loginRepository.findOne({ - where: { loginId }, - }); + const existingAdmin = + await this.adminRepository.findAdminByLoginId(loginId); if (existingAdmin) { throw new ConflictException('이미 존재하는 아이디입니다.'); @@ -106,6 +103,6 @@ export class AdminService { const saltRounds = 10; password = await bcrypt.hash(password, saltRounds); - return this.loginRepository.registerAdmin({ loginId, password }); + return this.adminRepository.registerAdmin({ loginId, password }); } } diff --git a/server/src/admin/api-docs/createAdmin.api-docs.ts b/server/src/admin/api-docs/createAdmin.api-docs.ts new file mode 100644 index 00000000..13ce8c72 --- /dev/null +++ b/server/src/admin/api-docs/createAdmin.api-docs.ts @@ -0,0 +1,47 @@ +import { applyDecorators } from '@nestjs/common'; +import { + ApiBadRequestResponse, + ApiConflictResponse, + ApiCreatedResponse, + ApiOperation, + ApiUnauthorizedResponse, +} from '@nestjs/swagger'; + +export function ApiCreateAdmin() { + return applyDecorators( + ApiOperation({ + summary: `관리자 회원 가입 API`, + }), + ApiCreatedResponse({ + description: 'Created', + schema: { + properties: { + message: { + type: 'string', + }, + }, + }, + example: { + message: '성공적으로 관리자 계정이 생성되었습니다.', + }, + }), + ApiBadRequestResponse({ + description: 'Bad Request', + example: { + message: '오류 메세지', + }, + }), + ApiConflictResponse({ + description: 'Conflict', + example: { + message: '이미 존재하는 계정입니다.', + }, + }), + ApiUnauthorizedResponse({ + description: 'Unauthorized', + example: { + message: '인증되지 않은 요청입니다.', + }, + }), + ); +} diff --git a/server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts b/server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts new file mode 100644 index 00000000..9a78acaa --- /dev/null +++ b/server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts @@ -0,0 +1,60 @@ +import { applyDecorators } from '@nestjs/common'; +import { + ApiOkResponse, + ApiOperation, + ApiUnauthorizedResponse, +} from '@nestjs/swagger'; + +export function ApigetSessionIdAdmin() { + return applyDecorators( + ApiOperation({ + summary: `관리자 페이지 출력을 위한 sessionId 확인 API`, + }), + ApiOkResponse({ + description: 'Ok', + schema: { + properties: { + message: { + type: 'string', + }, + }, + }, + example: { + message: '정상적인 sessionId입니다.', + }, + }), + ApiUnauthorizedResponse({ + description: 'Unauthorized', + example: { + message: '인증되지 않은 요청입니다.', + }, + }), + ); +} + +export function ApiLogout() { + return applyDecorators( + ApiOperation({ + summary: '관리자 로그아웃 API', + }), + ApiOkResponse({ + description: 'Ok', + schema: { + properties: { + message: { + type: 'string', + }, + }, + }, + example: { + message: '로그아웃이 성공적으로 처리되었습니다.', + }, + }), + ApiUnauthorizedResponse({ + description: 'Unauthorized', + example: { + message: '인증되지 않은 요청입니다.', + }, + }), + ); +} diff --git a/server/src/admin/api-docs/loginAdmin.api-docs.ts b/server/src/admin/api-docs/loginAdmin.api-docs.ts new file mode 100644 index 00000000..a7fb7a98 --- /dev/null +++ b/server/src/admin/api-docs/loginAdmin.api-docs.ts @@ -0,0 +1,40 @@ +import { applyDecorators } from '@nestjs/common'; +import { + ApiBadRequestResponse, + ApiOkResponse, + ApiOperation, + ApiUnauthorizedResponse, +} from '@nestjs/swagger'; + +export function ApiLoginAdmin() { + return applyDecorators( + ApiOperation({ + summary: `관리자 로그인 API`, + }), + ApiOkResponse({ + description: 'Ok', + schema: { + properties: { + message: { + type: 'string', + }, + }, + }, + example: { + message: '로그인이 성공적으로 처리되었습니다.', + }, + }), + ApiBadRequestResponse({ + description: 'Bad Request', + example: { + message: '오류 메세지', + }, + }), + ApiUnauthorizedResponse({ + description: 'Unauthorized', + example: { + message: '아이디 혹은 비밀번호가 잘못되었습니다.', + }, + }), + ); +} diff --git a/server/src/admin/api-docs/logoutAdmin.api-docs.ts b/server/src/admin/api-docs/logoutAdmin.api-docs.ts new file mode 100644 index 00000000..343b242b --- /dev/null +++ b/server/src/admin/api-docs/logoutAdmin.api-docs.ts @@ -0,0 +1,33 @@ +import { + ApiOkResponse, + ApiOperation, + ApiUnauthorizedResponse, +} from '@nestjs/swagger'; +import { applyDecorators } from '@nestjs/common'; + +export function ApiLogoutAdmin() { + return applyDecorators( + ApiOperation({ + summary: '관리자 로그아웃 API', + }), + ApiOkResponse({ + description: 'Ok', + schema: { + properties: { + message: { + type: 'string', + }, + }, + }, + example: { + message: '로그아웃이 성공적으로 처리되었습니다.', + }, + }), + ApiUnauthorizedResponse({ + description: 'Unauthorized', + example: { + message: '인증되지 않은 요청입니다.', + }, + }), + ); +} From be14d5636dd0e8fca28bb32c31551fc36538f4cb Mon Sep 17 00:00:00 2001 From: asn6878 Date: Tue, 3 Dec 2024 03:36:59 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20statistic?= =?UTF-8?q?=20controller,=20service,=20api-docs=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20dao=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/feed/feed.repository.ts | 10 +++++ .../readPlatformStatistic.api-docs.ts | 42 +++++++++++++++++++ .../{ => api-docs}/statistic.api-docs.ts | 42 ------------------- server/src/statistic/statistic.controller.ts | 19 ++++----- server/src/statistic/statistic.service.ts | 15 +++---- 5 files changed, 66 insertions(+), 62 deletions(-) create mode 100644 server/src/statistic/api-docs/readPlatformStatistic.api-docs.ts rename server/src/statistic/{ => api-docs}/statistic.api-docs.ts (63%) diff --git a/server/src/feed/feed.repository.ts b/server/src/feed/feed.repository.ts index 480059c6..416de0d8 100644 --- a/server/src/feed/feed.repository.ts +++ b/server/src/feed/feed.repository.ts @@ -26,4 +26,14 @@ export class FeedRepository extends Repository { relations: ['blog'], }); } + + async findAllStatisticsOrderByViewCount(limit: number) { + return this.find({ + select: ['id', 'title', 'viewCount'], + order: { + viewCount: 'DESC', + }, + take: limit, + }); + } } diff --git a/server/src/statistic/api-docs/readPlatformStatistic.api-docs.ts b/server/src/statistic/api-docs/readPlatformStatistic.api-docs.ts new file mode 100644 index 00000000..01b60e8f --- /dev/null +++ b/server/src/statistic/api-docs/readPlatformStatistic.api-docs.ts @@ -0,0 +1,42 @@ +import { applyDecorators } from '@nestjs/common'; +import { ApiOkResponse, ApiOperation } from '@nestjs/swagger'; + +export function ApiReadPlatformStatistic() { + return applyDecorators( + ApiOperation({ + summary: '블로그 플랫폼 통계 조회 API', + }), + ApiOkResponse({ + description: 'Ok', + schema: { + properties: { + message: { + type: 'string', + }, + data: { + type: 'array', + items: { + properties: { + platform: { + type: 'string', + }, + count: { + type: 'number', + }, + }, + }, + }, + }, + }, + example: { + message: '블로그 플랫폼 통계 조회 완료', + data: [ + { + platform: 'test', + count: 30, + }, + ], + }, + }), + ); +} diff --git a/server/src/statistic/statistic.api-docs.ts b/server/src/statistic/api-docs/statistic.api-docs.ts similarity index 63% rename from server/src/statistic/statistic.api-docs.ts rename to server/src/statistic/api-docs/statistic.api-docs.ts index dd42bc70..f3fc00d1 100644 --- a/server/src/statistic/statistic.api-docs.ts +++ b/server/src/statistic/api-docs/statistic.api-docs.ts @@ -4,10 +4,8 @@ import { ApiOkResponse, ApiOperation, ApiQuery, - ApiUnauthorizedResponse, } from '@nestjs/swagger'; - export function ApiStatistic(category: 'today' | 'all') { const type = category === 'all' ? '전체' : '금일'; return applyDecorators( @@ -66,43 +64,3 @@ export function ApiStatistic(category: 'today' | 'all') { }), ); } - -export function ApiPlatformStatistic() { - return applyDecorators( - ApiOperation({ - summary: '블로그 플랫폼 통계 조회 API', - }), - ApiOkResponse({ - description: 'Ok', - schema: { - properties: { - message: { - type: 'string', - }, - data: { - type: 'array', - items: { - properties: { - platform: { - type: 'string', - }, - count: { - type: 'number', - }, - }, - }, - }, - }, - }, - example: { - message: '블로그 플랫폼 통계 조회 완료', - data: [ - { - platform: 'test', - count: 30, - }, - ], - }, - }), - ); -} diff --git a/server/src/statistic/statistic.controller.ts b/server/src/statistic/statistic.controller.ts index 8848b929..3def17ea 100644 --- a/server/src/statistic/statistic.controller.ts +++ b/server/src/statistic/statistic.controller.ts @@ -2,16 +2,15 @@ import { Controller, Get, Query, - UseGuards, UsePipes, ValidationPipe, } from '@nestjs/common'; -import { ApiPlatformStatistic, ApiStatistic } from './statistic.api-docs'; import { StatisticService } from './statistic.service'; import { ApiResponse } from '../common/response/common.response'; import { ApiTags } from '@nestjs/swagger'; -import { CookieAuthGuard } from '../common/guard/auth.guard'; import { StatisticQueryDto } from './dto/statistic-query.dto'; +import { ApiReadPlatformStatistic } from './api-docs/readPlatformStatistic.api-docs'; +import { ApiStatistic } from './api-docs/statistic.api-docs'; @ApiTags('Statistic') @Controller('statistic') @@ -25,8 +24,8 @@ export class StatisticController { transform: true, }), ) - async getTodayStatistic(@Query() queryObj: StatisticQueryDto) { - const data = await this.statisticService.getTodayViewCount(queryObj.limit); + async readTodayStatistic(@Query() queryObj: StatisticQueryDto) { + const data = await this.statisticService.readTodayStatistic(queryObj.limit); return ApiResponse.responseWithData('금일 조회수 통계 조회 완료', data); } @@ -37,15 +36,15 @@ export class StatisticController { transform: true, }), ) - async getAllStatistic(@Query() queryObj: StatisticQueryDto) { - const data = await this.statisticService.getAllViewCount(queryObj.limit); + async readAllStatistic(@Query() queryObj: StatisticQueryDto) { + const data = await this.statisticService.readAllStatistic(queryObj.limit); return ApiResponse.responseWithData('전체 조회수 통계 조회 완료', data); } - @ApiPlatformStatistic() + @ApiReadPlatformStatistic() @Get('platform') - async getPlatformStatistic() { - const data = await this.statisticService.getPlatformGroupCount(); + async readPlatformStatistic() { + const data = await this.statisticService.readPlatformStatistic(); return ApiResponse.responseWithData('블로그 플랫폼 통계 조회 완료', data); } } diff --git a/server/src/statistic/statistic.service.ts b/server/src/statistic/statistic.service.ts index 13185b2e..9dd3a5a8 100644 --- a/server/src/statistic/statistic.service.ts +++ b/server/src/statistic/statistic.service.ts @@ -12,7 +12,7 @@ export class StatisticService { private readonly feedRepository: FeedRepository, private readonly rssAcceptRepository: RssAcceptRepository, ) {} - async getTodayViewCount(limit: number) { + async readTodayStatistic(limit: number) { const ranking = await this.redisService.redisClient.zrevrange( redisKeys.FEED_TREND_KEY, 0, @@ -37,18 +37,13 @@ export class StatisticService { return result; } - async getAllViewCount(limit: number) { - const ranking = await this.feedRepository.find({ - select: ['id', 'title', 'viewCount'], - order: { - viewCount: 'DESC', - }, - take: limit, - }); + async readAllStatistic(limit: number) { + const ranking = + await this.feedRepository.findAllStatisticsOrderByViewCount(limit); return ranking; } - async getPlatformGroupCount() { + async readPlatformStatistic() { const platformStatistics = await this.rssAcceptRepository.countByBlogPlatform(); return PlatformResponseDto.platformToResults(platformStatistics); From 03f8c6f0f8aaeae7f1bd37f14fd5230effe1d7f3 Mon Sep 17 00:00:00 2001 From: asn6878 Date: Thu, 5 Dec 2024 14:19:54 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20read=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/admin.controller.ts | 6 +++--- ...onIdAdmin.api-docs.ts => readSessionIdAdmin.api-docs.ts} | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) rename server/src/admin/api-docs/{getSessionIdAdmin.api-docs.ts => readSessionIdAdmin.api-docs.ts} (96%) diff --git a/server/src/admin/admin.controller.ts b/server/src/admin/admin.controller.ts index 42349965..37a62e2a 100644 --- a/server/src/admin/admin.controller.ts +++ b/server/src/admin/admin.controller.ts @@ -19,7 +19,7 @@ import { ApiResponse } from '../common/response/common.response'; import { LoginAdminDto } from './dto/login-admin.dto'; import { CookieAuthGuard } from '../common/guard/auth.guard'; import { ApiLoginAdmin } from './api-docs/loginAdmin.api-docs'; -import { ApigetSessionIdAdmin } from './api-docs/getSessionIdAdmin.api-docs'; +import { ApiReadSessionIdAdmin } from './api-docs/readSessionIdAdmin.api-docs'; import { ApiLogoutAdmin } from './api-docs/logoutAdmin.api-docs'; import { ApiCreateAdmin } from './api-docs/createAdmin.api-docs'; @@ -68,12 +68,12 @@ export class AdminController { ); } - @ApigetSessionIdAdmin() + @ApiReadSessionIdAdmin() @Get('/sessionId') @HttpCode(HttpStatus.OK) @UseGuards(CookieAuthGuard) @UsePipes(new ValidationPipe({ transform: true })) - async getSessionIdAdmin() { + async readSessionIdAdmin() { return ApiResponse.responseWithNoContent('정상적인 sessionId 입니다.'); } } diff --git a/server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts b/server/src/admin/api-docs/readSessionIdAdmin.api-docs.ts similarity index 96% rename from server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts rename to server/src/admin/api-docs/readSessionIdAdmin.api-docs.ts index 9a78acaa..ad30e09b 100644 --- a/server/src/admin/api-docs/getSessionIdAdmin.api-docs.ts +++ b/server/src/admin/api-docs/readSessionIdAdmin.api-docs.ts @@ -5,7 +5,7 @@ import { ApiUnauthorizedResponse, } from '@nestjs/swagger'; -export function ApigetSessionIdAdmin() { +export function ApiReadSessionIdAdmin() { return applyDecorators( ApiOperation({ summary: `관리자 페이지 출력을 위한 sessionId 확인 API`, From 2cb30644f036b976bf109b271da8f400311d1813 Mon Sep 17 00:00:00 2001 From: asn6878 Date: Thu, 5 Dec 2024 14:24:33 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=90=9B=20fix:=20admin=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=EB=B6=84=EB=A6=AC=20=EB=B3=B5=EA=B5=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/admin.repository.ts | 8 +------- server/src/admin/admin.service.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/server/src/admin/admin.repository.ts b/server/src/admin/admin.repository.ts index 1d3a4f3f..cae30588 100644 --- a/server/src/admin/admin.repository.ts +++ b/server/src/admin/admin.repository.ts @@ -9,7 +9,7 @@ export class AdminRepository extends Repository { super(Admin, dataSource.createEntityManager()); } - async registerAdmin(registerAdminDto: RegisterAdminDto) { + async createAdmin(registerAdminDto: RegisterAdminDto) { const { loginId, password } = registerAdminDto; const admin = this.create({ loginId, @@ -18,10 +18,4 @@ export class AdminRepository extends Repository { await this.save(admin); return admin; } - - async findAdminByLoginId(loginId: string) { - return await this.findOne({ - where: { loginId }, - }); - } } diff --git a/server/src/admin/admin.service.ts b/server/src/admin/admin.service.ts index 889723ea..00ee6252 100644 --- a/server/src/admin/admin.service.ts +++ b/server/src/admin/admin.service.ts @@ -30,7 +30,9 @@ export class AdminService { const cookie = request.cookies['sessionId']; const { loginId, password } = loginAdminDto; - const admin = await this.adminRepository.findAdminByLoginId(loginId); + const admin = await this.adminRepository.findOne({ + where: { loginId }, + }); if (!admin || !(await bcrypt.compare(password, admin.password))) { throw new UnauthorizedException('아이디 혹은 비밀번호가 잘못되었습니다.'); @@ -93,8 +95,9 @@ export class AdminService { async createAdmin(registerAdminDto: RegisterAdminDto) { let { loginId, password } = registerAdminDto; - const existingAdmin = - await this.adminRepository.findAdminByLoginId(loginId); + const existingAdmin = await this.adminRepository.findOne({ + where: { loginId }, + }); if (existingAdmin) { throw new ConflictException('이미 존재하는 아이디입니다.'); @@ -103,6 +106,6 @@ export class AdminService { const saltRounds = 10; password = await bcrypt.hash(password, saltRounds); - return this.adminRepository.registerAdmin({ loginId, password }); + return this.adminRepository.createAdmin({ loginId, password }); } } From d42494f7d2ee19ff1d13a95998d0dd68ebd62bbc Mon Sep 17 00:00:00 2001 From: asn6878 Date: Thu, 5 Dec 2024 21:59:32 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=AA=85=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/admin/admin.service.ts | 2 +- server/test/admin/login.e2e-spec.ts | 2 +- server/test/admin/register.e2e-spec.ts | 2 +- server/test/admin/sessionId.e2e-spec.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/admin/admin.service.ts b/server/src/admin/admin.service.ts index 00ee6252..dda0527d 100644 --- a/server/src/admin/admin.service.ts +++ b/server/src/admin/admin.service.ts @@ -106,6 +106,6 @@ export class AdminService { const saltRounds = 10; password = await bcrypt.hash(password, saltRounds); - return this.adminRepository.createAdmin({ loginId, password }); + await this.adminRepository.createAdmin({ loginId, password }); } } diff --git a/server/test/admin/login.e2e-spec.ts b/server/test/admin/login.e2e-spec.ts index 162d1284..6d3cbc20 100644 --- a/server/test/admin/login.e2e-spec.ts +++ b/server/test/admin/login.e2e-spec.ts @@ -14,7 +14,7 @@ describe('POST api/admin/login E2E Test', () => { beforeAll(async () => { app = global.testApp; adminService = app.get(AdminService); - await adminService.registerAdmin(registerAdminDto); + await adminService.createAdmin(registerAdminDto); }); it('등록된 계정이면 정상적으로 로그인할 수 있다.', async () => { //given diff --git a/server/test/admin/register.e2e-spec.ts b/server/test/admin/register.e2e-spec.ts index bb91661a..ee1d6b56 100644 --- a/server/test/admin/register.e2e-spec.ts +++ b/server/test/admin/register.e2e-spec.ts @@ -22,7 +22,7 @@ describe('POST api/admin/register E2E Test', () => { app = global.testApp; adminService = app.get(AdminService); - await adminService.registerAdmin(loginAdminDto); + await adminService.createAdmin(loginAdminDto); }); it('관리자가 로그인되어 있으면 다른 관리자 계정 회원가입을 할 수 있다.', async () => { diff --git a/server/test/admin/sessionId.e2e-spec.ts b/server/test/admin/sessionId.e2e-spec.ts index 75940aa8..2d591f24 100644 --- a/server/test/admin/sessionId.e2e-spec.ts +++ b/server/test/admin/sessionId.e2e-spec.ts @@ -18,7 +18,7 @@ describe('GET api/admin/sessionId E2E Test', () => { app = global.testApp; adminService = app.get(AdminService); - await adminService.registerAdmin(loginAdminDto); + await adminService.createAdmin(loginAdminDto); }); it('쿠키의 session id가 유효하다면 관리자를 로그인 상태로 취급한다.', async () => {