1
0
mirror of https://github.com/sismics/docs.git synced 2025-12-24 23:22:56 +00:00

Tag stats (server)

This commit is contained in:
jendib
2013-08-04 14:19:37 +02:00
parent f5871e89e2
commit 97fa6b10f7
5 changed files with 143 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.sismics.docs.core.dao.jpa.TagDao;
import com.sismics.docs.core.dao.jpa.dto.TagStatDto;
import com.sismics.docs.core.model.jpa.Tag;
import com.sismics.rest.exception.ClientException;
import com.sismics.rest.exception.ForbiddenClientException;
@@ -59,6 +60,35 @@ public class TagResource extends BaseResource {
return Response.ok().entity(response).build();
}
/**
* Returns stats on tags.
*
* @return Response
* @throws JSONException
*/
@GET
@Path("/stats")
@Produces(MediaType.APPLICATION_JSON)
public Response stats() throws JSONException {
if (!authenticate()) {
throw new ForbiddenClientException();
}
TagDao tagDao = new TagDao();
List<TagStatDto> tagStatDtoList = tagDao.getStats(principal.getId());
JSONObject response = new JSONObject();
List<JSONObject> items = new ArrayList<JSONObject>();
for (TagStatDto tagStatDto : tagStatDtoList) {
JSONObject item = new JSONObject();
item.put("id", tagStatDto.getId());
item.put("name", tagStatDto.getName());
item.put("count", tagStatDto.getCount());
items.add(item);
}
response.put("stats", items);
return Response.ok().entity(response).build();
}
/**
* Creates a new tag.
*