Skip to content

feat: implement custody return flow with escrow resolution and trust …#90

Open
Christopherdominic wants to merge 5 commits intoamina69:mainfrom
Christopherdominic:feature/custody-return-flow-63
Open

feat: implement custody return flow with escrow resolution and trust …#90
Christopherdominic wants to merge 5 commits intoamina69:mainfrom
Christopherdominic:feature/custody-return-flow-63

Conversation

@Christopherdominic
Copy link
Copy Markdown

…updates

  • Add returnCustody() endpoint for successful custody returns
  • Add violationCustody() endpoint for custody violations (admin only)
  • Implement escrow release on successful return
  • Implement escrow refund on violation
  • Create TrustScoreService for managing user trust scores
  • Reward +5 trust score on successful custody return
  • Penalize -15 trust score on custody violation
  • Update pet status to AVAILABLE after custody ends
  • Emit CUSTODY_RETURNED and ESCROW_RELEASED events
  • Add comprehensive unit tests for return flow

Closes #63

PR: Pet Status Lifecycle Implementation (Closes #17)

Overview

This PR implements the Pet Status Lifecycle feature, enforcing a state machine for pet status transitions throughout the adoption and custody process. It ensures that pets can only move between valid states, maintaining data integrity and preventing invalid transitions.

Features

  • State Machine for Pet Status:
    • Enforces valid transitions: AVAILABLE → PENDING → ADOPTED, AVAILABLE → IN_CUSTODY → AVAILABLE, etc.
    • Blocks invalid transitions (e.g., ADOPTED → PENDING, IN_CUSTODY → ADOPTED).
    • Allows admin override for ADOPTED → AVAILABLE (return scenario).
  • Transition Validation:
    • Centralized validator for all status changes.
    • Throws clear errors for invalid transitions.
    • Logs all status changes for audit trail.
  • API Endpoints:
    • PATCH /pets/:id/status: Update pet status with validation and audit logging.
    • GET /pets/:id/transitions: Get allowed transitions and current status for a pet.
    • GET /pets/:id/transitions/allowed: Get allowed transitions for the current user (role-aware).
  • Swagger Documentation:
    • All endpoints are fully documented and visible in Swagger UI.
    • Request/response schemas and examples included.
  • Test Coverage:
    • Unit tests for all valid and invalid transitions.
    • Tests for admin overrides and edge cases.

Acceptance Criteria

  • Valid transitions work as expected.
  • Invalid transitions are blocked with clear error messages.
  • Admin can override certain restrictions.
  • Status changes are logged.
  • All endpoints are documented in Swagger.
  • Unit tests cover all scenarios.

Closes


Please review the implementation and test the endpoints via Swagger UI (/api/docs).

…updates

- Add returnCustody() endpoint for successful custody returns
- Add violationCustody() endpoint for custody violations (admin only)
- Implement escrow release on successful return
- Implement escrow refund on violation
- Create TrustScoreService for managing user trust scores
- Reward +5 trust score on successful custody return
- Penalize -15 trust score on custody violation
- Update pet status to AVAILABLE after custody ends
- Emit CUSTODY_RETURNED and ESCROW_RELEASED events
- Add comprehensive unit tests for return flow

Closes amina69#63
- Remove manual pet status updates (now derived from custody/adoption status)
- Remove PetsService dependency from custody module
- Update tests to reflect new architecture
- Pet availability automatically updates when custody status changes to RETURNED/VIOLATION
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.

Custody Return Flow Pet Status Lifecycle

1 participant