I 'm building an application to store and retrieve books, but I have an issue with retrieving data from the db.
I'm using REST and testing with postman. Everything works OK. Currently I have a series of methods written in Java at the backend like so
@Override
@POST
@Path("/add")
//@Produces("application/json")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response addBook(Book book) {
dbAccess.connectToDb();
return dbAccess.addBook(book);
}
@Override
@DELETE
@Path("/{id}/delete")
@Produces("application/json")
public Response deleteBook(@PathParam("id") int id) {
dbAccess.connectToDb();
return dbAccess.deleteBook(id);
}
@Override
@GET
@Path("/{id}/get")
@Produces("application/json")
public Book getBook(@PathParam("id") int id) {
dbAccess.connectToDb();
return dbAccess.getBook(id);
}
So in postman I have a request like http://localhost:8080/book-storage-REST/book/15/get to retrieve a record.
Eventually I will write a front end, maybe in angular, which allows users to do their searches and display the results back to them.
Now, in the real world, a user of course wouldn't use an ID to search for a record, but he/she will be more likely to use the author name or book title. So my question is:
do I need to rewrite the methods above and not use an id parameter or should the front end do the job of taking a search term (title or author), query the db to find the equivalent id, do the necessry filtering in case of more than 1 record and only then, call the relevant methods above wth only one ID?