File tree Expand file tree Collapse file tree
src/main/kotlin/com/coded/spring/ordering Expand file tree Collapse file tree Original file line number Diff line number Diff line change 7272 <dependency >
7373 <groupId >org.postgresql</groupId >
7474 <artifactId >postgresql</artifactId >
75- <scope >compile</scope >
7675 </dependency >
7776 <dependency >
7877 <groupId >com.hazelcast</groupId >
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 >
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 >
Original file line number Diff line number Diff line change @@ -15,12 +15,25 @@ import org.springframework.web.bind.annotation.RestController
1515class 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" )
Original file line number Diff line number Diff line change 11package com.coded.spring.ordering.menu
22
33import jakarta.inject.Named
4+ import org.springframework.beans.factory.annotation.Value
5+ import java.math.BigDecimal
6+ import java.math.RoundingMode
47
58@Named
69class 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 }
You can’t perform that action at this time.
0 commit comments