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

travel.izi.api.model.entity.ReviewsResponse Maven / Gradle / Ivy

/*
 * Copyright (C) 2015 IZITEQ B.V.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package travel.izi.api.model.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.google.auto.value.AutoValue;

import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Response object for endpoint {@link travel.izi.api.service.ReviewService#reviews(String,
 * String, Long, Long)}.
 */
@SuppressWarnings("unused")
@AutoValue
public abstract class ReviewsResponse implements Serializable {

    @JsonCreator
    public static ReviewsResponse create(@JsonProperty("metadata") Estimation estimation,
            @JsonProperty("data") List reviews,
            @JsonProperty("paging") Paging paging) {
        return new AutoValue_ReviewsResponse(estimation, reviews, paging);
    }

    @JsonProperty("metadata")
    public abstract Estimation estimation();

    @Nullable
    @JsonProperty("data")
    public abstract List reviews();

    public abstract Paging paging();

    /**
     * The average of ratings/reviews. If the average is not calculated yet, the section will be
     * returned
     * where 'ratingAverage','ratingsCount', 'reviewsCount' fields will be 0 and 'date' will be
     * current time.
     */
    @AutoValue
    @JsonDeserialize(builder = AutoValue_ReviewsResponse_Estimation.Builder.class)
    public abstract static class Estimation implements Serializable {

        public static Builder builder() {
            return new AutoValue_ReviewsResponse_Estimation.Builder();
        }

        /**
         * UUID of the MtgObject (content).
         */
        @Nullable
        public abstract String uuid();

        /**
         * Average of all ratings [0..10] (across all languages), Museums ratings includes their
         * Collections ratings.
         */
        @Nullable
        public abstract Float ratingAverage();

        /**
         * Total number of ratings at average snapshot time (across all languages).
         */
        @Nullable
        public abstract Integer ratingsCount();

        /**
         * Total number of reviews at average snapshot time (across all languages).
         */
        @Nullable
        public abstract Integer reviewsCount();

        /**
         * UTC time when average was calculated. Format is according to ISO-8601
         * "YYYY-MM-DDThh:mm:ssZ".
         */
        @Nullable
        public abstract Date date();

        @AutoValue.Builder
        @JsonPOJOBuilder(withPrefix = "")
        public abstract static class Builder {
            public abstract Builder uuid(String uuid);
            public abstract Builder ratingAverage(Float ratingAverage);
            public abstract Builder ratingsCount(Integer ratingsCount);
            public abstract Builder reviewsCount(Integer reviewsCount);
            public abstract Builder date(Date date);

            public abstract Estimation build();
        }
    }

    /**
     * Pagination to navigate through results data using Unix timestamps.
     */
    @AutoValue
    public abstract static class Paging implements Serializable {

        @JsonCreator
        public static Paging create(@JsonProperty("limit") Integer limit,
                @JsonProperty("returned_count") Integer returnedCount,
                @JsonProperty("total_count") Integer totalCount,
                @JsonProperty("next") String next,
                @JsonProperty("previous") String previous) {
            return new AutoValue_ReviewsResponse_Paging(
                    limit, returnedCount, totalCount, next, previous);
        }

        /**
         * The number of individual records that are returned in each page.
         */
        public abstract Integer limit();

        /**
         * The number of returned records in section 'data'. Values: [0..limit].
         */
        public abstract Integer returnedCount();

        /**
         * The total number of review records for the content at request time
         * (all languages or for certain language passed as parameter).
         */
        public abstract Integer totalCount();

        /**
         * An endpoint request that will return the next page of data or null.
         */
        @Nullable
        public abstract String next();

        /**
         * An endpoint request that will return the previous page of data or null.
         */
        @Nullable
        public abstract String previous();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy