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
121 changes: 82 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,68 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.coded.spring</groupId>
<artifactId>Ordering</artifactId>

<groupId>com.coded.spring.ordering</groupId>
<artifactId>food-ordering</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Kotlin.SpringbootV2</name>
<description>Kotlin.SpringbootV2</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<name>Online Food Ordering System</name>
<description>My first project</description>

<properties>
<java.version>21</java.version>
<kotlin.version>1.9.25</kotlin.version>
<java.version>23</java.version>
<kotlin.version>2.1.20</kotlin.version>
</properties>

<dependencies>
<!-- Spring Boot Starter Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Jackson Kotlin Module -->
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-kotlin</artifactId>
</dependency>

<!-- Kotlin Reflection -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- Kotlin Standard Library -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>${kotlin.version}</version>
</dependency>

<!-- Spring Boot Starter Data JPA -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- H2 Database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<version>2.1.214</version> <!-- Added missing version -->
</dependency>

<!-- Jakarta Inject -->
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>

<!-- Spring Boot Starter Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Kotlin Test JUnit5 -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<scope>test</scope>
</dependency>

<!-- Kotlin Test -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -71,21 +112,23 @@
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/HomeController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coded.spring.ordering
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class HomeController {

@GetMapping("/")
fun welcome(): String {
return "We don't want to keep you hungry, order now!"
}
}
12 changes: 12 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/items/Item.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.coded.spring.ordering.items

import jakarta.persistence.*

@Entity
@Table(name = "items")
data class Item(
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,
var name: String,
var quantity: Int
)
20 changes: 20 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/items/ItemsController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.coded.spring.ordering.items

import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/items")
class ItemsController(private val itemsRepo: ItemsRepo) {

@PostMapping
fun addItem(@RequestBody request: AddItemRequest) =
itemsRepo.save(Item(name = request.name, quantity = request.quantity))

@GetMapping
fun getAllItems() = itemsRepo.findAll()
}

data class AddItemRequest(
val name: String,
val quantity: Int
)
7 changes: 7 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/items/ItemsRepo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.coded.spring.ordering.items

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface ItemsRepo : JpaRepository<Item, Long>
19 changes: 19 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/orders/Order.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.coded.spring.ordering.orders
import jakarta.persistence.*

@Entity
@Table(name = "orders")
data class Order(

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
var id: Long? = null,

var userId: Long,
var restaurant: String,
var items: String,
var createdAt: Long = System.currentTimeMillis()

) {
constructor() : this(id = null, userId = 0L, restaurant = "", items = "", createdAt = 0L)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.coded.spring.ordering.orders
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/orders")
class OrdersController(
private val ordersRepo: OrdersRepo
) {

@PostMapping
fun orderItems(@RequestBody request: OrderItemsRequest): Order {
return ordersRepo.save(
Order(
userId = request.user,
restaurant = request.restaurant,
items = request.items
)
)
}

@GetMapping
fun getAllOrders(): List<Order> =
ordersRepo.findAllByOrderByCreatedAtAsc()
}

data class OrderItemsRequest(
val user: Long,
val restaurant: String,
val items: String
)
18 changes: 18 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/orders/OrdersRepo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//package com.coded.spring.ordering.orders
//
//import org.springframework.data.jpa.repository.JpaRepository
//import org.springframework.stereotype.Repository
//
//@Repository
// interface OrdersRepo : JpaRepository<Order, Long> {
// fun findAllByOrderByCreatedAtAsc(): List<Order>
// }
package com.coded.spring.ordering.orders

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface OrdersRepo : JpaRepository<Order, Long> {
fun findAllByOrderByCreatedAtAsc(): List<Order>
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/users/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.coded.spring.ordering.users

import jakarta.persistence.*

@Entity
@Table(name = "users")
data class User(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long = 0,

val name: String = ""
) {
constructor() : this(0, "")
}
19 changes: 19 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/users/UsersController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.coded.spring.ordering.users

import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/users")
class UsersController(private val usersRepo: UsersRepo) {

@PostMapping
fun createUser(@RequestBody request: CreateUserRequest) =
usersRepo.save(User(name = request.name))

@GetMapping
fun getAllUsers() = usersRepo.findAll()
}

data class CreateUserRequest(
val name: String,
)
7 changes: 7 additions & 0 deletions src/main/kotlin/com/coded/spring/ordering/users/UsersRepo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.coded.spring.ordering.users

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository

@Repository
interface UsersRepo : JpaRepository<User, Long>
8 changes: 7 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
spring.application.name=Kotlin.SpringbootV2
spring.datasource.url=jdbc:postgresql://localhost:5432/food_ordering
spring.datasource.username=postgres
spring.datasource.password=55866653
spring.datasource.driver-class-name=org.postgresql.Driver

spring.jpa.hibernate.ddl-auto=create
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect