From 4e80a3d9f20df45bfeab8991f0c170a51133d7b4 Mon Sep 17 00:00:00 2001 From: gowthaman Date: Mon, 27 May 2024 12:52:14 +0530 Subject: [PATCH] some changes --- src/main/kotlin/com/restapi/Main.kt | 1 + .../com/restapi/controllers/Entities.kt | 20 ++++++++++++++++++- src/main/resources/logback.xml | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/restapi/Main.kt b/src/main/kotlin/com/restapi/Main.kt index 659ce72..a406555 100644 --- a/src/main/kotlin/com/restapi/Main.kt +++ b/src/main/kotlin/com/restapi/Main.kt @@ -301,6 +301,7 @@ fun main(args: Array) { } } + get("/{entity}", Entities::getAll, Roles(adminRole, viewRole, appAdmin) ) post("/{entity}/next", Entities::getNextSeqNo, Roles(adminRole, viewRole, appAdmin)) get("/{entity}/{id}", Entities::view, Roles(adminRole, viewRole, appAdmin)) post("/{entity}/search", Entities::search, Roles(adminRole, viewRole, appAdmin)) diff --git a/src/main/kotlin/com/restapi/controllers/Entities.kt b/src/main/kotlin/com/restapi/controllers/Entities.kt index bc2dde9..db61824 100644 --- a/src/main/kotlin/com/restapi/controllers/Entities.kt +++ b/src/main/kotlin/com/restapi/controllers/Entities.kt @@ -94,6 +94,7 @@ object Entities { e.deletedOn = LocalDateTime.now() e.update() e.delete() + ctx.json(OK) } fun patch(ctx: Context) { @@ -135,6 +136,7 @@ object Entities { verifyKeys(sql.params) val entity = ctx.pathParam("entity") + val searchJsonMap = sql.params.map { e -> Pair(e.key, e.value.getValue()) }.toMap() val fl = database.find(DataModel::class.java) .setRawSql( RawSqlBuilder.parse( @@ -167,14 +169,30 @@ object Entities { .setParameter("from", sql.dateRange.first()) .setParameter("to", sql.dateRange.last().plusDays(1)) .setParameter("e", entity) - .setParameter("search", objectMapper.writeValueAsString(sql.params.map { e -> Pair(e.key, e.value.getValue()) }.toMap())) + .setParameter("search", objectMapper.writeValueAsString(searchJsonMap)) .findList() + logger.warn("Search jsonMap [$searchJsonMap] => ${fl.size} entries") + ctx.json(fl) } + fun getAll(ctx: Context) { + val entity = ctx.pathParam("entity").uppercase() + val pageNo = ctx.queryParam("pageNo")?.toInt() ?: 1 + val perPage = ctx.queryParam("perPage")?.toInt() ?: 100 + val cnt = database.find(DataModel::class.java) + .where() + .eq("entityName", entity.lowercase()) + .setFirstRow((pageNo - 1) * perPage) + .setMaxRows(perPage) + .findPagedList() + + ctx.json(cnt) + } + fun getNextSeqNo(ctx: Context) { val entity = ctx.pathParam("entity").uppercase() diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 8d7159d..a7138dc 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -21,14 +21,14 @@ - + - +