package restx.stats.central;

import restx.annotations.POST;
import restx.annotations.RestxResource;
import restx.factory.Component;
import restx.jongo.JongoCollection;
import restx.security.PermitAll;
import restx.stats.RestxStats;

import javax.inject.Named;

/**
 * Date: 9/5/14
 * Time: 09:50
 */
@RestxResource
@Component
public class StatsResource {
    private final JongoCollection statsCollection;

    public StatsResource(@Named("stats") JongoCollection statsCollection) {
        this.statsCollection = statsCollection;
    }

    @PermitAll
    @POST("/v1/stats")
    public void addStats(RestxStats stats) {
        statsCollection.get().save(stats);
    }
}

@@ -23,16 +23,130 @@
 ntral;%0A%0A
+import com.google.common.base.Optional;%0Aimport com.google.common.collect.Iterables;%0Aimport restx.annotations.GET;%0A
 import r
@@ -777,11 +777,373 @@
 );%0A    %7D
+%0A%0A    @PermitAll%0A    @GET(%22/v1/stats/app/:appNameHash%22)%0A    public Optional%3CRestxStats%3E findStats(String appNameHash) %7B%0A        return Optional.fromNullable(Iterables.getFirst(%0A                statsCollection.get().find(%22%7BappNameHash: #%7D%22, appNameHash)%0A                        .sort(%22%7Btimestamp: -1%7D%22).limit(1).as(RestxStats.class),%0A                null));%0A    %7D
 %0A%7D%0A

add route to get current stats for an app hash