Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GWL-83] Record Swagger 리팩토링 #114

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions BackEnd/src/auth/dto/auth-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { ApiProperty, PickType } from '@nestjs/swagger';

class SuccessResDto {
@ApiProperty({ description: '에러가 없는 경우 null' })
code: number;

@ApiProperty({ description: '에러가 없는 경우 null' })
errorMessage: string;
}
import { SuccessResDto } from 'src/common/dto/SuccessRes.dto';

class Token {
@ApiProperty({
Expand Down
10 changes: 10 additions & 0 deletions BackEnd/src/common/dto/SuccessRes.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ApiProperty } from "@nestjs/swagger";

export class SuccessResDto {
@ApiProperty({ example: null, description: '에러 코드 성공시 null', nullable: true })
code: number | null;

@ApiProperty({ example: null, description: '에러 코드 성공시 null', nullable: true })
errorMessage: string | null;
}

17 changes: 0 additions & 17 deletions BackEnd/src/records/dto/create-recordResponse.dto.ts

This file was deleted.

13 changes: 0 additions & 13 deletions BackEnd/src/records/dto/get-recordResponse.dto.ts

This file was deleted.

20 changes: 20 additions & 0 deletions BackEnd/src/records/dto/record-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ApiProperty, PickType } from "@nestjs/swagger";
import { SuccessResDto } from "src/common/dto/SuccessRes.dto";
import { RecordModel } from "../entities/records.entity";

class GetRecord extends PickType(RecordModel, ['id', 'workout', 'profile', 'workoutTime', 'distance', 'calorie', 'avgHeartRate', 'minHeartRate', 'maxHeartRate', 'createdAt']){}

export class CreateRecordResDto extends SuccessResDto {
@ApiProperty({ example: 1, description: '운동 기록 레코드 ID' })
recordId: number;
}

export class GetUsersRecordsResDto extends SuccessResDto {
@ApiProperty({ type: () => [GetRecord] })
data: GetRecord[]
}

export class GetRecordResDto extends SuccessResDto {
@ApiProperty({ type: () => GetRecord })
data: GetRecord
}
3 changes: 2 additions & 1 deletion BackEnd/src/records/entities/records.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class RecordModel {
@PrimaryGeneratedColumn()
id: number;

@ApiProperty({ example: 'biking', description: '선택한 운동 종료' })
@ApiProperty({ example: '자전거', description: '선택한 운동 종료' })
@Column()
@IsString()
workout: string;
Expand Down Expand Up @@ -51,6 +51,7 @@ export class RecordModel {
@IsNumber()
maxHeartRate: number;

@ApiProperty( {example: 'YYYY-MM-DD hh:mm:ss', description: '운동 기록 생성 날짜'} )
@CreateDateColumn()
createdAt: Date;

Expand Down
10 changes: 4 additions & 6 deletions BackEnd/src/records/records.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { AccessTokenGuard } from 'src/auth/guard/bearerToken.guard';
import { Profile } from 'src/profiles/decorator/profile.decorator';
import { ProfileModel } from 'src/profiles/entities/profiles.entity';
import {ApiBody, ApiCreatedResponse, ApiOperation, ApiTags} from "@nestjs/swagger";
import {CreateRecordDataDto} from "./dto/create-recordResponse.dto";
import {RecordDataDto} from "./dto/get-recordResponse.dto";

import { CreateRecordResDto, GetRecordResDto, GetUsersRecordsResDto } from './dto/record-response.dto';

@ApiTags('사용자 기록 API')
@Controller('api/v1/records')
Expand All @@ -16,7 +14,7 @@ export class RecordsController {
@Post()
@ApiOperation({summary: '운동 기록 생성'})
@ApiBody({type: CreateExerciseLogDto})
@ApiCreatedResponse({type: CreateRecordDataDto})
@ApiCreatedResponse({type: CreateRecordResDto})
@UseGuards(AccessTokenGuard)
async createWorkOutLog(
@Profile() profile: ProfileModel,
Expand All @@ -31,15 +29,15 @@ export class RecordsController {

@Get('me')
@ApiOperation({summary: '내 모든 운동 기록 조회'})
@ApiCreatedResponse({type: RecordDataDto})
@ApiCreatedResponse({type: GetUsersRecordsResDto})
@UseGuards(AccessTokenGuard)
async getUserRecords(@Profile() profile: ProfileModel) {
return this.recordsService.findByProfileId(profile.id);
}

@Get(':recordId')
@ApiOperation({summary: '하나의 기록 조회'})
@ApiCreatedResponse({type: RecordDataDto})
@ApiCreatedResponse({type: GetRecordResDto})
async getRecord(@Param('recordId') recordId: number) {
return this.recordsService.findById(recordId);
}
Expand Down
Loading