-
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 #151 from innovationacademy-kr/v3-log
#113 로그, 검색 모듈 추가
- Loading branch information
Showing
23 changed files
with
1,259 additions
and
11 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,57 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class CabinetLentLogDto { | ||
@ApiProperty({ | ||
description: '42 고유 ID', | ||
example: 12345, | ||
}) | ||
user_id: number; // 42 고유 ID | ||
|
||
@ApiProperty({ | ||
description: '42 로그인 ID', | ||
example: 'joopark', | ||
}) | ||
intra_id: string; // 42 로그인 ID | ||
|
||
@ApiProperty({ | ||
description: '캐비넷 고유 ID', | ||
example: 1234, | ||
}) | ||
cabinet_id: number; // 캐비넷 고유 ID | ||
|
||
@ApiProperty({ | ||
description: '사물함에 붙어있는 숫자', | ||
example: 12, | ||
}) | ||
cabinet_num: number; // 사물함에 붙어있는 숫자 | ||
|
||
@ApiProperty({ | ||
description: '사물함이 존재하는 건물 이름', | ||
example: '새롬관', | ||
}) | ||
location: string; // 사물함 건물 | ||
|
||
@ApiProperty({ | ||
description: '사물함이 존재하는 층수', | ||
example: 2, | ||
}) | ||
floor: number; // 사물함 층수 | ||
|
||
@ApiProperty({ | ||
description: '사물함의 섹션 종류 (오아시스 등)', | ||
example: 'Oasis', | ||
}) | ||
section: string; // 사물함의 섹션 종류 (오아시스 등) | ||
|
||
@ApiProperty({ | ||
description: '대여한 시간', | ||
example: '2022-08-24 13:03:03', | ||
}) | ||
lent_time: Date; // 대여한 시간 | ||
|
||
@ApiProperty({ | ||
description: '반납 시간', | ||
example: '2022-08-24 13:03:03', | ||
}) | ||
return_time: Date; // 반납 시간 | ||
} |
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,16 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { CabinetLentLogDto } from './cabinet-lent-log.dto'; | ||
|
||
export class LogPagenationDto { | ||
@ApiProperty({ | ||
description: '로그 배열', | ||
type: [CabinetLentLogDto], | ||
}) | ||
result: CabinetLentLogDto[]; // 대여 정보 | ||
|
||
@ApiProperty({ | ||
description: 'DB에 저장된 총 결과의 길이', | ||
example: 42, | ||
}) | ||
total_length: number; // DB에 저장된 총 결과의 길이 | ||
} |
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,120 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Logger, | ||
Param, | ||
ParseIntPipe, | ||
Query, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiBadRequestResponse, | ||
ApiBearerAuth, | ||
ApiOkResponse, | ||
ApiOperation, | ||
ApiParam, | ||
ApiQuery, | ||
ApiTags, | ||
ApiUnauthorizedResponse, | ||
} from '@nestjs/swagger'; | ||
import { JWTAuthGuard } from 'src/auth/auth.guard'; | ||
import { LogPagenationDto } from './dto/log.pagenation.dto'; | ||
import { LogService } from './log.service'; | ||
|
||
@ApiTags('(V3) 로그') | ||
@ApiBearerAuth() | ||
@ApiUnauthorizedResponse({ | ||
description: '로그아웃 상태', | ||
}) | ||
@Controller({ | ||
version: '3', | ||
path: 'log', | ||
}) | ||
@UseGuards(JWTAuthGuard) | ||
export class LogController { | ||
constructor(private cabinetService: LogService) {} | ||
|
||
private logger = new Logger(LogController.name); | ||
|
||
@ApiOperation({ | ||
summary: '특정 유저의 사물함 대여 기록 반환', | ||
description: '특정 유저의 사물함 대여 기록을 반환합니다.', | ||
}) | ||
@ApiQuery({ | ||
name: 'index', | ||
description: '(페이지네이션) 가져올 데이터 인덱스', | ||
}) | ||
@ApiQuery({ | ||
name: 'length', | ||
description: '(페이지네이션) 가져올 데이터 길이', | ||
}) | ||
@ApiParam({ | ||
name: 'user_id', | ||
description: '유저 고유 ID', | ||
}) | ||
@ApiOkResponse({ | ||
type: LogPagenationDto, | ||
description: | ||
'파라미터로 받은 사물함의 정보를 CabinetInfoResponseDto 형식으로 받아옵니다', | ||
}) | ||
@ApiBadRequestResponse({ | ||
description: '존재하지 않는 유저, 잘못된 페이지네이션 요청', | ||
}) | ||
@Get('/user/:user_id') | ||
async getUserLogs( | ||
@Param('user_id', ParseIntPipe) user_id: number, | ||
@Query('index', ParseIntPipe) index: number, | ||
@Query('length', ParseIntPipe) length: number, | ||
): Promise<LogPagenationDto> { | ||
this.logger.debug(`Called ${this.getUserLogs.name}`); | ||
try { | ||
return await this.cabinetService.getUserLogs(user_id, index, length); | ||
} catch (err) { | ||
this.logger.error(err); | ||
throw err; | ||
} | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '특정 사물함의 대여 기록 반환', | ||
description: '특정 사물함의 대여 기록을 반환합니다.', | ||
}) | ||
@ApiQuery({ | ||
name: 'index', | ||
description: '(페이지네이션) 가져올 데이터 인덱스', | ||
}) | ||
@ApiQuery({ | ||
name: 'length', | ||
description: '(페이지네이션) 가져올 데이터 길이', | ||
}) | ||
@ApiParam({ | ||
name: 'cabinet_id', | ||
description: '사물함 고유 ID', | ||
}) | ||
@ApiOkResponse({ | ||
type: LogPagenationDto, | ||
description: | ||
'파라미터로 받은 사물함의 정보를 CabinetInfoResponseDto 형식으로 받아옵니다', | ||
}) | ||
@ApiBadRequestResponse({ | ||
description: '존재하지 않는 사물함, 잘못된 페이지네이션 요청', | ||
}) | ||
@Get('/cabinet/:cabinet_id') | ||
async getCabinetLogs( | ||
@Param('cabinet_id', ParseIntPipe) cabinet_id: number, | ||
@Query('index', ParseIntPipe) index: number, | ||
@Query('length', ParseIntPipe) length: number, | ||
): Promise<LogPagenationDto> { | ||
this.logger.debug(`Called ${this.getCabinetLogs.name}`); | ||
try { | ||
return await this.cabinetService.getCabinetLogs( | ||
cabinet_id, | ||
index, | ||
length, | ||
); | ||
} catch (err) { | ||
this.logger.error(err); | ||
throw err; | ||
} | ||
} | ||
} |
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,20 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { AuthModule } from 'src/auth/auth.module'; | ||
import LentLog from 'src/entities/lent.log.entity'; | ||
import { LogController } from './log.controller'; | ||
import { LogService } from './log.service'; | ||
import { LogRepository } from './repository/log.repository'; | ||
|
||
const repo = { | ||
provide: 'ILogRepository', | ||
useClass: LogRepository, | ||
}; | ||
|
||
@Module({ | ||
imports: [AuthModule, TypeOrmModule.forFeature([LentLog])], | ||
exports: [LogService], | ||
controllers: [LogController], | ||
providers: [LogService, repo], | ||
}) | ||
export class LogModule {} |
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,65 @@ | ||
import { | ||
BadRequestException, | ||
Inject, | ||
Injectable, | ||
Logger, | ||
} from '@nestjs/common'; | ||
import { CabinetLentLogDto } from './dto/cabinet-lent-log.dto'; | ||
import { LogPagenationDto } from './dto/log.pagenation.dto'; | ||
import { ILogRepository } from './repository/log.repository.interface'; | ||
|
||
@Injectable() | ||
export class LogService { | ||
private logger = new Logger(LogService.name); | ||
|
||
constructor( | ||
@Inject('ILogRepository') | ||
private logRepository: ILogRepository, | ||
) {} | ||
|
||
/** | ||
* 특정 유저의 사물함 대여 기록을 반환합니다. | ||
* | ||
* @param user_id 유저 고유 ID | ||
* @param index 가져올 데이터 인덱스 | ||
* @param length 가져올 데이터 길이 | ||
* @returns LogPagenationDto | ||
* @throw HTTPError | ||
*/ | ||
async getUserLogs( | ||
user_id: number, | ||
index: number, | ||
length: number, | ||
): Promise<LogPagenationDto> { | ||
const result = await this.logRepository.getUserLogs(user_id, index, length); | ||
if (index !== 0 && length !== 0 && result.total_length === 0) { | ||
throw new BadRequestException('Index Error'); | ||
} | ||
return result; | ||
} | ||
|
||
/** | ||
* 특정 사물함의 대여 기록을 반환합니다. | ||
* | ||
* @param cabinet_id 캐비넷 고유 ID | ||
* @param index 가져올 데이터 인덱스 | ||
* @param length 가져올 데이터 길이 | ||
* @returns LogPagenationDto | ||
* @throw HTTPError | ||
*/ | ||
async getCabinetLogs( | ||
cabinet_id: number, | ||
index: number, | ||
length: number, | ||
): Promise<LogPagenationDto> { | ||
const result = await this.logRepository.getCabinetLogs( | ||
cabinet_id, | ||
index, | ||
length, | ||
); | ||
if (index !== 0 && length !== 0 && result.total_length === 0) { | ||
throw new BadRequestException('Index Error'); | ||
} | ||
return result; | ||
} | ||
} |
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,30 @@ | ||
import { CabinetLentLogDto } from '../dto/cabinet-lent-log.dto'; | ||
import { LogPagenationDto } from '../dto/log.pagenation.dto'; | ||
|
||
export interface ILogRepository { | ||
/** | ||
* 특정 유저의 사물함 대여 기록을 반환합니다. | ||
* | ||
* @param user_id 유저 고유 ID | ||
* @param index 가져올 데이터 인덱스 | ||
* @param length 가져올 데이터 길이 | ||
*/ | ||
getUserLogs( | ||
user_id: number, | ||
index: number, | ||
length: number, | ||
): Promise<LogPagenationDto>; | ||
|
||
/** | ||
* 특정 사물함의 대여 기록을 반환합니다. | ||
* | ||
* @param cabinet_id 캐비넷 고유 ID | ||
* @param index 가져올 데이터 인덱스 | ||
* @param length 가져올 데이터 길이 | ||
*/ | ||
getCabinetLogs( | ||
cabinet_id: number, | ||
index: number, | ||
length: number, | ||
): Promise<LogPagenationDto>; | ||
} |
Oops, something went wrong.