File tree Expand file tree Collapse file tree 8 files changed +48
-2
lines changed
src/main/kotlin/com/example Expand file tree Collapse file tree 8 files changed +48
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ data class FoodDto(
99 val id : Int ,
1010 val name : String ,
1111 val description : String ,
12+ val restaurant : String ,
1213 @Serializable(with = BigDecimalSerializer ::class ) val price : BigDecimal ,
1314 val rating : Double ,
1415 val orderCount : Int ,
Original file line number Diff line number Diff line change @@ -64,14 +64,16 @@ data class Food(
6464 val rating : Double ,
6565 val orderCount : Int ,
6666 val category : FoodCategory ,
67- val imageUrl : String
67+ val imageUrl : String ,
68+ val restaurant : String = " " ,
6869)
6970
7071fun Food.toFoodDto (): FoodDto {
7172 return FoodDto (
7273 id = this .id,
7374 name = this .name,
7475 description = this .description,
76+ restaurant = this .restaurant,
7577 price = this .price.toBigDecimal(),
7678 rating = this .rating,
7779 orderCount = this .orderCount,
@@ -1581,6 +1583,6 @@ val foodDtos = listOf(
15811583 FoodCategory .Pizza ,
15821584 getRandomImageUrl(FoodCategory .Pizza )
15831585 ),
1584- ).map {
1586+ ).map {
15851587 it.toFoodDto()
15861588}
Original file line number Diff line number Diff line change 1+ package com.example.fake
2+
3+ val FakeRestaurants = listOf (
4+ " McDonald's" ,
5+ " Burger King" ,
6+ " KFC" ,
7+ " Subway" ,
8+ " Pizza Hut" ,
9+ " Domino's Pizza" ,
10+ " Starbucks" ,
11+ " Dunkin' Donuts" ,
12+ " Tim Hortons" ,
13+ " Dairy Queen" ,
14+ " Papa John's" ,
15+ " Wendy's" ,
16+ " Taco Bell" ,
17+ " Chipotle Mexican Grill" ,
18+ " Panera Bread" ,
19+ " Sonic Drive-In" ,
20+ " Arby's" ,
21+ " Little Caesars" ,
22+ " Popeyes Louisiana Kitchen" ,
23+ " Chick-fil-A" ,
24+ " Jimmy John's" ,
25+ )
Original file line number Diff line number Diff line change @@ -67,5 +67,9 @@ fun Application.foodRoute() {
6767 val categories = FoodCategory .entries.map(FoodCategory ::name)
6868 call.respond(categories)
6969 }
70+
71+ get(" /foods/update" ) {
72+ foodService.updateRestaurant()
73+ }
7074 }
7175}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ interface FoodService {
99 suspend fun getAllFoods (): Result <List <FoodDto >>
1010 suspend fun getFoodsByCategory (type : String ): Result <List <FoodDto >>
1111 suspend fun registerFood (foodDto : FoodDto ): Result <Boolean >
12+ suspend fun updateRestaurant (): Result <Boolean >
1213 companion object {
1314 val foodService: FoodService by lazy { FoodServiceImpl () }
1415 }
Original file line number Diff line number Diff line change 11package com.example.service.impl
22
33import com.example.dto.FoodDto
4+ import com.example.fake.FakeRestaurants
45import com.example.service.DatabaseModule.dbQuery
56import com.example.service.FoodService
67import com.example.table.Foods
@@ -47,4 +48,14 @@ class FoodServiceImpl : FoodService {
4748 }
4849 true
4950 }
51+
52+ override suspend fun updateRestaurant (): Result <Boolean > = dbQuery {
53+ val allFoodIds = Foods .selectAll().map { it[Foods .id] }
54+ allFoodIds.forEach { foodId ->
55+ Foods .update({ Foods .id eq foodId }) {
56+ it[restaurant] = FakeRestaurants .random()
57+ }
58+ }
59+ true
60+ }
5061}
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ object Foods : Table() {
77 val id = integer(" id" ).autoIncrement()
88 val name = varchar(" name" , 128 )
99 val description = varchar(" description" , 256 )
10+ val restaurant = varchar(" restaurant" , 256 )
1011 val price = decimal(" price" , 10 , 2 )
1112 val rating = double(" rating" )
1213 val orderCount = integer(" orderCount" )
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ fun ResultRow.toFoodDto(): FoodDto = FoodDto(
1515 id = this [Foods .id],
1616 name = this [Foods .name],
1717 description = this [Foods .description],
18+ restaurant = this [Foods .restaurant],
1819 price = this [Foods .price],
1920 rating = this [Foods .rating],
2021 orderCount = this [Foods .orderCount],
You can’t perform that action at this time.
0 commit comments