From dfd9b0baec8a6f5c9314f92a75b6602c232d8ab4 Mon Sep 17 00:00:00 2001 From: Quentin Aubert Date: Wed, 27 Sep 2023 12:14:29 +0200 Subject: [PATCH] Add new routes for admin-api --- .../app/controllers/AdminApiController.scala | 46 ++++++++++++++++++- daikoku/conf/routes | 14 ++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/daikoku/app/controllers/AdminApiController.scala b/daikoku/app/controllers/AdminApiController.scala index 593d50531..23e8da21d 100644 --- a/daikoku/app/controllers/AdminApiController.scala +++ b/daikoku/app/controllers/AdminApiController.scala @@ -502,6 +502,42 @@ class TranslationsAdminApiController(daa: DaikokuApiAction, .leftMap(_.flatMap(_._2).map(_.message).mkString(", ")) } +class UsagePlansAdminApiController(daa: DaikokuApiAction, + env: Env, + cc: ControllerComponents) + extends AdminApiController[UsagePlan, UsagePlanId](daa, env, cc) { + override def entityClass = classOf[UsagePlan] + override def entityName: String = "usage-plan" + override def pathRoot: String = s"/admin-api/${entityName}s" + override def entityStore(tenant: Tenant, + ds: DataStore): Repo[UsagePlan, UsagePlanId] = + ds.usagePlanRepo.forTenant(tenant) + override def toJson(entity: UsagePlan): JsValue = entity.asJson + override def fromJson(entity: JsValue): Either[String, UsagePlan] = + UsagePlanFormat + .reads(entity) + .asEither + .leftMap(_.flatMap(_._2).map(_.message).mkString(", ")) +} + +class SubscriptionDemandsAdminApiController(daa: DaikokuApiAction, + env: Env, + cc: ControllerComponents) + extends AdminApiController[SubscriptionDemand, SubscriptionDemandId](daa, env, cc) { + override def entityClass = classOf[SubscriptionDemand] + override def entityName: String = "subscription-demand" + override def pathRoot: String = s"/admin-api/${entityName}s" + override def entityStore(tenant: Tenant, + ds: DataStore): Repo[SubscriptionDemand, SubscriptionDemandId] = + ds.subscriptionDemandRepo.forTenant(tenant) + override def toJson(entity: SubscriptionDemand): JsValue = entity.asJson + override def fromJson(entity: JsValue): Either[String, SubscriptionDemand] = + SubscriptionDemandFormat + .reads(entity) + .asEither + .leftMap(_.flatMap(_._2).map(_.message).mkString(", ")) +} + class AdminApiSwaggerController( env: Env, cc: ControllerComponents, @@ -518,7 +554,9 @@ class AdminApiSwaggerController( ctrl11: MessagesAdminApiController, ctrl12: IssuesAdminApiController, ctrl13: PostsAdminApiController, - ctrl14: TranslationsAdminApiController + ctrl14: TranslationsAdminApiController, + ctrl15: UsagePlansAdminApiController, + ctrl16: SubscriptionDemandsAdminApiController ) extends AbstractController(cc) { def schema[A, B <: ValueType]( @@ -541,7 +579,9 @@ class AdminApiSwaggerController( schema(ctrl11) ++ schema(ctrl12) ++ schema(ctrl13) ++ - schema(ctrl14) + schema(ctrl14) ++ + schema(ctrl15) ++ + schema(ctrl16) ++ def paths: JsValue = path(ctrl1) ++ @@ -558,6 +598,8 @@ class AdminApiSwaggerController( path(ctrl12) ++ path(ctrl13) ++ path(ctrl14) ++ + path(ctrl15) ++ + path(ctrl16) ++ ctrl1.pathForIntegrationApi() def swagger() = Action { diff --git a/daikoku/conf/routes b/daikoku/conf/routes index 01b701933..eae3daa7c 100644 --- a/daikoku/conf/routes +++ b/daikoku/conf/routes @@ -450,6 +450,20 @@ PUT /admin-api/translations/:id fr.maif.otoroshi.daikoku GET /admin-api/translations/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.findById(id) POST /admin-api/translations fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.createEntity() GET /admin-api/translations fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.findAll() + +DELETE /admin-api/usage-plans/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.deleteEntity(id) +PATCH /admin-api/usage-plans/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.patchEntity(id) +PUT /admin-api/usage-plans/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.updateEntity(id) +GET /admin-api/usage-plans/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.findById(id) +POST /admin-api/usage-plans fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.createEntity() +GET /admin-api/usage-plans fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.findAll() + +DELETE /admin-api/subscription-demands/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.deleteEntity(id) +PATCH /admin-api/subscription-demands/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.patchEntity(id) +PUT /admin-api/subscription-demands/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.updateEntity(id) +GET /admin-api/subscription-demands/:id fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.findById(id) +POST /admin-api/subscription-demands fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.createEntity() +GET /admin-api/subscription-demands fr.maif.otoroshi.daikoku.ctrls.TranslationsAdminApiController.findAll() ### # summary: get apikey from integration token # tags: