Many to Many in RESTFUL API [closed] - rest

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
For example let's say I have employees and restaurant resources:
Employee {ID, Name, Gender, Birthday} exposed to GET\POST\PUT\DELETE
Restaurant {ID, Name, Address, Business_Number} exposed to GET\POST\PUT\DELETE
Also, I have many to many resources:
Restaurant_Has_Employee {ID, Employee_ID, Restaurant_ID, Employee_Work_In_Restaurant}
So the question is, what is the best practise to expose GET\POST\PUT\DELETE to this resource?

I always do this using the following pattern:
parents/{id}/children
In your case, if for the sake of the example a given restaurant had the id of 55, then the url GET restaurants/55/employees would a return a list of employees that belong to that restaurant, and POST restaurants/55/employees would be used for inserting a new employee to that restaurant's record. PUT isn't really relevant here, since it should be used directly on the employee endpoint, but DELETE restaurants/55/employees could be used to delete all employees belonging to that restaurant.
BTW, this looks like a duplicate of this question.
Edit: Made path nouns plural

Related

REST( GET method ) naming for getting a list of list of objects

I have a list of courses with a list of students. The idea is that a student can attend multiple courses.
The requirement is to return a unified list of courses-students where the "key" is like courseId + studentId. The GET result will be like:
courseId, courseName, studentId, studentName,...
My question is, which is the best approach to define this REST GET method. I have two solutions and any idea is welcome.
GET:api-name/v1/courses/students?version=5 - mening return from all courses the all students
GET:api-name/v1/courses-students?version=5 - in this case, is a dedicated method as courses-students
Any idea is welcome. Many thanks!
Update:
I was going to use solution 2.
Also, the remark that this relation could be considered a new resource is a strong argument.
I would bet on the second option, since you are exposing a new resource, which is the relationship between courses and students - even identifiable with that "key" relating the two IDs.
Going with this option may then allow you, for example, to find the new resource with the key, or filter this new resource with query string parameters (e.g. api-name/v1/courses-students?courseId=12,45&studentId=32,67), or request for students of an individual course (api-name/v1/courses/{courseId}/students), or for courses of an individual student (api-name/v1/students/{studentId}/courses).
There is a question with good answers on this topic here.

How to Model data using UML for this situation? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The Situtation is that there is a data named Progress which has 2 valid values (suppose 'A' and B). this means Progress = 'A' or Progress = B. A is just a string, but B is not string. B itself has some valid values (suppose strings: 'V1', 'V2', 'V3'). progress can be A which is a string or can be B which is 'V1', 'V2' or 'V3'. How to model this data?
If B is just a simple string (just like A) so we can define Progress as a string but i think one solution is defining progress as a class which has two children: Class A & Class B. Class B has 2 fields: Id & state so we have 3 IDs which correspond to 3 states: 'V1', 'V2' and 'V3' and Class A with a const field called state with fixed value 'A'. so with this solution progress can be objects A or B which has a state.
Please help me if such design is not good or if there is any design pattern for such situation.
First of all, since I'm not 100% sure if you speak about classes in a typed language or objects in a dynamically typed language, I'd like to clarify the obvious: UML uses typed objects. So object instances such as progress must be of a class Progress that defines their properties and behaviors.
If your question would really be only about data and values, since there is no overlap between 'A' and 'Vn', the easiest way would be to define Progress as a class with a sole property that is of type String.
But from your narrative, I understand that it's not just about data but also about semantics and potentially object behaviors:
One way to address your requirement is to use class specialisation: Progress would have a generalization set with two specializations, ProgressString (with a sole String property) and B (with itself having a string property). Moreover the generalization set would have the constraint {complete, disjoint}
Another way is to use object composition (caution do not confuse object composition with UML composition): Progress would have two properties, a String and a B (defined as above). If you'd give them a multiplicity of 0..1 you could use a constraint to make sure that it's either the one or the other but not the two.
In both cases, if you want the string to be limited to the possible values that you have documented, you'd need to add a constraint. Alternatively, you could go for a more expressive model, using an «enumeration» to make explicit the possible values (as qwerty_so suggested in the comments).

Plugin update field from a related entity [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to build a plugin for updating a field from a related entity.
On Entity Agreement I have two fields: field A(look-up Account) and field B(look-up Contact)
I have to check if an option set field from Account(field A) is one specific value, then to update an option set field from Contact(field B).
That's all. Thanks!
Entity agreement = (Entity)context.InputParameters["Target"]; // this is your target entity from which plugin is firing.
// Now do whatever your check you wish to perform
// once you are ready to update lookupAccount Record below code will work
Entity lookupAccount = new Entity();
lookupAccount.LogicalName = "account";
lookupAccount.Id = agreement.GetAttributeValue<EntityReference>("field A").Id;
lookupAccount["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupAccount);
// In similar way you can perform update for ook-up Contact)
Entity lookupContact = new Entity();
lookupContact.LogicalName = "contact";
lookupContact.Id = agreement.GetAttributeValue<EntityReference>("field B").Id;
lookupContact["optionSetFieldToUpdate"]= new OptionSetValue(1234);
orgService.Update(lookupContact);

Complex and multiple connected database relations in MongoDB

I am currently trying to model a MongoDB database structure where the entities are very complex in relation to each other.
In my current collections, MongoDB queries are difficult or impossible to put into a single aggregation. Incidentally, I'm not a database specialist and have been working with MongoDB for only about half a year.
To keep it as simple as possible but necessary, this is my challenge:
I have newspaper articles that contain simple keywords, works (oevres, books, movies), persons and linked combinations of works and persons. In addition, the same people appear under different names in different articles.
Later, on the person view I want to show the following:
the links of the person with name and work and the respective articles
the articles in which the person appears without a work (by name)
the other keywords that are still in the article
In my structure I want to avoid that entities such as people occur multiple times. So these are my current collections:
Article
id
title
keywordRelations
KeywordRelation
id
type (single or combination)
simpleKeywordId (optional)
personNameConnectionIds (optional)
workIds (optional)
SimpleKeyword
id
value
PersonNameConnection
id
personId
nameInArticleId
Person
id
firstname
lastname
NameInArticle
id
name
type (e.g. abbreviation, synonyme)
Work
id
title
To meet the requirements, I would always have to create queries that range over 3 to 4 tables. Is that possible and useful with MongoDB?
Or is there an easier way and structure to achieve that?

Update a composed entity in greenDao

Let say i have a business domain in which there are two entities, Survey and Question, in OOP terms, the Survey has QuestionsList, the greenDao generation getQuestions method which returns a list of questions resolving 1:M relation from Survey to Question, but there is no method like setQuestions( questionList) which will take a list of question to update. How can i update the questionList for the Survey entity ?
you can use:
getQuestions().add(Question);
but for setting Question parent you should set ParentId for your Question and then add it to QuestionList of Survey. ParentId is the foreign-key of Question which links a question to a survey.
Remember that you must store Question after these changes.