Skip to content

Commit 62e10c9

Browse files
committed
Online Ordering - Configuration Task is completed
1 parent a3320eb commit 62e10c9

3 files changed

Lines changed: 37 additions & 14 deletions

File tree

pom.xml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
<dependency>
7373
<groupId>org.postgresql</groupId>
7474
<artifactId>postgresql</artifactId>
75-
<scope>compile</scope>
7675
</dependency>
7776
<dependency>
7877
<groupId>com.hazelcast</groupId>
@@ -84,11 +83,11 @@
8483
<artifactId>spring-boot-starter-test</artifactId>
8584
<scope>test</scope>
8685
</dependency>
87-
<dependency>
88-
<groupId>com.h2database</groupId>
89-
<artifactId>h2</artifactId>
90-
<scope>test</scope>
91-
</dependency>
86+
<!-- <dependency>-->
87+
<!-- <groupId>com.h2database</groupId>-->
88+
<!-- <artifactId>h2</artifactId>-->
89+
<!-- <scope>test</scope>-->
90+
<!-- </dependency>-->
9291
<dependency>
9392
<groupId>org.jetbrains.kotlin</groupId>
9493
<artifactId>kotlin-test-junit5</artifactId>
@@ -100,11 +99,11 @@
10099
<artifactId>spring-boot-starter-data-jpa</artifactId>
101100
</dependency>
102101

103-
<dependency>
104-
<groupId>com.h2database</groupId>
105-
<artifactId>h2</artifactId>
106-
<scope>runtime</scope>
107-
</dependency>
102+
<!-- <dependency>-->
103+
<!-- <groupId>com.h2database</groupId>-->
104+
<!-- <artifactId>h2</artifactId>-->
105+
<!-- <scope>runtime</scope>-->
106+
<!-- </dependency>-->
108107

109108
<dependency>
110109
<groupId>jakarta.inject</groupId>

src/main/kotlin/com/coded/spring/ordering/HelloWorldController.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ import org.springframework.web.bind.annotation.RestController
1515
class HelloWorldController(
1616
val usersRepository: UsersRepository,
1717
val orderRepository: OrderRepository,
18+
19+
// welcome endpoint
1820
@Value("\${server-welcome-message}")
19-
val welcomeMessage: String
21+
val welcomeMessage: String,
22+
//the feature
23+
@Value("\${feature.festive.enabled:false}")
24+
val festiveStatus: Boolean,
25+
26+
@Value("\${festive-welcome-message: Eidkom Mubarak}")
27+
private val festiveWelcomeMessage: String
2028
){
2129

2230
@GetMapping("/hello")
23-
fun helloWorld() = "$welcomeMessage Barrak"
31+
32+
fun helloWorld() = if(festiveStatus){
33+
festiveWelcomeMessage
34+
}else {
35+
"$welcomeMessage Barrak"
36+
}
2437

2538

2639
@GetMapping("/cart")

src/main/kotlin/com/coded/spring/ordering/menu/MenuService.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
package com.coded.spring.ordering.menu
22

33
import jakarta.inject.Named
4+
import org.springframework.beans.factory.annotation.Value
5+
import java.math.BigDecimal
6+
import java.math.RoundingMode
47

58
@Named
69
class MenuService(
710
private val menuRepository: MenuRepository,
11+
12+
@Value("\${feature.festive.enabled:false}")
13+
val festiveStatus: Boolean,
814
) {
915

1016
fun listMenu(): List<MenuEntity> = menuRepository.findAll().map {
1117
MenuEntity(
1218
id = it.id,
1319
name = it.name,
14-
price = it.price,
20+
price = if(festiveStatus) {
21+
// discount the price by 20%
22+
it.price.multiply(BigDecimal("0.8"))
23+
} else{
24+
it.price
25+
},
1526
description = it.description
1627
)
1728
}

0 commit comments

Comments
 (0)