hugoblanc / accelerator-api

0 stars 0 forks source link

Sweep: add endpoint on workspace controller to list them all #10

Open hugoblanc opened 1 year ago

hugoblanc commented 1 year ago
Checklist - [X] `src/workspace/workspace.service.ts` > • Add a new method getAllWorkspaces that fetches all workspaces from the database. This method should return a Promise that resolves with an array of Workspace objects. - [X] `src/workspace/workspace.controller.ts` > • Add a new method that handles the GET request to retrieve all workspaces. This method should call the getAllWorkspaces method in the WorkspaceService. > • Use the @UseGuards decorator with the JwtAuthGuard in the new controller method to ensure the endpoint is only accessible to authenticated users. - [X] `src/workspace/workspace.controller.spec.ts` > • Create a new test file for the WorkspaceController. > • Add tests for the new getAllWorkspaces method. The tests should check that the method returns the expected output and that it correctly handles errors.
sweep-test-hugo[bot] commented 1 year ago

Here's the PR! https://github.com/hugoblanc/accelerator-api/pull/11.

💎 Sweep Pro: I used GPT-4 to create this ticket. You have unlimited GPT-4 tickets. To retrigger Sweep, edit the issue.


Step 1: 🔍 Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/workspace/workspace.service.ts#L1-L137 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/workspace/workspace.module.ts#L1-L12 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/team/team.service.ts#L40-L165 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/core/security/auth/auth.module.ts#L1-L18 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/prompt/infrastructure/prompt.controller.ts#L1-L78

Step 2: 🧐 Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
src/workspace/workspace.service.ts Modify src/workspace/workspace.service.ts with contents:
• Add a new method getAllWorkspaces that fetches all workspaces from the database. This method should return a Promise that resolves with an array of Workspace objects.
src/workspace/workspace.controller.ts Modify src/workspace/workspace.controller.ts with contents:
• Add a new method that handles the GET request to retrieve all workspaces. This method should call the getAllWorkspaces method in the WorkspaceService.
• Use the @UseGuards decorator with the JwtAuthGuard in the new controller method to ensure the endpoint is only accessible to authenticated users.
src/workspace/workspace.controller.spec.ts Create src/workspace/workspace.controller.spec.ts with contents:
• Create a new test file for the WorkspaceController.
• Add tests for the new getAllWorkspaces method. The tests should check that the method returns the expected output and that it correctly handles errors.

Step 3: 📝 Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Add endpoint to retrieve all workspaces sweep/add-workspace-endpoint

Description

This PR adds a new endpoint to the WorkspaceController that allows users to retrieve all workspaces. It also includes the necessary changes in the WorkspaceService to fetch all workspaces from the database. The endpoint is protected by the JwtAuthGuard to ensure only authenticated users can access it. Additionally, tests have been added to ensure the new functionality works as expected.

Summary of Changes

  • Added a new method getAllWorkspaces in the WorkspaceService to fetch all workspaces from the database.
  • Added a new method getAllWorkspaces in the WorkspaceController to handle the GET request for retrieving all workspaces. This method calls the getAllWorkspaces method in the WorkspaceService.
  • Protected the new endpoint with the JwtAuthGuard to ensure only authenticated users can access it.
  • Added tests for the new getAllWorkspaces method in the WorkspaceController to verify its functionality.

Please review and merge this PR. Thank you!


Step 4: ⌨️ Coding

File Instructions Progress Error logs
src/workspace/workspace.service.ts Modify src/workspace/workspace.service.ts with contents:
• Add a new method getAllWorkspaces that fetches all workspaces from the database. This method should return a Promise that resolves with an array of Workspace objects.
✅ Commit 3f7683a No errors.
src/workspace/workspace.controller.ts Modify src/workspace/workspace.controller.ts with contents:
• Add a new method that handles the GET request to retrieve all workspaces. This method should call the getAllWorkspaces method in the WorkspaceService.
• Use the @UseGuards decorator with the JwtAuthGuard in the new controller method to ensure the endpoint is only accessible to authenticated users.
✅ Commit 25e2b41 No errors.
src/workspace/workspace.controller.spec.ts Create src/workspace/workspace.controller.spec.ts with contents:
• Create a new test file for the WorkspaceController.
• Add tests for the new getAllWorkspaces method. The tests should check that the method returns the expected output and that it correctly handles errors.
✅ Commit 6228891 No errors.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/add-workspace-endpoint.

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord