Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
<kotlin.version>1.9.25</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/OrdersController.kt
Original file line number Diff line number Diff line change
@@ -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<Orders> {
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<String>
)
21 changes: 21 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/OrdersRepository.kt
Original file line number Diff line number Diff line change
@@ -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<Orders, Long>

@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<String>
){
constructor() : this(null, "","", items = listOf("",""))
}