nitweb: add catalog sidebar on package views
[nit.git] / src / web / api_catalog.nit
index 9bca8be..d22289b 100644 (file)
@@ -14,7 +14,7 @@
 
 module api_catalog
 
-import web_base
+import api_model
 import catalog
 
 redef class NitwebConfig
@@ -274,6 +274,20 @@ class APICatalogContributing
        end
 end
 
+redef class APIEntity
+       redef fun get(req, res) do
+               var mentity = mentity_from_uri(req, res)
+               if mentity == null then return
+
+               # Special case for packages (catalog view)
+               if mentity isa MPackage then
+                       res.raw_json mentity.to_full_catalog_json(plain=true, config.catalog)
+               else
+                       res.raw_json mentity.to_full_json
+               end
+       end
+end
+
 redef class Catalog
 
        # Build the catalog from `mpackages`