From 263ccd6b0560d54b9d401ea52535cbd6143b5c8b Mon Sep 17 00:00:00 2001 From: blaz-cerpnjak Date: Tue, 19 Mar 2024 19:05:45 +0100 Subject: [PATCH] Add swagger and logging --- RestaurantManagementAPI/build.gradle | 2 ++ .../kotlin/com/blazc/controller/ProductController.kt | 11 +++++++++-- .../com/blazc/controller/RestaurantController.kt | 7 +++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/RestaurantManagementAPI/build.gradle b/RestaurantManagementAPI/build.gradle index 7cd8abf..02d7e81 100644 --- a/RestaurantManagementAPI/build.gradle +++ b/RestaurantManagementAPI/build.gradle @@ -18,6 +18,8 @@ dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' implementation 'io.quarkus:quarkus-arc' testImplementation 'io.quarkus:quarkus-junit5' + implementation 'io.quarkus:quarkus-smallrye-openapi' + implementation 'org.jboss.logging:jboss-logging' } group 'com.blazc' diff --git a/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt b/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt index db85907..e07f6b3 100644 --- a/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt +++ b/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/ProductController.kt @@ -7,10 +7,15 @@ import jakarta.inject.Inject import jakarta.ws.rs.* import jakarta.ws.rs.core.MediaType import org.bson.types.ObjectId +import org.jboss.logging.Logger @Path("/product") class ProductController { + companion object { + val LOG: Logger = Logger.getLogger(ProductController::class.java) + } + @Inject lateinit var productRepository: ProductRepository @@ -25,11 +30,12 @@ class ProductController { @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) fun getProductById(@PathParam("id") id: String): Uni { - lateinit var objectId: ObjectId + val objectId: ObjectId try { objectId = ObjectId(id) } catch (e: Exception) { + LOG.error("Error parsing id", e) return Uni.createFrom().failure(e) } @@ -61,11 +67,12 @@ class ProductController { @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) fun deleteProduct(@PathParam("id") id: String): Uni { - lateinit var objectId: ObjectId + val objectId: ObjectId try { objectId = ObjectId(id) } catch (e: Exception) { + LOG.error("Error parsing id", e) return Uni.createFrom().failure(e) } diff --git a/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/RestaurantController.kt b/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/RestaurantController.kt index cc9858a..775e0ea 100644 --- a/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/RestaurantController.kt +++ b/RestaurantManagementAPI/src/main/kotlin/com/blazc/controller/RestaurantController.kt @@ -7,10 +7,15 @@ import jakarta.inject.Inject import jakarta.ws.rs.* import jakarta.ws.rs.core.MediaType import org.bson.types.ObjectId +import org.jboss.logging.Logger @Path("/restaurant") class RestaurantController { + companion object { + val LOG: Logger = Logger.getLogger(RestaurantController::class.java) + } + @Inject lateinit var restaurantRepository: RestaurantRepository @@ -30,6 +35,7 @@ class RestaurantController { try { objectId = ObjectId(id) } catch (e: Exception) { + LOG.error("Error parsing id", e) return Uni.createFrom().failure(e) } @@ -57,6 +63,7 @@ class RestaurantController { try { objectId = ObjectId(id) } catch (e: Exception) { + LOG.error("Error parsing id", e) return Uni.createFrom().failure(e) }