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

refactor: use interface instead of class to define response dtos #161

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Nictheboy
Copy link
Contributor

replace 'export class (\w+ResponseDto)' with 'export interface $1'

replace 'export class (\w+ResponseDto)' with 'export interface $1'
Copy link

coderabbitai bot commented Apr 10, 2024

Walkthrough

The recent updates primarily involve converting various Data Transfer Objects (DTOs) from classes to interfaces across multiple modules like users, questions, groups, and more. This shift enhances flexibility and maintainability in the codebase, ensuring easier integration and modification in future developments.

Changes

File Path Change Summary
.../DTO/*.dto.ts (Multiple) Converted various DTO classes to interfaces, maintaining existing structures and properties.
src/users/users.controller.ts Updated method signature for resetPasswordRequest to use ResetPasswordRequestRespondDto.

🐰✨
In the land of code where the data flows,
Classes to interfaces, oh how it goes!
With a hop and a skip, refactoring's a breeze,
Now our code's structured with so much ease!
Celebrate the changes, for they're here to please! 🌟
🐰💻


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 840ee30 and 6502aeb.
Files selected for processing (44)
  • src/answer/DTO/agree-answer.dto.ts (1 hunks)
  • src/answer/DTO/create-answer.dto.ts (1 hunks)
  • src/answer/DTO/get-answer-detail.dto.ts (1 hunks)
  • src/answer/DTO/get-answers.dto.ts (1 hunks)
  • src/attitude/DTO/update-attitude.dto.ts (1 hunks)
  • src/avatars/DTO/upload-avatar.dto.ts (1 hunks)
  • src/comments/DTO/create-comment.dto.ts (1 hunks)
  • src/comments/DTO/get-comment-detail.dto.ts (1 hunks)
  • src/comments/DTO/get-comments.dto.ts (1 hunks)
  • src/common/DTO/base-response.dto.ts (1 hunks)
  • src/groups/DTO/get-group-members.dto.ts (1 hunks)
  • src/groups/DTO/get-groups.dto.ts (1 hunks)
  • src/groups/DTO/get-members.dto.ts (1 hunks)
  • src/groups/DTO/get-questions.dto.ts (1 hunks)
  • src/groups/DTO/group.dto.ts (1 hunks)
  • src/groups/DTO/join-group.dto.ts (1 hunks)
  • src/groups/DTO/quit-group.dto.ts (1 hunks)
  • src/materials/DTO/get-material.dto.ts (1 hunks)
  • src/materials/DTO/upload-material.dto.ts (1 hunks)
  • src/questions/DTO/add-question.dto.ts (1 hunks)
  • src/questions/DTO/follow-unfollow-question.dto.ts (1 hunks)
  • src/questions/DTO/get-invitation-detail.dto.ts (1 hunks)
  • src/questions/DTO/get-question-follower.dto.ts (1 hunks)
  • src/questions/DTO/get-question-invitation.dto.ts (1 hunks)
  • src/questions/DTO/get-question-recommendations.dto.ts (1 hunks)
  • src/questions/DTO/get-question.dto.ts (1 hunks)
  • src/questions/DTO/invite-user-answer.dto.ts (1 hunks)
  • src/questions/DTO/search-question.dto.ts (1 hunks)
  • src/topics/DTO/add-topic.dto.ts (1 hunks)
  • src/topics/DTO/get-topic.dto.ts (1 hunks)
  • src/topics/DTO/search-topic.dto.ts (1 hunks)
  • src/users/DTO/follow-unfollow.dto.ts (1 hunks)
  • src/users/DTO/get-answered-answers.dto.ts (1 hunks)
  • src/users/DTO/get-asked-questions.dto.ts (1 hunks)
  • src/users/DTO/get-followed-questions.dto.ts (1 hunks)
  • src/users/DTO/get-followers.dto.ts (1 hunks)
  • src/users/DTO/get-user.dto.ts (1 hunks)
  • src/users/DTO/login.dto.ts (1 hunks)
  • src/users/DTO/refresh-token.dto.ts (1 hunks)
  • src/users/DTO/register.dto.ts (1 hunks)
  • src/users/DTO/reset-password.dto.ts (2 hunks)
  • src/users/DTO/send-email-verify-code.dto.ts (1 hunks)
  • src/users/DTO/update-user.dto.ts (1 hunks)
  • src/users/users.controller.ts (2 hunks)
Additional comments not posted (45)
src/users/DTO/refresh-token.dto.ts (1)

3-3: Conversion from class to interface is correctly implemented, maintaining inheritance from LoginResponseDto.

src/answer/DTO/create-answer.dto.ts (1)

3-3: Interface correctly extends BaseResponseDto and maintains the data structure with an id field.

src/comments/DTO/create-comment.dto.ts (1)

3-3: Interface correctly extends BaseResponseDto and maintains the data structure with an id field.

src/avatars/DTO/upload-avatar.dto.ts (1)

2-2: Interface correctly extends BaseResponseDto and maintains the data structure with an avatarid field.

src/groups/DTO/quit-group.dto.ts (1)

3-3: Interface correctly extends BaseResponseDto and maintains the data structure with a member_count field.

src/answer/DTO/agree-answer.dto.ts (1)

3-3: Interface correctly extends BaseResponseDto and maintains the data structure with an agree_count field.

src/users/DTO/get-user.dto.ts (1)

4-4: Interface correctly extends BaseResponseDto and maintains the data structure with a user field of type UserDto.

src/topics/DTO/get-topic.dto.ts (1)

4-4: Interface correctly extends BaseResponseDto and maintains the data structure with a topic field of type TopicDto.

src/materials/DTO/get-material.dto.ts (1)

4-4: Conversion from class to interface for GetMaterialResponseDto is correctly implemented and aligns with TypeScript best practices for DTOs.

src/questions/DTO/get-question.dto.ts (1)

4-4: Conversion from class to interface for GetQuestionResponseDto is correctly implemented, enhancing maintainability and flexibility.

src/comments/DTO/get-comment-detail.dto.ts (1)

4-4: Conversion from class to interface for GetCommentDetailResponseDto is correctly implemented, enhancing maintainability and flexibility.

src/questions/DTO/get-question-recommendations.dto.ts (1)

4-4: Conversion from class to interface for GetQuestionRecommendationsResponseDto is correctly implemented, enhancing maintainability and flexibility.

src/attitude/DTO/update-attitude.dto.ts (1)

4-4: Conversion from class to interface for UpdateAttitudeResponseDto is correctly implemented, enhancing maintainability and flexibility.

src/users/DTO/send-email-verify-code.dto.ts (1)

9-9: Conversion from class to interface for SendEmailVerifyCodeResponseDto is correctly implemented, enhancing maintainability and flexibility.

src/common/DTO/base-response.dto.ts (1)

10-10: Conversion from class to interface for BaseResponseDto is correctly implemented, providing a consistent base for other DTOs.

src/topics/DTO/add-topic.dto.ts (1)

9-9: Conversion from class to interface for AddTopicResponseDto is correctly implemented, enhancing maintainability and flexibility.

src/questions/DTO/get-invitation-detail.dto.ts (1)

4-5: The conversion from class to interface is implemented correctly, maintaining the structure and extending BaseResponseDto as intended.

src/users/DTO/follow-unfollow.dto.ts (1)

3-3: Both interfaces are correctly defined, extending BaseResponseDto and maintaining the structure with follow_count.

Also applies to: 9-9

src/users/DTO/get-followers.dto.ts (1)

5-5: The conversion from class to interface is implemented correctly, maintaining the structure and extending BaseResponseDto as intended.

src/groups/DTO/get-groups.dto.ts (1)

5-5: The conversion from class to interface is implemented correctly, maintaining the structure and extending BaseResponseDto as intended.

src/topics/DTO/search-topic.dto.ts (1)

5-5: The conversion from class to interface is implemented correctly, maintaining the structure and extending BaseResponseDto as intended.

src/questions/DTO/follow-unfollow-question.dto.ts (1)

3-3: Both interfaces are correctly defined, extending BaseResponseDto.

Also applies to: 9-9

src/answer/DTO/get-answers.dto.ts (1)

5-5: The conversion from class to interface is implemented correctly, maintaining the structure and extending BaseResponseDto as intended.

src/questions/DTO/invite-user-answer.dto.ts (1)

9-9: The conversion from class to interface is implemented correctly, maintaining the structure and extending BaseResponseDto as intended.

src/comments/DTO/get-comments.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/answer/DTO/get-answer-detail.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/questions/DTO/search-question.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/groups/DTO/get-members.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/groups/DTO/get-group-members.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/questions/DTO/get-question-follower.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/users/DTO/get-answered-answers.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/users/DTO/update-user.dto.ts (1)

15-15: Conversion from class to interface is correctly implemented, extending BaseResponseDto.

src/groups/DTO/get-questions.dto.ts (1)

5-5: Conversion from class to interface is correctly implemented, maintaining the structure and extending BaseResponseDto.

src/users/DTO/get-asked-questions.dto.ts (1)

5-5: Correct implementation of the interface, preserving the data structure and extending BaseResponseDto.

src/users/DTO/get-followed-questions.dto.ts (1)

5-5: Interface correctly implemented, maintaining the data structure and extending BaseResponseDto.

src/materials/DTO/upload-material.dto.ts (1)

10-10: Interface conversion is correctly implemented, maintaining the data structure and extending BaseResponseDto.

src/questions/DTO/get-question-invitation.dto.ts (1)

5-5: Interface correctly implemented, maintaining the data structure and extending BaseResponseDto.

src/users/DTO/register.dto.ts (1)

21-21: Interface correctly implemented, extending LoginResponseDto.

src/users/DTO/login.dto.ts (1)

13-13: Interface correctly implemented, maintaining the data structure and extending BaseResponseDto.

src/groups/DTO/join-group.dto.ts (1)

15-15: Interface correctly implemented, maintaining the data structure and extending BaseResponseDto.

src/users/DTO/reset-password.dto.ts (2)

9-9: Interface ResetPasswordRequestRespondDto correctly extends BaseResponseDto. Good use of TypeScript interfaces for type definitions.


19-19: Interface ResetPasswordVerifyResponseDto is well-defined and extends BaseResponseDto as expected.

src/groups/DTO/group.dto.ts (1)

20-20: Interface GroupResponseDto is correctly refactored from a class and properly extends BaseResponseDto with a nested data object. This maintains consistency and type safety.

src/questions/DTO/add-question.dto.ts (1)

39-39: Interface AddQuestionResponseDto is correctly refactored and extends BaseResponseDto. The inclusion of the data object with an id property aligns with the intended changes.

src/users/users.controller.ts (1)

260-260: Method sendResetPasswordEmail correctly uses ResetPasswordRequestRespondDto for its return type, aligning with the refactor objectives.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Nictheboy Nictheboy requested a review from andylizf April 10, 2024 13:07
Copy link

codecov bot commented Apr 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.24%. Comparing base (2d71e8c) to head (6502aeb).
Report is 2 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev     #161   +/-   ##
=======================================
  Coverage   91.24%   91.24%           
=======================================
  Files          62       62           
  Lines        2901     2901           
  Branches      335      335           
=======================================
  Hits         2647     2647           
  Misses        254      254           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andylizf
Copy link
Contributor

Why? Explain the advantages of interfaces over classes. Using interfaces would result in the class-validator not being able to validate and transform the returned response value, which does not currently exist but may be applied in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants