I have the following entity:
@Data
@Entity
public class DailyEntry {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private LocalDate date;
private LocalTime startTime;
private LocalTime endTime;
private Duration breaks;
private String performanceRecord;
private EntryStatus status;
@ManyToOne
private Project project;
@ManyToOne
private Employee employee;
}
In the RepositoryRestResource
i have the following method defined:
@PostFilter("hasRole('ROLE_BACKOFFICE') or hasRole('ROLE_ADMIN')")
List<DailyEntry> findByProjectId(@Param("id") Long id);
Im able to call that API-method with the following URL for example:
http://localhost:8080/api/dailyEntries/search/findByProjectId?id=1005
This will return all dailyEntries
whose project has the id 1005
.
Thats how i call it on the client site:
projects.forEach(project => {
const httpParams = new HttpParams().set('id', project.id.toString());
const dailyEntriesObservable = this.dailyEntryService.search('findByProjectId', httpParams);
// the definition of the search method is not important
});
The problem is that in some cases i have around a hundret(and more) projects which resulsts in a hundret(and more) requests which slows things down. Instead of doing a request for every single project, i would like to do one single request for all projects. Should i just send the Ids of the project in the RequestBody
? How would the URL look like? Would it be something like http://localhost:8080/api/dailyEntries/search/findByProjectIds
with the Ids being in the RequestBody
? Ive never seen such a GET-request, so im not sure how the standarts here are for the REST-URL-Design or whether im doing something wrong and theres actually a better way to do it.