Skip to content

ENH-008 β€” Replace orderedBy Free-Text with Structured User Reference 🟠 #65

Description

@hajk1

FreightOrder.orderedBy is a free-text String with only a @NotBlank constraint. Any arbitrary
value is accepted ("me", "ops-team", ""), there is no referential integrity, and orders
cannot be queried by a specific operator. This issue replaces the string field with an Operator
entity that represents an internal system user.

New entity: Operator

  • id β€” BIGINT PK
  • username β€” VARCHAR(50), UNIQUE, NOT NULL
  • fullName β€” VARCHAR(100)
  • email β€” VARCHAR(150), UNIQUE, NOT NULL
  • active β€” BOOLEAN, DEFAULT TRUE
  • createdAt / updatedAt β€” timestamps (via BaseEntity)

New endpoints:

  • POST /api/v1/operators β€” create an operator
  • GET /api/v1/operators β€” list all operators
  • GET /api/v1/operators/{id} β€” get a single operator

Changes to FreightOrder:

  • Remove String orderedBy
  • Add @ManyToOne(fetch = LAZY) Operator operator (FK operator_id)
  • CreateFreightOrderRequest: replace orderedBy: String with operatorId: Long
  • FreightOrderResponse: expose operatorId and operatorUsername

Migration:

  • Flyway V2__add_operators.sql β€” creates the operators table and adds the operator_id column
    to freight_orders
  • If seed data contains existing orderedBy strings, the migration should insert corresponding
    Operator rows and back-fill the FK

Hints:

  • This is a breaking API change β€” orderedBy is removed entirely, not deprecated alongside
    operatorId
  • Operator will be the natural entity to link to an auth identity if authentication is introduced
    later; keep the model clean for that

Acceptance criteria:

  • Operator entity, repository, service, and controller created
  • POST, GET (list), GET (by id) endpoints working under /api/v1/operators
  • FreightOrder.orderedBy (String) removed; operator (@ManyToOne) added
  • CreateFreightOrderRequest uses operatorId: Long
  • FreightOrderResponse exposes operatorId and operatorUsername
  • V2__add_operators.sql Flyway migration present
  • FreightOrderControllerTest and FreightOrderServiceTest updated to use operatorId
  • Existing seed data migrated in the SQL file if applicable
  • Code is formatted

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions