hugoblanc / accelerator-api

0 stars 0 forks source link

Sweep: Add a visibility state (public or private) on the workspace to allow users list and join public workspace only #7

Open hugoblanc opened 1 year ago

hugoblanc commented 1 year ago
Checklist - [X] `prisma/schema.prisma` > • Add a WorkspaceVisibility enum with 'public' and 'private' values. > • Add a visibility field to the Workspace model with a default value of 'private'. This field will use the WorkspaceVisibility enum. - [X] `src/workspace/workspace.controller.ts` > • Add a new endpoint to toggle the visibility of a workspace. This endpoint will use the toggleVisibility method from the workspace service. > • Modify the create workspace endpoint to include the visibility state in the request body. - [X] `src/workspace/dto/toggle-visibility.dto.ts` > • Create a new DTO for the toggle visibility endpoint. This DTO should contain the workspace ID and the new visibility state. - [X] `src/workspace/workspace.service.ts` > • Add a new method to toggle the visibility of a workspace. This method will update the visibility field of the workspace in the database. > • Modify the create workspace method to include the visibility state in the workspace creation data. - [X] `src/workspace/dto/create-workspace.dto.ts` > • Add a visibility field to the CreateWorkspaceDto. This field will use the WorkspaceVisibility enum.
sweep-ai[bot] commented 1 year ago

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

⚡ Sweep Free Trial: I used GPT-3.5 to create this ticket. You have 3 GPT-4 tickets left for the month and 0 for the day. For more GPT-4 tickets, visit our payment portal. 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.controller.ts#L1-L67 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/workspace/dto/create-workspace.dto.ts#L1-L2 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/prisma/schema.prisma#L1-L145 https://github.com/hugoblanc/accelerator-api/blob/baca396d3e3e15fb5fdaac9f1a9269111150f253/src/workspace/guard/is-user-in-workspace.guard.ts#L1-L27

Step 2: 🧐 Snippet Analysis

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

File Path Proposed Changes
prisma/schema.prisma Modify prisma/schema.prisma with contents:
• Add a WorkspaceVisibility enum with 'public' and 'private' values.
• Add a visibility field to the Workspace model with a default value of 'private'. This field will use the WorkspaceVisibility enum.
src/workspace/workspace.controller.ts Modify src/workspace/workspace.controller.ts with contents:
• Add a new endpoint to toggle the visibility of a workspace. This endpoint will use the toggleVisibility method from the workspace service.
• Modify the create workspace endpoint to include the visibility state in the request body.
src/workspace/dto/toggle-visibility.dto.ts Create src/workspace/dto/toggle-visibility.dto.ts with contents:
• Create a new DTO for the toggle visibility endpoint. This DTO should contain the workspace ID and the new visibility state.
src/workspace/workspace.service.ts Modify src/workspace/workspace.service.ts with contents:
• Add a new method to toggle the visibility of a workspace. This method will update the visibility field of the workspace in the database.
• Modify the create workspace method to include the visibility state in the workspace creation data.
src/workspace/dto/create-workspace.dto.ts Modify src/workspace/dto/create-workspace.dto.ts with contents:
• Add a visibility field to the CreateWorkspaceDto. This field will use the WorkspaceVisibility enum.

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 visibility state and toggle endpoint for workspaces sweep/add-visibility-state

Description

This PR adds a visibility state to workspaces and a new endpoint to toggle the visibility. It also modifies the workspace creation process to include the visibility state.

Summary of Changes

  • Added a visibility field to the Workspace model in the Prisma schema, with a default value of private.
  • Created a new endpoint in the WorkspaceController to toggle the visibility of a workspace.
  • Added a new DTO, ToggleVisibilityDto, for the toggle visibility endpoint.
  • Modified the createWorkspace method in the WorkspaceController to include the visibility state in the request body.
  • Added a new method, toggleVisibility, to the WorkspaceService to update the visibility field of a workspace.
  • Modified the createWorkspace method in the WorkspaceService to include the visibility state in the workspace creation data.
  • Added a visibility field to the CreateWorkspaceDto.

Please review and merge these changes.


Step 4: ⌨️ Coding

File Instructions Progress Error logs
prisma/schema.prisma Modify prisma/schema.prisma with contents:
• Add a WorkspaceVisibility enum with 'public' and 'private' values.
• Add a visibility field to the Workspace model with a default value of 'private'. This field will use the WorkspaceVisibility enum.
✅ Commit 72291fe No errors.
src/workspace/workspace.controller.ts Modify src/workspace/workspace.controller.ts with contents:
• Add a new endpoint to toggle the visibility of a workspace. This endpoint will use the toggleVisibility method from the workspace service.
• Modify the create workspace endpoint to include the visibility state in the request body.
✅ Commit 27ab27b No errors.
src/workspace/dto/toggle-visibility.dto.ts Create src/workspace/dto/toggle-visibility.dto.ts with contents:
• Create a new DTO for the toggle visibility endpoint. This DTO should contain the workspace ID and the new visibility state.
✅ Commit d17115f No errors.
src/workspace/workspace.service.ts Modify src/workspace/workspace.service.ts with contents:
• Add a new method to toggle the visibility of a workspace. This method will update the visibility field of the workspace in the database.
• Modify the create workspace method to include the visibility state in the workspace creation data.
✅ Commit f9fd3b7 No errors.
src/workspace/dto/create-workspace.dto.ts Modify src/workspace/dto/create-workspace.dto.ts with contents:
• Add a visibility field to the CreateWorkspaceDto. This field will use the WorkspaceVisibility enum.
✅ Commit f9fd3b7 No errors. I have finished coding the issue. I am now reviewing it for completeness.

Step 5: 🔁 Code Review

Here are my self-reviews of my changes at sweep/add-visibility-state.

Here is the 1st review

Hello, great job on the changes so far. However, there are a few things that need to be addressed:

  • In src/workspace/dto/create-workspace.dto.ts, WorkspaceVisibility type is not imported. Please add the import statement at the top of the file.
  • In src/workspace/workspace.controller.ts, ToggleVisibilityDto type is not imported. Please add the import statement at the top of the file.
  • In src/workspace/workspace.service.ts, WorkspaceVisibility type is not imported. Please add the import statement at the top of the file.

Once these changes are made, your code should work as expected. Keep up the good work!

I finished incorporating these changes.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. Join Our Discord