CRUD for complex objects
Hi! I have two tables in my database
Sets
and Terms
. One set has many terms. Set can have any number of terms. I need API routes to do CRUD for both of them. Is it better to create a single route that will accept set object
and decide which term update or create. Or make two routes one for Set
and other for one Term
and call first Set
route then Term
route for each term one by one? Set also can be imported from file. I have and route that parses file and returns terms that must be stored if user confirms that import is fine.9 Replies
is it a one-to-many relationship, or many to many? ie, can a term belong to more than one set?
one-to-many, One set has many terms
and decide which term update or createhow is this a problem then? if a single term only ever belongs to a single set, for an
UpdateSet
action just take in something that can hold term IDs
if the term id is 0, its a new term, if the term id has a value, EF will handle it for youI can't decide what way is better - create one endpoint for creation, one to update one
Term
and send request for each edited term one by one or single endpoint where I send many terms both creation and update and decide on server what to do with each termAh. Given the relationship, I'd personally design this as part of the set endpoints
ie,
CreateSet
can create terms, and UpdateSet
can remove/create/update termsThat means I don't need separate endpoints like
CreateTerm
, UpdateTerm
, right?you could, but if you agree with me you can also skip it
sure, that's problem that I'm thinking how can I do it better instead of writing code..
wouldn't say thats a problem in itself
its a problem if you get hard-stuck because of overthinking
but thinking before coding is generally a good thing