Skip to content

[LFXV2-947] Add NATS message handler for getting parent project UID#38

Merged
andrest50 merged 2 commits intomainfrom
andrest50/get-parent-uid
Dec 31, 2025
Merged

[LFXV2-947] Add NATS message handler for getting parent project UID#38
andrest50 merged 2 commits intomainfrom
andrest50/get-parent-uid

Conversation

@andrest50
Copy link
Contributor

Summary

  • Added new NATS message handler lfx.projects-api.get_parent_uid to retrieve a project's parent UID
  • Enables other services to navigate project hierarchies by querying parent relationships
  • Handler follows the same pattern as existing attribute handlers (get_name, get_slug, get_logo)
  • Returns the parent_uid field from a project, or empty string for root projects

Changes

Core Implementation

  • Added ProjectGetParentUIDSubject constant in pkg/constants/nats.go
  • Implemented HandleProjectGetParentUID handler in internal/service/project_handlers.go
  • Registered handler in handlers map and NATS subscription list in cmd/project-api/main.go

Testing

  • Added comprehensive unit tests in internal/service/project_handlers_test.go
  • Test coverage includes:
    • Successful retrieval of parent UID
    • Handling of projects with no parent (root projects)
    • Project not found error
    • Invalid UUID format error
    • Empty project UID error

Documentation & Improvements

  • Updated README.md to document the new NATS message handler
  • Improved error logging in GetProjectBase and GetProjectBaseWithRevision to show actual underlying errors instead of generic "internal error"

Ticket

https://linuxfoundation.atlassian.net/browse/LFXV2-947

🤖 Generated with Claude Code

Adds a new NATS message handler that retrieves a project's parent UID
given a project UID. This enables other services to navigate project
hierarchies by querying parent relationships.

Changes:
- Add ProjectGetParentUIDSubject constant (lfx.projects-api.get_parent_uid)
- Implement HandleProjectGetParentUID handler using existing attribute helper
- Register handler in handlers map and NATS subscription list
- Add comprehensive unit tests with 5 test cases covering success and error scenarios
- Update README.md to document the new NATS message handler
- Improve error logging in GetProjectBase and GetProjectBaseWithRevision
  to show actual underlying errors instead of just "internal error"

The handler follows the same pattern as other attribute handlers (get_name,
get_slug, get_logo) and returns the parent_uid field from a project. If a
project has no parent (root project), an empty string is returned.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Andres Tobon <andrest2455@gmail.com>
Copilot AI review requested due to automatic review settings December 30, 2025 22:24
@andrest50 andrest50 requested a review from a team as a code owner December 30, 2025 22:24
@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

Walkthrough

Adds a new NATS subject and handler to return a project's parent UID; registers the subject for subscription, adds a constant, augments repository error logging, updates tests (including a duplicated test function), and bumps the Helm chart version.

Changes

Cohort / File(s) Summary
Constants
pkg/constants/nats.go
Added exported constant ProjectGetParentUIDSubject = "lfx.projects-api.get_parent_uid".
Service handler
internal/service/project_handlers.go
Added HandleProjectGetParentUID(ctx context.Context, msg domain.Message) ([]byte, error) and registered it in the handlers map to reuse existing attribute retrieval flow for "parent_uid".
Service startup / subscription
cmd/project-api/main.go
Included the new subject in the list of NATS subjects subscribed via QueueSubscribe.
Repository observability
internal/infrastructure/nats/repository.go
Added error logging when KV lookups in GetProjectBase and GetProjectBaseWithRevision return non-key-not-found errors; returns domain.ErrInternal afterward.
Tests
internal/service/project_handlers_test.go
Added tests for ProjectGetParentUID covering success, empty parent UID, not found, invalid UUID, and empty UID. Note: the new TestProjectsService_HandleProjectGetParentUID appears duplicated in the file.
Docs
README.md
Documented new NATS subject lfx.projects-api.get_parent_uid in the message handlers list.
Charts / Version
charts/lfx-v2-project-service/Chart.yaml
Bumped Helm chart version 0.5.30.5.4.
Build tooling
Makefile
Updated GOA_VERSION and adjusted Goa CLI install path/version pinning.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant NATS as NATS<br/>'lfx.projects-api.get_parent_uid'
    participant Handler as ProjectsService<br/>HandleProjectGetParentUID
    participant Repo as KV Repository<br/>GetProjectBase

    Client->>NATS: Publish message (project_uid)
    NATS->>Handler: Deliver message
    Handler->>Handler: Validate project_uid
    rect rgb(230,240,255)
        Handler->>Repo: GetProjectBase(project_uid)
        alt KV Success
            Repo-->>Handler: Project data (includes parent_uid)
            Handler->>Handler: Extract parent_uid
            Handler-->>NATS: Respond with parent_uid JSON
        else Not found
            Repo-->>Handler: KeyNotFound
            Handler-->>NATS: Respond 404
        else KV error
            Repo-->>Handler: Error (logged)
            Handler-->>NATS: Respond internal error
        end
    end
    NATS-->>Client: Response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Out of Scope Changes check ❓ Inconclusive While most changes align with the linked issue, the Makefile update to GOA_VERSION (v3 to v3.22.6) and improved error logging appear to be enhancements beyond the core requirement of adding the parent UID handler. Clarify whether the Makefile version pinning and error logging improvements are intentional enhancements or should be split into a separate PR focused on the parent UID handler.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a NATS message handler for getting parent project UID, which matches the changeset.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the implementation, testing, and improvements made for the new message handler.
