0

Imagine I have the next two entities

public int Id {get;set;}
public string Desc {get;set;}
public int AssignmentId {get;set;}
public Assignment Assignment {get;set;}

class Assignment{
public int Id {get; set;}
public ICollection<Task> Tasks {get;set;}
}

What would be the best way to POST a task to an existing assignment?

How would endpoint and incoming DTO look like?

  1. /assignments/3/tasks

Receive

TaskDTO1{
string Desc
}

and assignment id to your controller method, call service method that will retrieve assignment by the id and append a task to its task collection, then save

  1. /tasks/

Receive

TaskDTO2{
string Desc,
int AssignmentId
}

in your controller method, call service method that will create a task entity, retrieve a corresponding assignment by id (AssignmentId from dto2) and fill the Task.Assignment with this assignment, then save

Which way looks better to you? Why?

Bookuha
  • 13
  • 5
  • Hi @Bookuha, I think the second way is better. The second way will not expose the id from the url which is more secure I think. – Rena Nov 28 '22 at 02:45

0 Answers0