
io.sphere.internal.ReviewServiceImpl Maven / Gradle / Ivy
package io.sphere.internal;
import io.sphere.client.CommandRequest;
import io.sphere.client.FetchRequest;
import io.sphere.client.ProjectEndpoints;
import io.sphere.client.QueryRequest;
import io.sphere.client.model.QueryResult;
import io.sphere.client.model.VersionedId;
import io.sphere.client.shop.ApiMode;
import io.sphere.client.shop.ReviewService;
import io.sphere.client.shop.model.Review;
import io.sphere.client.shop.model.ReviewUpdate;
import io.sphere.internal.command.Command;
import io.sphere.internal.command.ReviewCommands;
import io.sphere.internal.command.UpdateCommand;
import io.sphere.internal.request.RequestFactory;
import com.google.common.base.Optional;
import org.codehaus.jackson.type.TypeReference;
public class ReviewServiceImpl extends ProjectScopedAPI implements ReviewService {
private final RequestFactory requestFactory;
public ReviewServiceImpl(RequestFactory requestFactory, ProjectEndpoints endpoints) {
super(endpoints);
this.requestFactory = requestFactory;
}
@Override public FetchRequest byId(String id) {
return requestFactory.createFetchRequest(
endpoints.reviews.byId(id),
Optional.absent(),
new TypeReference() {});
}
@Override public QueryRequest all() {
return requestFactory.createQueryRequest(
endpoints.reviews.root(),
Optional.absent(),
new TypeReference>() {});
}
@Override public QueryRequest forCustomer(String customerId) {
return requestFactory.createQueryRequest(
endpoints.reviews.queryByCustomerId(customerId),
Optional.absent(),
new TypeReference>() {});
}
@Override public QueryRequest forCustomerAndProduct(String customerId, String productId) {
return requestFactory.createQueryRequest(
endpoints.reviews.queryByCustomerIdProductId(customerId, productId),
Optional.absent(),
new TypeReference>() {});
}
@Override public QueryRequest forProduct(String productId) {
return requestFactory.createQueryRequest(
endpoints.reviews.queryByProductId(productId),
Optional.absent(),
new TypeReference>() {});
}
@Override public CommandRequest createReview(
String productId, String customerId, String authorName, String title, String text, Double score) {
return createCommandRequest(
endpoints.reviews.root(),
new ReviewCommands.CreateReview(productId, customerId, authorName, title, text, score));
}
@Override public CommandRequest updateReview(VersionedId reviewId, ReviewUpdate update) {
return createCommandRequest(
endpoints.reviews.byId(reviewId.getId()),
new UpdateCommand(reviewId.getVersion(), update));
}
/** Helper to save some repetitive code in this class. */
private CommandRequest createCommandRequest(String url, Command command) {
return requestFactory.createCommandRequest(url, command, new TypeReference() {});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy