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

io.sphere.internal.CommentServiceImpl 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.CommentService;
import io.sphere.client.shop.model.Comment;
import io.sphere.client.shop.model.CommentUpdate;
import io.sphere.internal.command.CommentCommands;
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 CommentServiceImpl extends ProjectScopedAPI implements CommentService {
    public CommentServiceImpl(RequestFactory requestFactory, ProjectEndpoints endpoints) {
        super(requestFactory, endpoints, new TypeReference() {}, new TypeReference>() { } );
    }

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

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

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

    @Override public QueryRequest forCustomer(String customerId) {
        return requestFactory.createQueryRequest(
                endpoints.comments.queryByCustomerId(customerId),
                Optional.absent(),
                new TypeReference>() {});
    }

    @Override public QueryRequest forProduct(String productId) {
        return requestFactory.createQueryRequest(
                endpoints.comments.queryByProductId(productId),
                Optional.absent(),
                new TypeReference>() {});
    }
    
    @Override public CommandRequest createComment(String productId, String customerId, String authorName, String title, String text) {
        return createCommandRequest(
                endpoints.comments.root(),
                new CommentCommands.CreateComment(productId, customerId, authorName, title, text));
    }

    @Override public CommandRequest updateComment(VersionedId commentId, CommentUpdate update) {
        return createCommandRequest(
                endpoints.comments.byId(commentId.getId()),
                new UpdateCommand(commentId.getVersion(), update));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy