-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from piashcse/payment
- Implemented payment route
- Loading branch information
Showing
23 changed files
with
185 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/com/piashcse/controller/PaymentController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.piashcse.controller | ||
|
||
import com.piashcse.entities.Payment | ||
import com.piashcse.entities.PaymentEntity | ||
import com.piashcse.entities.PaymentTable | ||
import com.piashcse.entities.orders.OrderEntity | ||
import com.piashcse.entities.orders.OrderTable | ||
import com.piashcse.models.AddPayment | ||
import com.piashcse.repository.PaymentRepo | ||
import com.piashcse.utils.extension.notFoundException | ||
import com.piashcse.utils.extension.query | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
|
||
class PaymentController : PaymentRepo { | ||
override suspend fun addPayment(payment: AddPayment): Payment = query { | ||
val isOrderExist = OrderEntity.find { OrderTable.id eq payment.orderId }.toList().singleOrNull() | ||
isOrderExist?.let { | ||
PaymentEntity.new { | ||
orderId = EntityID(payment.orderId, PaymentTable) | ||
amount = payment.amount | ||
status = payment.status | ||
paymentMethod = payment.paymentMethod | ||
}.response() | ||
} ?: throw payment.orderId.notFoundException() | ||
|
||
} | ||
|
||
override suspend fun getPayment(paymentId: String): Payment = query { | ||
val isOrderExist = PaymentEntity.find { PaymentTable.id eq paymentId }.toList().firstOrNull() | ||
isOrderExist?.response() ?: throw paymentId.notFoundException() | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/kotlin/com/piashcse/controller/ProductCategoryController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/piashcse/controller/ProductSubCategoryController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tlin/com/piashcse/entities/orders/Cart.kt → ...main/kotlin/com/piashcse/entities/Cart.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.piashcse.entities | ||
|
||
import com.piashcse.entities.base.BaseIntEntity | ||
import com.piashcse.entities.base.BaseIntEntityClass | ||
import com.piashcse.entities.base.BaseIntIdTable | ||
import com.piashcse.entities.orders.OrderTable | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
|
||
object PaymentTable : BaseIntIdTable("payment") { | ||
val orderId = reference("order_id", OrderTable.id) | ||
val amount = long("amount") | ||
val status = varchar("status", 50) // e.g., "PENDING", "COMPLETED" | ||
val paymentMethod = varchar("payment_method", 50) // e.g., "CREDIT_CARD", "PAYPAL" | ||
} | ||
|
||
class PaymentEntity(id: EntityID<String>) : BaseIntEntity(id, PaymentTable) { | ||
companion object : BaseIntEntityClass<PaymentEntity>(PaymentTable) // Reference the Payments table | ||
var paymentId by PaymentTable.id | ||
var orderId by PaymentTable.orderId | ||
var amount by PaymentTable.amount | ||
var status by PaymentTable.status | ||
var paymentMethod by PaymentTable.paymentMethod | ||
fun response() = Payment( | ||
id = paymentId.value, | ||
orderId = orderId.value, | ||
amount = amount, | ||
status = status, | ||
paymentMethod = paymentMethod, | ||
) | ||
} | ||
|
||
data class Payment( | ||
val id: String, | ||
val orderId: String, | ||
val amount: Long, | ||
val status: String, | ||
val paymentMethod: String | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ities/product/category/ProductCategory.kt → ...shcse/entities/product/ProductCategory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/product/category/ProductSubCategory.kt → ...se/entities/product/ProductSubCategory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.piashcse.models | ||
|
||
import org.valiktor.functions.isGreaterThan | ||
import org.valiktor.functions.isNotEmpty | ||
import org.valiktor.functions.isNotNull | ||
import org.valiktor.validate | ||
|
||
data class AddPayment( | ||
val orderId: String, | ||
val amount: Long, | ||
val status: String, | ||
val paymentMethod: String | ||
){ | ||
fun validation(){ | ||
validate(this){ | ||
validate(AddPayment::orderId).isNotNull().isNotEmpty() | ||
validate(AddPayment::amount).isNotNull().isGreaterThan(0) | ||
validate(AddPayment::status).isNotNull().isNotEmpty() | ||
validate(AddPayment::paymentMethod).isNotNull().isNotEmpty() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.piashcse.repository | ||
|
||
import com.piashcse.entities.Payment | ||
import com.piashcse.models.AddPayment | ||
|
||
interface PaymentRepo { | ||
suspend fun addPayment(payment: AddPayment): Payment | ||
suspend fun getPayment(paymentId:String): Payment | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/piashcse/repository/ProductSubCategoryRepo.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.