Get the ratings of a dimension

Property definitions

nitc :: api_feedback $ MEntity :: ratings_by_dimension
	# Get the ratings of a `dimension`
	fun ratings_by_dimension(config: NitwebConfig, dimension: String, user: nullable String): JsonObject do
		var match = (new MongoMatch).eq("mentity", full_name).eq("dimension", dimension)
		var pipeline = new MongoPipeline
		pipeline.match(match)
		pipeline.group((new MongoGroup("mean_group")).avg("mean", "$rating"))

		var res = config.stars.collection.aggregate(pipeline)
		var obj = new JsonObject
		obj["mean"] = if res.is_empty then 0.0 else res.first["mean"]
		obj["ratings"] = new JsonArray.from(config.stars.find_all(match))

		if user != null then
			match["user"] = user
			obj["user"] = config.stars.find(match)
		end
		return obj
	end
src/doc/api/api_feedback.nit:216,2--233,4