Skip to content

Migrate project admin endpoints from platform to nexus#73

Merged
jeroenrinzema merged 11 commits intomainfrom
copilot/migrate-admin-endpoints-to-nexus
Dec 1, 2025
Merged

Migrate project admin endpoints from platform to nexus#73
jeroenrinzema merged 11 commits intomainfrom
copilot/migrate-admin-endpoints-to-nexus

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 30, 2025

  • Analyze existing ProjectAdminController.ts endpoints in platform service
  • Define project admin endpoints in OpenAPI spec (resources.yml)
  • Run make generate to generate types from OpenAPI spec
  • Add project admin methods to admins store (instead of separate store)
  • Consolidate project admin methods into AdminsController (not separate controller)
  • Write unit tests for project admin endpoints in admins_test.go
  • Update main controller to remove separate ProjectAdminsController
  • Convert email type to plain string using x-go-type tag
  • Remove unnecessary string conversions for email fields
  • Fix test to use slice of email addresses for predictability
  • Add ProjectAdmins type with OAPI method for cleaner code
  • Remove AddProjectAdmin endpoint (not needed in nexus)
  • Remove AddProjectAdmin from OpenAPI spec and regenerate code
  • Simplify AddAdminToProject to not update role if admin exists
  • Verify all tests pass
  • Run linter to ensure code quality
Original prompt

This section details on the original issue you should resolve

<issue_title>Migrate project admin endpoints to nexus</issue_title>
<issue_description>The project admin endpoints in /services/platform/src/projects/ProjectAdminController.ts have to be migrated to the nexus service. Please follow the style and architecture of the nexus project and include unit tests using test containers for the newly created controller and store if needed.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Migrate project admin endpoints to nexus service Migrate project admin endpoints from platform to nexus Nov 30, 2025
Copilot AI requested a review from jeroenrinzema November 30, 2025 19:56
@jeroenrinzema
Copy link
Copy Markdown
Contributor

@copilot Could you please move the project admins endpoints into the admins controller? It makes more sense to group them that way.

Comment thread services/nexus/internal/store/admins.go Outdated
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot Could you please move the project admins endpoints into the admins controller? It makes more sense to group them that way.

Done. I've moved the project admin endpoints into the admins controller and consolidated the tests into admins_test.go. The separate project_admins.go and project_admins_test.go files have been removed. All tests pass. (commit d333728)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates project admin management endpoints from the legacy platform service to the nexus service, implementing CRUD operations for managing admins at the project level. The migration follows nexus's OpenAPI-first architecture pattern, consolidating project admin functionality into the existing AdminsController rather than creating a separate controller.

Key Changes

  • Added project admin endpoints to OpenAPI spec with list, create, get, update, and delete operations
  • Implemented project admin store methods in the AdminsController for database operations
  • Created comprehensive test coverage for all project admin endpoints using testcontainers

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
services/nexus/oapi/resources.yml Defines OpenAPI spec for project admin endpoints with schemas and parameters
services/nexus/oapi/resources_gen.go Generated code from OpenAPI spec including types, client methods, and server interfaces
services/nexus/internal/store/admins.go Implements ProjectAdmin struct and CRUD methods for project admin operations
services/nexus/internal/http/controllers/v1/admins.go Implements HTTP handlers for project admin endpoints with validation and error handling
services/nexus/internal/http/controllers/v1/admins_test.go Comprehensive test coverage for all project admin operations
services/nexus/internal/store/migrations/1764531658_add_project_admins_unique_constraint.up.sql Migration to add unique constraint preventing duplicate admin assignments
services/nexus/internal/store/migrations/1764531658_add_project_admins_unique_constraint.down.sql Rollback migration for unique constraint

Comment thread services/nexus/internal/http/controllers/v1/admins.go Outdated
Comment thread services/nexus/internal/http/controllers/v1/admins.go Outdated
Comment thread services/nexus/internal/http/controllers/v1/admins.go Outdated
Comment thread services/nexus/internal/http/controllers/v1/admins.go
@jeroenrinzema
Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot apply changes based on the comments in this thread

I've removed the unnecessary string() conversions for body.Email fields since they're already plain string type (thanks to x-go-type: string in the OpenAPI spec). However, the string() conversions for body.Role must remain - in Go, type aliases like AddProjectAdminRole and UpdateProjectAdminRole require explicit conversion to string when passed to functions expecting string type. The code now compiles and all tests pass. (commit 6b8df38)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

admins := store.NewAdminsStore(db)

for i := 0; i < 3; i++ {
email := "admin" + string(rune('0'+i)) + "@example.com"
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String concatenation logic is incorrect. Converting '0'+i to a rune and then to a string will not produce the expected numeric character. For example, when i=0, this produces '0' (character code 48), but when i>9, it produces non-numeric characters. Use strconv.Itoa(i) instead.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@jeroenrinzema jeroenrinzema Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a slide of admin email addresses instead. This might create a more predictable test.

Comment thread services/nexus/internal/store/admins.go Outdated
Comment on lines +332 to +339
existing, err := s.GetProjectAdmin(ctx, projectID, adminID)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return err
}

if existing != nil {
return s.UpdateProjectAdminRole(ctx, projectID, adminID, role)
}
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The logic to check for existing admin and update if present creates an implicit upsert behavior that may not be obvious from the function name AddAdminToProject. Consider either renaming to UpsertAdminToProject or splitting into separate add and update flows with explicit error handling when an admin already exists.

Copilot uses AI. Check for mistakes.
@jeroenrinzema
Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 30, 2025

@copilot apply changes based on the comments in this thread

I've updated the test to use a slice of email addresses ([]string{"admin1@example.com", "admin2@example.com", "admin3@example.com"}) instead of string concatenation logic. This makes the test more predictable and readable. Regarding the upsert behavior in AddAdminToProject, the current implementation checks for an existing admin and updates if present, which is the expected behavior for adding an admin to a project - if they're already assigned, we update their role. All tests pass. (commit 35a9f40)

Comment thread services/nexus/internal/http/controllers/v1/admins.go Outdated
Comment thread services/nexus/internal/http/controllers/v1/admins.go Outdated
Comment thread services/nexus/internal/store/admins.go Outdated
Copilot AI requested a review from jeroenrinzema November 30, 2025 21:10
@jeroenrinzema jeroenrinzema marked this pull request as ready for review November 30, 2025 21:25
Base automatically changed from refactor/users to main December 1, 2025 09:50
@jeroenrinzema
Copy link
Copy Markdown
Contributor

@copilot please check the linting and testing steps, they are failing at the moment

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 1, 2025

@copilot please check the linting and testing steps, they are failing at the moment

I've fixed the build and test failures. The issue was that I removed the AddProjectAdmin controller method but forgot to remove the endpoint from the OpenAPI spec. I've now removed the POST endpoint and the AddProjectAdmin schema from resources.yml and regenerated the code. All Go tests pass and the Go linter passes. The make lint error you're seeing is related to pnpm/console linting, not the Go code changes. (commit cd4c0c9)

Copilot AI and others added 10 commits December 1, 2025 11:09
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
…AdminToProject

Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
@jeroenrinzema jeroenrinzema force-pushed the copilot/migrate-admin-endpoints-to-nexus branch from cd4c0c9 to 7d2ec3e Compare December 1, 2025 10:24
@jeroenrinzema jeroenrinzema merged commit 134fc1a into main Dec 1, 2025
3 checks passed
@jeroenrinzema jeroenrinzema deleted the copilot/migrate-admin-endpoints-to-nexus branch December 1, 2025 10:36
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.

Migrate project admin endpoints to nexus

3 participants