Skip to content

Commit

Permalink
Merge pull request #28 from piashcse/ktor-3.0.0
Browse files Browse the repository at this point in the history
- Update ktor 3.0.0
  • Loading branch information
piashcse authored Oct 26, 2024
2 parents a554566 + df5a483 commit 4d7683a
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 71 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
ktor-version = "2.3.12"
ktor-version = "3.0.0"
kotlin-version = "2.0.21"
logback-version = "1.5.11"
exposed-version = "0.54.0"
Expand All @@ -11,7 +11,7 @@ kotlinx-datetime-version = "0.6.1"
commons-email-version ="1.5"
valiktor-core-version = "0.12.0"
commons-io-version = "2.17.0"
ktor-swagger-ui-version = "3.6.0"
ktor-swagger-ui-version = "4.0.0"
swagger-parser-version = "2.1.22"
shadow-version = "8.3.3"
koin = "4.0.0"
Expand Down
32 changes: 13 additions & 19 deletions src/main/kotlin/com/piashcse/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,17 @@ import io.ktor.server.engine.*
import io.ktor.server.netty.*

fun main() {
val configName = "application.conf"
val appEngineEnv = applicationEngineEnvironment {
config = HoconApplicationConfig(ConfigFactory.load(configName))
module {
configureDataBase()
configureBasic()
configureKoin()
configureRequestValidation()
configureAuth()
configureSwagger()
configureStatusPage()
configureRoute()
}
connector {
host = config.property("ktor.deployment.host").getString()
port = config.property("ktor.deployment.port").getString().toInt()
}
}
embeddedServer(Netty, appEngineEnv).start(wait = true)
val config = HoconApplicationConfig(ConfigFactory.load("application.conf"))
val port = config.property("ktor.deployment.port").getString().toInt()
val host = config.property("ktor.deployment.host").getString()
embeddedServer(Netty, port = port, host = host) {
configureDataBase()
configureBasic()
configureKoin()
configureRequestValidation()
configureAuth()
configureSwagger()
configureStatusPage()
configureRoute()
}.start(wait = true)
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/piashcse/plugins/ConfigureBasic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.piashcse.plugins
import io.ktor.serialization.gson.*
import io.ktor.server.application.*
import io.ktor.server.plugins.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.calllogging.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.request.*
import org.slf4j.event.Level
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/piashcse/route/BrandRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/com/piashcse/route/CartRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand All @@ -31,7 +30,7 @@ fun Route.cartRoute(cartController: CartController) {
call.respond(
ApiResponse.success(
cartController.addToCart(
getCurrentUser().userId,
call.getCurrentUser().userId,
requestBody.productId,
requestBody.quantity
), HttpStatusCode.OK
Expand All @@ -58,7 +57,7 @@ fun Route.cartRoute(cartController: CartController) {
call.respond(
ApiResponse.success(
cartController.getCartItems(
getCurrentUser().userId,
call.getCurrentUser().userId,
limit.toInt(),
offset.toLong()
), HttpStatusCode.OK
Expand All @@ -84,7 +83,7 @@ fun Route.cartRoute(cartController: CartController) {
val (productId, quantity) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
cartController.updateCartQuantity(getCurrentUser().userId, productId, quantity.toInt()),
cartController.updateCartQuantity(call.getCurrentUser().userId, productId, quantity.toInt()),
HttpStatusCode.OK
)
)
Expand All @@ -105,7 +104,7 @@ fun Route.cartRoute(cartController: CartController) {
val (productId) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
cartController.deleteCartItem(getCurrentUser().userId, productId),
cartController.deleteCartItem(call.getCurrentUser().userId, productId),
HttpStatusCode.OK
)
)
Expand All @@ -116,7 +115,7 @@ fun Route.cartRoute(cartController: CartController) {
}) {
call.respond(
ApiResponse.success(
cartController.deleteAllItemsOfCart(getCurrentUser().userId), HttpStatusCode.OK
cartController.deleteAllItemsOfCart(call.getCurrentUser().userId), HttpStatusCode.OK
)
)
}
Expand Down
13 changes: 6 additions & 7 deletions src/main/kotlin/com/piashcse/route/OrderRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand All @@ -31,7 +30,7 @@ fun Route.orderRoute(orderController: OrderController) {
val requestBody = call.receive<AddOrder>()
call.respond(
ApiResponse.success(
orderController.addOrder(getCurrentUser().userId, requestBody), HttpStatusCode.OK
orderController.addOrder(call.getCurrentUser().userId, requestBody), HttpStatusCode.OK
)
)
}
Expand All @@ -55,7 +54,7 @@ fun Route.orderRoute(orderController: OrderController) {
call.respond(
ApiResponse.success(
orderController.getOrders(
getCurrentUser().userId, limit.toInt(), offset.toLong()
call.getCurrentUser().userId, limit.toInt(), offset.toLong()
), HttpStatusCode.OK
)
)
Expand All @@ -76,7 +75,7 @@ fun Route.orderRoute(orderController: OrderController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
orderController.updateOrder(getCurrentUser().userId, id, OrderStatus.CANCELED),
orderController.updateOrder(call.getCurrentUser().userId, id, OrderStatus.CANCELED),
HttpStatusCode.OK
)
)
Expand All @@ -97,7 +96,7 @@ fun Route.orderRoute(orderController: OrderController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
orderController.updateOrder(getCurrentUser().userId, id, OrderStatus.RECEIVED),
orderController.updateOrder(call.getCurrentUser().userId, id, OrderStatus.RECEIVED),
HttpStatusCode.OK
)
)
Expand All @@ -120,7 +119,7 @@ fun Route.orderRoute(orderController: OrderController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
orderController.updateOrder(getCurrentUser().userId, id, OrderStatus.CANCELED),
orderController.updateOrder(call.getCurrentUser().userId, id, OrderStatus.CANCELED),
HttpStatusCode.OK
)
)
Expand All @@ -141,7 +140,7 @@ fun Route.orderRoute(orderController: OrderController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
orderController.updateOrder(getCurrentUser().userId, id, OrderStatus.DELIVERED),
orderController.updateOrder(call.getCurrentUser().userId, id, OrderStatus.DELIVERED),
HttpStatusCode.OK
)
)
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/piashcse/route/PaymentRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.piashcse.utils.extension.apiResponse
import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/piashcse/route/ProductCategoryRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/com/piashcse/route/ProductRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down Expand Up @@ -130,7 +129,7 @@ fun Route.productRoute(productController: ProductController) {
)
call.respond(
ApiResponse.success(
productController.getProductById(getCurrentUser().userId, params), HttpStatusCode.OK
productController.getProductById(call.getCurrentUser().userId, params), HttpStatusCode.OK
)
)
}
Expand All @@ -144,7 +143,7 @@ fun Route.productRoute(productController: ProductController) {
val requestBody = call.receive<AddProduct>()
call.respond(
ApiResponse.success(
productController.addProduct(getCurrentUser().userId, requestBody), HttpStatusCode.OK
productController.addProduct(call.getCurrentUser().userId, requestBody), HttpStatusCode.OK
)
)
}
Expand Down Expand Up @@ -206,7 +205,7 @@ fun Route.productRoute(productController: ProductController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
productController.updateProduct(getCurrentUser().userId, id, params), HttpStatusCode.OK
productController.updateProduct(call.getCurrentUser().userId, id, params), HttpStatusCode.OK
)
)
}
Expand All @@ -224,7 +223,7 @@ fun Route.productRoute(productController: ProductController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
productController.deleteProduct(getCurrentUser().userId, id), HttpStatusCode.OK
productController.deleteProduct(call.getCurrentUser().userId, id), HttpStatusCode.OK
)
)
}
Expand Down Expand Up @@ -275,7 +274,7 @@ fun Route.productRoute(productController: ProductController) {
}
val fileNameInServer = imageId.toString().plus(fileLocation.fileExtension())
productController.uploadProductImage(
getCurrentUser().userId,
call.getCurrentUser().userId,
id,
fileNameInServer,
).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/piashcse/route/ReviewRatingRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down Expand Up @@ -59,7 +58,7 @@ fun Route.reviewRatingRoute(reviewRatingController: ReviewRatingController) {
val requestBody = call.receive<AddReviewRating>()
call.respond(
ApiResponse.success(
reviewRatingController.addReviewRating(getCurrentUser().userId, requestBody), HttpStatusCode.OK
reviewRatingController.addReviewRating(call.getCurrentUser().userId, requestBody), HttpStatusCode.OK
)
)
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/com/piashcse/route/ShippingRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand All @@ -31,7 +30,7 @@ fun Route.shippingRoute(shippingController: ShippingController) {
val requestBody = call.receive<AddShipping>()
call.respond(
ApiResponse.success(
shippingController.addShipping(getCurrentUser().userId, requestBody), HttpStatusCode.OK
shippingController.addShipping(call.getCurrentUser().userId, requestBody), HttpStatusCode.OK
)
)
}
Expand All @@ -51,7 +50,7 @@ fun Route.shippingRoute(shippingController: ShippingController) {
val (orderId) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
shippingController.getShipping(getCurrentUser().userId, orderId), HttpStatusCode.OK
shippingController.getShipping(call.getCurrentUser().userId, orderId), HttpStatusCode.OK
)
)
}
Expand Down Expand Up @@ -88,7 +87,7 @@ fun Route.shippingRoute(shippingController: ShippingController) {

call.respond(
ApiResponse.success(
shippingController.updateShipping(getCurrentUser().userId, params), HttpStatusCode.OK
shippingController.updateShipping(call.getCurrentUser().userId, params), HttpStatusCode.OK
)
)
}
Expand All @@ -108,7 +107,7 @@ fun Route.shippingRoute(shippingController: ShippingController) {
val (id) = requiredParams.map { call.parameters[it]!! }
call.respond(
ApiResponse.success(
shippingController.deleteShipping(getCurrentUser().userId, id), HttpStatusCode.OK
shippingController.deleteShipping(call.getCurrentUser().userId, id), HttpStatusCode.OK
)
)
}
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/com/piashcse/route/ShopCategoryRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/com/piashcse/route/ShopRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import io.github.smiley4.ktorswaggerui.dsl.routing.get
import io.github.smiley4.ktorswaggerui.dsl.routing.post
import io.github.smiley4.ktorswaggerui.dsl.routing.put
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
Expand All @@ -30,7 +29,7 @@ fun Route.shopRoute(shopController: ShopController) {
val requestBody = call.receive<AddShop>()
requestBody.validation()
shopController.addShop(
getCurrentUser().userId, requestBody.shopCategoryId, requestBody.shopName
call.getCurrentUser().userId, requestBody.shopCategoryId, requestBody.shopName
).let {
call.respond(ApiResponse.success(it, HttpStatusCode.OK))
}
Expand All @@ -54,7 +53,7 @@ fun Route.shopRoute(shopController: ShopController) {
}
val (limit, offset) = requiredParams.map { call.parameters[it]!! }
shopController.getShop(
getCurrentUser().userId, limit.toInt(), offset.toLong()
call.getCurrentUser().userId, limit.toInt(), offset.toLong()
).let {
call.respond(ApiResponse.success(it, HttpStatusCode.OK))
}
Expand All @@ -77,7 +76,7 @@ fun Route.shopRoute(shopController: ShopController) {
}
val (id, shopName) = requiredParams.map { call.parameters[it]!! }
shopController.updateShop(
getCurrentUser().userId, id, shopName
call.getCurrentUser().userId, id, shopName
).let {
call.respond(ApiResponse.success(it, HttpStatusCode.OK))
}
Expand All @@ -98,7 +97,7 @@ fun Route.shopRoute(shopController: ShopController) {
val (id) = requiredParams.map { call.parameters[it]!! }

shopController.deleteShop(
getCurrentUser().userId, id
call.getCurrentUser().userId, id
).let {
call.respond(ApiResponse.success(it, HttpStatusCode.OK))
}
Expand Down
Loading

0 comments on commit 4d7683a

Please sign in to comment.