Skip to content

Commit f510bc4

Browse files
committed
feat: order flow
1 parent 52fb233 commit f510bc4

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

src/main/kotlin/com/example/route/FoodRoute.kt

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.example.route
22

3-
import com.example.fake.foodDtos
43
import com.example.service.FoodService.Companion.foodService
54
import com.example.util.Constants.GENERIC_ERROR
6-
import com.example.util.Constants.INVALID_FOOD_ID
75
import com.example.util.Constants.INVALID_SEARCH_QUERY
86
import com.example.util.ext.getValueFromParameters
97
import io.ktor.http.*
@@ -63,28 +61,5 @@ fun Application.foodRoute() {
6361
}
6462
)
6563
}
66-
67-
get("/fake/foods") {
68-
val type = call.request.queryParameters["type"]?.lowercase()?.replaceFirstChar { it.uppercase() } ?: "all"
69-
val limit = call.request.queryParameters["limit"]?.toIntOrNull() ?: 10
70-
require(limit in 0..100) {
71-
call.respondText(
72-
text = "Limit must be between 0 and 100",
73-
status = HttpStatusCode.BadRequest
74-
)
75-
return@get
76-
}
77-
val foods = if (type == "all") {
78-
foodDtos.shuffled().take(limit)
79-
} else {
80-
foodDtos.filter { it.category == type }.shuffled().take(limit)
81-
}
82-
call.respond(foods)
83-
}
84-
85-
get("fake/foods/stock") {
86-
val stock = foodDtos.groupBy { it.category }.mapValues { it.value.size }
87-
call.respond(stock)
88-
}
8964
}
9065
}

src/main/kotlin/com/example/route/OrderRoute.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ fun Application.orderRoute() {
3838
)
3939
}
4040

41+
get("/orders/{userId}/order/flow") {
42+
val userId = call.getValueFromParameters("userId", UUID::fromString)
43+
orderService.getActiveOrderFlow(userId).fold(
44+
onSuccess = { flow -> call.respond(flow) },
45+
onFailure = { call.respond(HttpStatusCode.NotFound, it.message ?: "No active order found") }
46+
)
47+
}
48+
4149
get("/orders/{userId}/complete") {
4250
val userId = call.getValueFromParameters("userId", UUID::fromString)
4351
orderService.completeCurrentOrder(userId).fold(

src/main/kotlin/com/example/route/UserRoute.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.example.dto.UserRegisterDto
55
import com.example.dto.UserUpdateLocationDto
66
import com.example.service.UserService.Companion.userService
77
import com.example.util.Constants.GENERIC_ERROR
8-
import com.example.util.Constants.INVALID_USER_ID
98
import com.example.util.ext.getValueFromParameters
109
import io.ktor.http.*
1110
import io.ktor.server.application.*

0 commit comments

Comments
 (0)