title: How can I manage my API endpoint for an entity that has other related entities?
body: <p>I'm building a RESTful API with Spring.
  I am reading the docs and tutorials and most of them have just basic objects in their examples and I don't know how to combine all that into solving my current problem...</p>
  
  <p>I don't know how to handle 2 things here:</p>
  
  <ol>
  <li>What is the best way to handle the creation of my entity with an HTTP request? Should I send the IDs of the related entities in the body, in the query params? Should I just send the entire object?</li>
  <li>In this case, if I send the IDs of the related entities separately, I believe the <code>@Valid</code> annotation
  would trigger as invalid because the body would not have the objects
  the model asks for (<code>Employee</code> and <code>Customer</code>, in my case).</li>
  </ol>
  
  <p>This is the endpoint:</p>
  
  <pre><code>    @PostMapping("/orders")
      ResponseEntity&lt;EntityModel&lt;Order&gt;&gt; createOrder(@Valid @RequestBody Order order) {
          order.setStatus(Status.IN_PROGRESS);
          Order newOrder = repository.save(order);
  
          return ResponseEntity
              .created(linkTo(methodOn(OrderController.class).getOrder(newOrder.getId())).toUri())
              .body(assembler.toModel(newOrder));
      }
  </code></pre>
  
  <p>The entity I want to create and validate:</p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "Orders")
  public class Order {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      private Long id;
  
      @NotBlank
      @NotNull
      private String description;
  
      @NotBlank
      @NotNull
      private Status status;
  
      @NotNull
      @ManyToOne
      @JoinColumn(foreignKey = @ForeignKey(name = "employee_id_fk"))
      private Employee employee;
  
      @NotNull
      @ManyToOne
      @JoinColumn(foreignKey = @ForeignKey(name = "customer_id_fk"))
      private Customer customer;
  
      protected Order() {}
  
      public Order(String description) {
          this.description = description;
          this.status = Status.IN_PROGRESS;
      }
  }
  </code></pre>
  
  <p>Thanks a lot in advance for your help.</p>