Skip to content

feat: Expose source of stand assignment in API#1817

Merged
kristiankunc merged 12 commits intoVATSIM-UK:mainfrom
MrAdder:issue-1745
Mar 17, 2026
Merged

feat: Expose source of stand assignment in API#1817
kristiankunc merged 12 commits intoVATSIM-UK:mainfrom
MrAdder:issue-1745

Conversation

@MrAdder
Copy link
Contributor

@MrAdder MrAdder commented Feb 27, 2026

PR Summary

Fixes #1745

Persists and exposes the source of each stand assignment so plugin clients can determine how an assignment was made.

What changed

  • Added assignment_source column to stand_assignments (migration with DB default of system_auto)
  • Added source constants to StandAssignment:
    • SOURCE_USER (manual) — explicitly assigned by a controller
    • SOURCE_RESERVATION_ALLOCATOR (reservation_allocator) — pilot-requested via UserRequestedArrivalStandAllocator
    • SOURCE_VAA_ALLOCATOR (vaa_allocator) — VAA reservation allocators
    • SOURCE_SYSTEM (system_auto) — system/auto allocation fallback
  • assignment_source is written on every assignment creation via assignmentSourceFromType() in StandAssignmentsService
  • assignment_source is now returned by:
    • GET /stand/assignment (all assignments)
    • GET /stand/assignment/{callsign} (single assignment)
    • StandAssignedEvent real-time broadcast
  • StandUnassignedEvent kept minimal (callsign only — source not meaningful on unassign)
  • Removed unused assignmentHistory relation and eager load

Backward compatibility

Purely additive — assignment_source is a new key alongside existing fields in all responses.

Tests

  • Updated controller and event tests to assert assignment_source in responses
  • Added explicit service tests proving source is set correctly for user, reservation allocator, and system fallback assignment types

@MrAdder
Copy link
Contributor Author

MrAdder commented Feb 27, 2026

Currently draft while I look into the Plugin side of things will also need changes in Lists_SMR and Lists as looking into adding this as a tag item

@kristiankunc
Copy link
Contributor

kristiankunc commented Mar 16, 2026

Kept existing fields for compatibility:

* `assigned_by_reservation_allocator`

* `assigned_by_pilot_request`

What do you mean? Those fields are not currently in the API so there is no backwards compatibility? I'd probably scrap the assignment_status field and let's stick to assignment_source since we can easily use it in the plugin.

Let's not overcomplicate the logic. Just a simple database field of the source + etxnesion to the API endpoints should suffice.

@kristiankunc
Copy link
Contributor

I might just be missing it but where are we assigning the source field? I think I'm seeing only logic to expose it via the API but we gotta set it beforehand since I don't think we currently do that.

@MrAdder
Copy link
Contributor Author

MrAdder commented Mar 16, 2026

I might just be missing it but where are we assigning the source field? I think I'm seeing only logic to expose it via the API but we gotta set it beforehand since I don't think we currently do that.

Good shout — we are setting assignment_source before exposing it via the API.

It’s persisted in the assignment write path here:

The value is derived from assignment type here:

So the API endpoints are returning stored data, not deriving source at read time.

There’s also a DB-level fallback default of system_auto:

@MrAdder
Copy link
Contributor Author

MrAdder commented Mar 16, 2026

Moving this out of Draft for Copilot to look at this aswell

@MrAdder MrAdder marked this pull request as ready for review March 16, 2026 17:59
Copilot AI review requested due to automatic review settings March 16, 2026 17:59
Copy link
Contributor

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

Adds an assignment_source field to stand assignments so API consumers and real-time subscribers can tell where an assignment originated.

Changes:

  • Added assignment_source column + model constants for canonical sources (manual, reservation_allocator, vaa_allocator, system_auto).
  • Populated assignment_source during assignment creation based on assignment type/allocator and exposed it in REST + broadcast payloads.
  • Updated unit/functional tests to assert the new field.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/Models/Stand/StandAssignment.php Adds source constants, fillable field, and an assignmentHistory relation.
app/Services/Stand/StandAssignmentsService.php Sets assignment_source on create/update and tweaks unassign event dispatch.
app/Http/Controllers/StandController.php Includes assignment_source in stand assignment REST responses and adjusts single-assignment payload shape.
app/Events/StandAssignedEvent.php Adds assignment_source to broadcast payload.
database/migrations/2026_03_16_120000_add_assignment_source_to_stand_assignments_table.php Adds the new DB column with a default value.
tests/app/Services/Stand/StandAssignmentsServiceTest.php Adds coverage for source mapping behavior.
tests/app/Http/Controllers/StandControllerTest.php Updates API response assertions for assignment_source and adjusts helper.
tests/app/Events/StandAssignedEventTest.php Updates event payload expectations to include assignment_source.

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

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

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

Adds persistence and API exposure for how each stand assignment was created, so plugin clients can distinguish manual vs allocator/system assignments (Fixes #1745).

Changes:

  • Adds assignment_source to stand_assignments with a DB default of system_auto.
  • Populates assignment_source on assignment creation in StandAssignmentsService via assignmentSourceFromType().
  • Exposes assignment_source in GET /stand/assignment, GET /stand/assignment/{callsign}, and StandAssignedEvent broadcasts; updates tests accordingly.

Reviewed changes

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

Show a summary per file
File Description
database/migrations/2026_03_16_120000_add_assignment_source_to_stand_assignments_table.php Adds the assignment_source column with default system_auto.
app/Models/Stand/StandAssignment.php Defines source constants and makes assignment_source mass-assignable.
app/Services/Stand/StandAssignmentsService.php Sets assignment_source on create/update; adds source mapping helper; tweaks unassign event helper signature.
app/Http/Controllers/StandController.php Returns assignment_source in stand assignment API responses (and adjusts single-assignment payload).
app/Events/StandAssignedEvent.php Includes assignment_source in broadcast payload.
tests/app/Services/Stand/StandAssignmentsServiceTest.php Adds assertions/tests for persisted assignment_source on creation.
tests/app/Http/Controllers/StandControllerTest.php Updates API response expectations to include assignment_source and adjusts helper.
tests/app/Events/StandAssignedEventTest.php Updates broadcast payload assertions to include assignment_source.

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

You can also share your feedback on Copilot code review. Take the survey.

@sonarqubecloud
Copy link

@kristiankunc kristiankunc requested a review from CLC0609 March 16, 2026 18:45
@MrAdder
Copy link
Contributor Author

MrAdder commented Mar 16, 2026

currently working on issue 604 on the plugin side

@kristiankunc kristiankunc merged commit 511bc75 into VATSIM-UK:main Mar 17, 2026
6 checks passed
@VATSIMUK
Copy link
Contributor

🎉 This PR is included in version 6.64.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

Expose source of stand assignment in API

5 participants