Linked Issues check ✅ Passed The pull request fully implements the requirements from LFXV2-947: adds a message handler for retrieving a project's parent UID, follows existing patterns (get_name, get_slug, get_logo), and enables service-to-service parent relationship queries.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch andrest50/get-parent-uid

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 689080c and 8f666f6.

⛔ Files ignored due to path filters (14)
  • api/project/v1/gen/http/cli/lfx_v2_project_service/cli.go is excluded by !**/gen/**
  • api/project/v1/gen/http/openapi.json is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/client/cli.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/client/client.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/client/encode_decode.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/client/paths.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/client/types.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/server/encode_decode.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/server/paths.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/server/server.go is excluded by !**/gen/**
  • api/project/v1/gen/http/project_service/server/types.go is excluded by !**/gen/**
  • api/project/v1/gen/project_service/client.go is excluded by !**/gen/**
  • api/project/v1/gen/project_service/endpoints.go is excluded by !**/gen/**
  • api/project/v1/gen/project_service/service.go is excluded by !**/gen/**
📒 Files selected for processing (1)
  • Makefile
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build and Test
  • GitHub Check: MegaLinter
🔇 Additional comments (1)
Makefile (1)

13-13: Good improvement to version pinning and installation path.

The changes properly pin Goa to a specific version (v3.22.6) and fix the installation command to respect the version variable. The old pattern used @latest which ignored the GOA_VERSION variable; the new pattern correctly installs the pinned version. Goa v3.22.6 (released October 19, 2025) contains only improvements and bug fixes with no breaking changes.

This improves build reproducibility and consistency.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

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 adds a new NATS message handler to retrieve a project's parent UID, enabling other services to navigate project hierarchies. The implementation follows the established pattern of existing attribute handlers (get_name, get_slug, get_logo).

  • Added NATS subject handler lfx.projects-api.get_parent_uid for querying parent project UIDs
  • Implemented comprehensive test coverage including edge cases (empty parent, not found, invalid UUID)
  • Enhanced error logging in repository methods to expose underlying errors instead of generic messages

Reviewed changes

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

Show a summary per file
File Description
pkg/constants/nats.go Added ProjectGetParentUIDSubject constant for the new NATS subject
internal/service/project_handlers.go Implemented HandleProjectGetParentUID handler using the shared attribute helper pattern
cmd/project-api/main.go Registered the new handler in the NATS subscription list
internal/service/project_handlers_test.go Added comprehensive unit tests for the new handler covering success and error scenarios
internal/infrastructure/nats/repository.go Enhanced error logging in GetProjectBase and GetProjectBaseWithRevision to show underlying errors
README.md Updated documentation to include the new NATS message handler
charts/lfx-v2-project-service/Chart.yaml Bumped chart version from 0.5.3 to 0.5.4

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Updates the Makefile to pin the Goa framework version from v3 (latest)
to v3.22.6 to ensure consistent code generation and build compatibility
across development environments.

Changes:
- Pin GOA_VERSION to v3.22.6 in Makefile
- Update goa install command to use the pinned version
- Regenerate API code with goa v3.22.6

This ensures all developers and CI/CD pipelines use the same version
of Goa, preventing code generation inconsistencies.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: Andres Tobon <andrest2455@gmail.com>

// HandleProjectGetParentUID is the message handler for the project-get-parent-uid subject.
func (s *ProjectsService) HandleProjectGetParentUID(ctx context.Context, msg domain.Message) ([]byte, error) {
return s.handleProjectGetAttribute(ctx, msg, constants.ProjectGetParentUIDSubject, "parent_uid")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is very handy!

@andrest50 andrest50 merged commit d830254 into main Dec 31, 2025
6 checks passed
@andrest50 andrest50 deleted the andrest50/get-parent-uid branch December 31, 2025 13:53
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