Skip to content

Commit

Permalink
refactor: use interface instead of class to define response dtos
Browse files Browse the repository at this point in the history
replace 'export class (\w+ResponseDto)' with 'export interface $1'
  • Loading branch information
Nictheboy committed Apr 10, 2024
1 parent 2d71e8c commit 6502aeb
Show file tree
Hide file tree
Showing 44 changed files with 49 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/answer/DTO/agree-answer.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class AgreeAnswerResponseDto extends BaseResponseDto {
export interface AgreeAnswerResponseDto extends BaseResponseDto {
data: {
agree_count: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/answer/DTO/create-answer.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class CreateAnswerResponseDto extends BaseResponseDto {
export interface CreateAnswerResponseDto extends BaseResponseDto {
data: {
id: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/answer/DTO/get-answer-detail.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { QuestionDto } from '../../questions/DTO/question.dto';
import { AnswerDto } from './answer.dto';

export class GetAnswerDetailResponseDto extends BaseResponseDto {
export interface GetAnswerDetailResponseDto extends BaseResponseDto {
data: {
question: QuestionDto;
answer: AnswerDto;
Expand Down
2 changes: 1 addition & 1 deletion src/answer/DTO/get-answers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { AnswerDto } from './answer.dto';

export class GetAnswersResponseDto extends BaseResponseDto {
export interface GetAnswersResponseDto extends BaseResponseDto {
data: {
answers: AnswerDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/attitude/DTO/update-attitude.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { AttitudeStateDto } from './attitude-state.dto';

export class UpdateAttitudeResponseDto extends BaseResponseDto {
export interface UpdateAttitudeResponseDto extends BaseResponseDto {
data: {
attitudes: AttitudeStateDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/avatars/DTO/upload-avatar.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
export class UploadAvatarResponseDto extends BaseResponseDto {
export interface UploadAvatarResponseDto extends BaseResponseDto {
data: {
avatarid: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/comments/DTO/create-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class CreateCommentResponseDto extends BaseResponseDto {
export interface CreateCommentResponseDto extends BaseResponseDto {
data: {
id: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/comments/DTO/get-comment-detail.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { CommentDto } from './comment.dto';

export class GetCommentDetailResponseDto extends BaseResponseDto {
export interface GetCommentDetailResponseDto extends BaseResponseDto {
data: {
comment: CommentDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/comments/DTO/get-comments.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { CommentDto } from './comment.dto';

export class GetCommentsResponseDto extends BaseResponseDto {
export interface GetCommentsResponseDto extends BaseResponseDto {
data: {
comments: CommentDto[];
page: PageDto;
Expand Down
12 changes: 1 addition & 11 deletions src/common/DTO/base-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
*
*/

import { IsInt, IsString } from 'class-validator';

export class BaseResponseDto {
constructor(code: number, message: string) {
this.code = code;
this.message = message;
}

@IsInt()
export interface BaseResponseDto {
code: number;

@IsString()
message: string;
}
2 changes: 1 addition & 1 deletion src/groups/DTO/get-group-members.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { UserDto } from '../../users/DTO/user.dto';

export class GetGroupMembersResponseDto extends BaseResponseDto {
export interface GetGroupMembersResponseDto extends BaseResponseDto {
data: {
members: UserDto[];
page?: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/groups/DTO/get-groups.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { GroupDto } from './group.dto';

export class GetGroupsResponseDto extends BaseResponseDto {
export interface GetGroupsResponseDto extends BaseResponseDto {
data: {
groups: GroupDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/groups/DTO/get-members.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { UserDto } from '../../users/DTO/user.dto';

export class GetGroupMembersResponseDto extends BaseResponseDto {
export interface GetGroupMembersResponseDto extends BaseResponseDto {
data: {
members: UserDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/groups/DTO/get-questions.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { QuestionDto } from '../../questions/DTO/question.dto';

export class GetGroupQuestionsResponseDto extends BaseResponseDto {
export interface GetGroupQuestionsResponseDto extends BaseResponseDto {
data: {
questions: QuestionDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/groups/DTO/group.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class GroupDto {
is_public: boolean;
}

export class GroupResponseDto extends BaseResponseDto {
export interface GroupResponseDto extends BaseResponseDto {
data: {
group: GroupDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/groups/DTO/join-group.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export class JoinGroupResultDto {
is_waiting: boolean;
}

export class JoinGroupResponseDto extends BaseResponseDto {
export interface JoinGroupResponseDto extends BaseResponseDto {
data: JoinGroupResultDto;
}
2 changes: 1 addition & 1 deletion src/groups/DTO/quit-group.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class QuitGroupResponseDto extends BaseResponseDto {
export interface QuitGroupResponseDto extends BaseResponseDto {
data: {
member_count: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/materials/DTO/get-material.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Material } from '@prisma/client';
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class GetMaterialResponseDto extends BaseResponseDto {
export interface GetMaterialResponseDto extends BaseResponseDto {
data: {
material: Material;
};
Expand Down
2 changes: 1 addition & 1 deletion src/materials/DTO/upload-material.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class UploadMaterialRequestDto {
type: string;
}

export class UploadMaterialResponseDto extends BaseResponseDto {
export interface UploadMaterialResponseDto extends BaseResponseDto {
data: {
id: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/add-question.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class AddQuestionRequestDto {
bounty: number = 0;
}

export class AddQuestionResponseDto extends BaseResponseDto {
export interface AddQuestionResponseDto extends BaseResponseDto {
data: {
id: number;
};
Expand Down
4 changes: 2 additions & 2 deletions src/questions/DTO/follow-unfollow-question.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class FollowQuestionResponseDto extends BaseResponseDto {
export interface FollowQuestionResponseDto extends BaseResponseDto {
data: {
follow_count: number;
};
}

export class UnfollowQuestionResponseDto extends BaseResponseDto {
export interface UnfollowQuestionResponseDto extends BaseResponseDto {
data: {
follow_count: number;
};
Expand Down
3 changes: 2 additions & 1 deletion src/questions/DTO/get-invitation-detail.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { QuestionInvitationDto } from './question-invitation.dto';

export class GetQuestionInvitationDetailResponseDto extends BaseResponseDto {
export interface GetQuestionInvitationDetailResponseDto
extends BaseResponseDto {
data: {
invitation: QuestionInvitationDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/get-question-follower.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { UserDto } from '../../users/DTO/user.dto';

export class GetQuestionFollowerResponseDto extends BaseResponseDto {
export interface GetQuestionFollowerResponseDto extends BaseResponseDto {
data: {
users: UserDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/get-question-invitation.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { QuestionInvitationDto } from './question-invitation.dto';

export class GetQuestionInvitationsResponseDto extends BaseResponseDto {
export interface GetQuestionInvitationsResponseDto extends BaseResponseDto {
data: {
invitations: QuestionInvitationDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/get-question-recommendations.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { UserDto } from '../../users/DTO/user.dto';

export class GetQuestionRecommendationsResponseDto extends BaseResponseDto {
export interface GetQuestionRecommendationsResponseDto extends BaseResponseDto {
data: {
users: UserDto[];
};
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/get-question.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { QuestionDto } from './question.dto';

export class GetQuestionResponseDto extends BaseResponseDto {
export interface GetQuestionResponseDto extends BaseResponseDto {
data: {
question: QuestionDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/invite-user-answer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class InviteUsersAnswerRequestDto {
user_id: number;
}

export class InviteUsersAnswerResponseDto extends BaseResponseDto {
export interface InviteUsersAnswerResponseDto extends BaseResponseDto {
data: {
invitationId: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/questions/DTO/search-question.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { QuestionDto } from './question.dto';

export class SearchQuestionResponseDto extends BaseResponseDto {
export interface SearchQuestionResponseDto extends BaseResponseDto {
data: {
questions: QuestionDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/topics/DTO/add-topic.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class AddTopicRequestDto {
name: string;
}

export class AddTopicResponseDto extends BaseResponseDto {
export interface AddTopicResponseDto extends BaseResponseDto {
data: {
id: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/topics/DTO/get-topic.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { TopicDto } from './topic.dto';

export class GetTopicResponseDto extends BaseResponseDto {
export interface GetTopicResponseDto extends BaseResponseDto {
data: {
topic: TopicDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/topics/DTO/search-topic.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { TopicDto } from './topic.dto';

export class SearchTopicResponseDto extends BaseResponseDto {
export interface SearchTopicResponseDto extends BaseResponseDto {
data: {
topics: TopicDto[];
page: PageDto;
Expand Down
4 changes: 2 additions & 2 deletions src/users/DTO/follow-unfollow.dto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';

export class FollowResponseDto extends BaseResponseDto {
export interface FollowResponseDto extends BaseResponseDto {
data: {
follow_count: number;
};
}

export class UnfollowResponseDto extends BaseResponseDto {
export interface UnfollowResponseDto extends BaseResponseDto {
data: {
follow_count: number;
};
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/get-answered-answers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AnswerDto } from '../../answer/DTO/answer.dto';
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';

export class GetAnsweredAnswersResponseDto extends BaseResponseDto {
export interface GetAnsweredAnswersResponseDto extends BaseResponseDto {
data: {
answers: AnswerDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/get-asked-questions.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { QuestionDto } from '../../questions/DTO/question.dto';

export class GetAskedQuestionsResponseDto extends BaseResponseDto {
export interface GetAskedQuestionsResponseDto extends BaseResponseDto {
data: {
questions: QuestionDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/get-followed-questions.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { QuestionDto } from '../../questions/DTO/question.dto';

export class GetFollowedQuestionsResponseDto extends BaseResponseDto {
export interface GetFollowedQuestionsResponseDto extends BaseResponseDto {
data: {
questions: QuestionDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/get-followers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { PageDto } from '../../common/DTO/page-response.dto';
import { UserDto } from './user.dto';

export class GetFollowersResponseDto extends BaseResponseDto {
export interface GetFollowersResponseDto extends BaseResponseDto {
data: {
users: UserDto[];
page: PageDto;
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/get-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseResponseDto } from '../../common/DTO/base-response.dto';
import { UserDto } from './user.dto';

export class GetUserResponseDto extends BaseResponseDto {
export interface GetUserResponseDto extends BaseResponseDto {
data: {
user: UserDto;
};
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/login.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class LoginRequestDto {
password: string;
}

export class LoginResponseDto extends BaseResponseDto {
export interface LoginResponseDto extends BaseResponseDto {
data: {
accessToken: string;
user: UserDto;
Expand Down
2 changes: 1 addition & 1 deletion src/users/DTO/refresh-token.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { LoginResponseDto } from './login.dto';

export class RefreshTokenResponseDto extends LoginResponseDto {}
export interface RefreshTokenResponseDto extends LoginResponseDto {}
2 changes: 1 addition & 1 deletion src/users/DTO/register.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export class RegisterRequestDto {
emailCode: string;
}

export class RegisterResponseDto extends LoginResponseDto {}
export interface RegisterResponseDto extends LoginResponseDto {}
4 changes: 2 additions & 2 deletions src/users/DTO/reset-password.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class ResetPasswordRequestRequestDto {
email: string;
}

export class ResetPasswordRequestDto extends BaseResponseDto {}
export interface ResetPasswordRequestRespondDto extends BaseResponseDto {}

export class ResetPasswordVerifyRequestDto {
@IsString()
Expand All @@ -16,4 +16,4 @@ export class ResetPasswordVerifyRequestDto {
new_password: string;
}

export class ResetPasswordVerifyResponseDto extends BaseResponseDto {}
export interface ResetPasswordVerifyResponseDto extends BaseResponseDto {}
2 changes: 1 addition & 1 deletion src/users/DTO/send-email-verify-code.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export class SendEmailVerifyCodeRequestDto {
email: string;
}

export class SendEmailVerifyCodeResponseDto extends BaseResponseDto {}
export interface SendEmailVerifyCodeResponseDto extends BaseResponseDto {}
2 changes: 1 addition & 1 deletion src/users/DTO/update-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export class UpdateUserRequestDto {
avatarId: number;
}

export class UpdateUserResponseDto extends BaseResponseDto {}
export interface UpdateUserResponseDto extends BaseResponseDto {}
Loading

0 comments on commit 6502aeb

Please sign in to comment.