diff --git a/pom.xml b/pom.xml index 163ad53..5a4d4e8 100644 --- a/pom.xml +++ b/pom.xml @@ -31,6 +31,18 @@ 1.9.25 + + jakarta.inject + jakarta.inject-api + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + org.springframework.boot spring-boot-starter-web diff --git a/src/main/kotlin/com/coded/spring/ordering/OrdersController.kt b/src/main/kotlin/com/coded/spring/ordering/OrdersController.kt new file mode 100644 index 0000000..ba30574 --- /dev/null +++ b/src/main/kotlin/com/coded/spring/ordering/OrdersController.kt @@ -0,0 +1,30 @@ +package com.coded.spring.ordering + +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController + +@RestController +class OrdersController( + val ordersRepository: OrdersRepository +){ + + @GetMapping("/my-orders") + fun printOrders() : MutableList { + return ordersRepository.findAll() + } + + @PostMapping("/my-orders") + fun myOrders( + @RequestBody request: MyOrdersRequeset + ) = ordersRepository.save(Orders(name = request.name, + civilId = request.civilId, + items = request.items)) +} + +data class MyOrdersRequeset( + val name: String, + val civilId: String, + var items: List +) \ No newline at end of file diff --git a/src/main/kotlin/com/coded/spring/ordering/OrdersRepository.kt b/src/main/kotlin/com/coded/spring/ordering/OrdersRepository.kt new file mode 100644 index 0000000..eb2721d --- /dev/null +++ b/src/main/kotlin/com/coded/spring/ordering/OrdersRepository.kt @@ -0,0 +1,21 @@ +package com.coded.spring.ordering + +import jakarta.inject.Named +import jakarta.persistence.* +import org.springframework.data.jpa.repository.JpaRepository + +@Named +interface OrdersRepository : JpaRepository + +@Entity +@Table(name = "orders") +data class Orders( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var id: Long? = null, + var name: String, + var civilId: String, + var items: List +){ + constructor() : this(null, "","", items = listOf("","")) +} \ No newline at end of file