Reputation: 47
I want to develop a microservice application in spring boot. I have created 2 services which are called user service and recipe service.
My question is that one user can have multiple recipes but I cannot determine the type of the recipes field. I cannot use private List<Recipe> recipes
because I want that each microservice should be independent. Do you have any idea?
If I determine like that private List<Long> recipes
how to do send a request with postman?
{
"id": 102,
"userName": "figen",
"email": 3,
"recipes":5,6,7 // line 5
}
this request is not working because of line 5
import org.springframework.data.mongodb.core.mapping.Document;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
//@Entity
@Document(collection = "User")
public class User {
@Id
private String id;
private String userName;
private Long email;
private List<Long> recipes; // I cannot determine this type(one-to-many relationship)
public User(){
}
public User(String id, String userName, Long email,List<Long> recipes) {
this.id = id;
this.userName = userName;
this.email = email;
this.notes = recipes;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Long getEmail() {
return email;
}
public void setEmail(Long email) {
this.email = email;
}
public List<Long> getRecipes() {
return recipes;
}
public void setRecipes(List<Long> recipes) {
this.notes = recipes;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", userName='" + userName + '\'' +
", email='" + email + '\'' +
", recipes=" + recipes+
'}';
}
}
Upvotes: 0
Views: 466
Reputation: 160
it will work after adding the [] at recipes.
{
"id": 102,
"userName": "figen",
"email": 3,
"recipes":[5,6,7]
}
Upvotes: 1
Reputation: 13817
"recipes":5,6,7
will cause an error because recipes have type List
. You can pass List via postman as following
"intArrayName" : [111,222,333]
"stringArrayName" : ["a","b","c"]
For above UseCase, you can send it as
{
"id": 102,
"userName": "figen",
"email": 3,
"recipes":[5,6,7]
}
Upvotes: 0