All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.internal.ReviewServiceImpl Maven / Gradle / Ivy

There is a newer version: 0.72.1
Show newest version
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.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 {
    public ReviewServiceImpl(RequestFactory requestFactory, ProjectEndpoints endpoints) {
        super(requestFactory, endpoints, new TypeReference() {}, new TypeReference>() { });
    }

    @Override public FetchRequest byId(String id) {
        return requestFactory.createFetchRequest(
                endpoints.reviews.byId(id),
                Optional.absent(),
                new TypeReference() {});
    }

    @Deprecated
    @Override public QueryRequest all() {
        return query();
    }

    @Override public QueryRequest query() {
        return queryImpl(endpoints.reviews.root());
    }

    @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));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy