File tree Expand file tree Collapse file tree 3 files changed +8
-26
lines changed
src/main/kotlin/com/example/route Expand file tree Collapse file tree 3 files changed +8
-26
lines changed Original file line number Diff line number Diff line change 11package com.example.route
22
3- import com.example.fake.foodDtos
43import com.example.service.FoodService.Companion.foodService
54import com.example.util.Constants.GENERIC_ERROR
6- import com.example.util.Constants.INVALID_FOOD_ID
75import com.example.util.Constants.INVALID_SEARCH_QUERY
86import com.example.util.ext.getValueFromParameters
97import 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}
Original file line number Diff line number Diff 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(
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ import com.example.dto.UserRegisterDto
55import com.example.dto.UserUpdateLocationDto
66import com.example.service.UserService.Companion.userService
77import com.example.util.Constants.GENERIC_ERROR
8- import com.example.util.Constants.INVALID_USER_ID
98import com.example.util.ext.getValueFromParameters
109import io.ktor.http.*
1110import io.ktor.server.application.*
You can’t perform that action at this time.
0 commit comments