I have the following JPA models:
Issue
@Entity
public class Issue {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String title;
private String text;
@ManyToOne
@JoinColumn(name="user_id")
private User user;
public Issue() {}
public Issue(String title, String text) {
this.title = title;
this.text = text;
}
public long getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
@Override
public String toString() {
return "Issue [id=" + id + ", title=" + title + ", text=" + text + ", user=" + user + "]";
}
}
User
@Entity
public class User {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String username;
private String firstname;
private String lastname;
public User() {}
public User(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
@Override
public String toString() {
return "User [id=" + id + ", username=" + username + ", firstname=" + firstname + ", lastname=" + lastname
+ "]";
}
}
And an Issue repository that extends PagingAndSortingRepository
and contains the method List<Issue> findByUser(User user);
See below:
public interface IssueRepository extends PagingAndSortingRepository<Issue,Long> {
List<Issue> findByUser(User user);
}
I'm trying to find a way to navigate these relationships with HTTP calls, namely how do I call findByUser(User user)
and get all the issues for that user?
Using the following call I can execute that particular query:
GET http://localhost:8080/issues/search/findByUser
But I'm unclear what I should be providing as the User? Do I send the id as a query param? Do I construct an object and send that as a query param? Am I just modeling this the wrong way?
I'd like to get back a JSON list containing all the Issues for this particular User.
Thanks in advance for any help or guidance.