Skip to content

Commit 9bdf911

Browse files
committed
chore: general
1 parent f510bc4 commit 9bdf911

File tree

4 files changed

+128
-2
lines changed

4 files changed

+128
-2
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ WORKDIR /app
55

66
COPY gradlew .
77
COPY gradle ./gradle
8+
COPY gradle.properties .
89

910
RUN chmod +x ./gradlew
1011

README.md

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,114 @@
1-
# food-delivery-backend
1+
# Food Delivery Backend API
2+
3+
Welcome to the Food Delivery Backend API documentation.
4+
5+
## Base URL
6+
7+
[https://espresso-food-delivery-backend-cc3e106e2d34.herokuapp.com/](https://espresso-food-delivery-backend-cc3e106e2d34.herokuapp.com/)
8+
9+
## DTOs
10+
11+
For information on the Data Transfer Objects (DTOs) used in the requests and responses, [check out the DTOs here](/src/main/kotlin/com/example/dto).
12+
13+
## User API Endpoints
14+
15+
### Register User
16+
- **POST** `/register`
17+
- Description: Registers a new user with the provided details.
18+
- Request Body: `UserRegisterDto` (Object) - Data Transfer Object containing user registration details.
19+
- Responses:
20+
- `201 Created` if registration is successful.
21+
- `400 Bad Request` with error message if registration fails.
22+
23+
### User Login
24+
- **POST** `/login`
25+
- Description: Authenticates a user and returns a user identifier upon successful login.
26+
- Request Body: `UserLoginDto` (Object) - Data Transfer Object containing user login credentials.
27+
- Responses:
28+
- `200 OK` with user identifier if login is successful.
29+
- `401 Unauthorized` with error message if login fails.
30+
31+
### Get User Profile
32+
- **GET** `/profile/{userId}`
33+
- Description: Retrieves the profile details of a specific user.
34+
- Path Parameters: `userId` (UUID) - The unique identifier of the user.
35+
- Responses:
36+
- `200 OK` with user profile details if found.
37+
- `404 Not Found` with error message if user profile is not found.
38+
39+
### Get User Profile Flow
40+
- **GET** `/profile/{userId}/flow`
41+
- Description: Retrieves a flow of profile details for a specific user. This is typically used for real-time updates.
42+
- Path Parameters: `userId` (UUID) - The unique identifier of the user.
43+
- Responses:
44+
- `200 OK` with a flow of user profile details if found.
45+
- `404 Not Found` with error message if user profile is not found.
46+
47+
### Update User Location
48+
- **POST** `/profile/{userId}/location`
49+
- Description: Updates the location details for a specific user's profile.
50+
- Path Parameters: `userId` (UUID) - The unique identifier of the user.
51+
- Request Body: `UserUpdateLocationDto` (Object) - Data Transfer Object containing new location details.
52+
- Responses:
53+
- `200 OK` if the location is successfully updated.
54+
- `404 Not Found` with error message if the user profile is not found or update fails.
55+
56+
## Order API Endpoints
57+
58+
### Add Item to Order
59+
- **POST** `/orders/{userId}/items`
60+
- Adds a food item to the user's order.
61+
- **Path**: `userId` (UUID as string)
62+
- **Body**: `FoodDto` (JSON)
63+
- **Response**: `200 OK` with order ID, `500 Internal Server Error` with error message.
64+
65+
### Update Order Item Quantity
66+
- **POST** `/orders/items/{itemId}`
67+
- Updates the quantity of an item in the order.
68+
- **Path**: `itemId` (Integer)
69+
- **Body**: Quantity (Integer)
70+
- **Response**: `200 OK` with item details, `500 Internal Server Error` with error message.
71+
72+
### Get Active Order
73+
- **GET** `/orders/{userId}`
74+
- Retrieves the user's active order.
75+
- **Path**: `userId` (UUID as string)
76+
- **Response**: `200 OK` with order details, `404 Not Found` with error message.
77+
78+
### Complete Order
79+
- **GET** `/orders/{userId}/complete`
80+
- Completes the user's current order.
81+
- **Path**: `userId` (UUID as string)
82+
- **Response**: `200 OK` with completion status, `500 Internal Server Error` with error message.
83+
84+
### Delete Current Order
85+
- **DELETE** `/orders/{userId}/current`
86+
- Deletes the user's current order.
87+
- **Path**: `userId` (UUID as string)
88+
- **Response**: `200 OK` with deletion status, `500 Internal Server Error` with error message.
89+
90+
### Delete Specific Order
91+
- **DELETE** `/orders/{userId}/{orderId}`
92+
- Deletes a specific order for the user.
93+
- **Path**: `userId` (UUID as string), `orderId` (Integer)
94+
- **Response**: `200 OK` with deletion status, `500 Internal Server Error` with error message.
95+
96+
## Food API Endpoints
97+
98+
### Get Food Details
99+
- **GET** `/foods/{foodId}`
100+
- Retrieves details for a specific food item.
101+
- **Path**: `foodId` (Integer)
102+
- **Response**: `200 OK` with food details, `404 Not Found` with error message.
103+
104+
### List All Foods or Search
105+
- **GET** `/foods`
106+
- Lists all foods or returns search results based on query.
107+
- **Query**: `search` (String, optional) - Search term for food items.
108+
- **Response**: `200 OK` with list of foods or search results, `404 Not Found` with error message.
109+
110+
### Get Foods by Category
111+
- **GET** `/foods/categories`
112+
- Retrieves foods filtered by category.
113+
- **Query**: `type` (String, optional) - Category type, defaults to "all".
114+
- **Response**: `200 OK` with foods by category, `404 Not Found` with error message.

src/main/kotlin/com/example/service/OrderService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ package com.example.service
33
import com.example.dto.FoodDto
44
import com.example.dto.GetActiveOrderDto
55
import com.example.dto.ItemDto
6+
import com.example.dto.OrderDto
67
import com.example.service.impl.OrderServiceImpl
8+
import kotlinx.coroutines.flow.Flow
79
import java.util.*
810

911
interface OrderService {
1012
suspend fun getActiveOrder(userId: UUID): Result<GetActiveOrderDto>
13+
suspend fun getActiveOrderFlow(userId: UUID): Result<Flow<GetActiveOrderDto>>
1114
suspend fun addFoodToOrder(userId: UUID, foodDto: FoodDto, quantity: Int): Result<Int>
1215
suspend fun updateItemInOrder(itemId: Int, quantity: Int): Result<Boolean>
1316
suspend fun deleteCurrentOrder(userId: UUID): Result<Boolean>

src/main/kotlin/com/example/service/impl/OrderServiceImpl.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import com.example.service.OrderService
66
import com.example.table.Foods
77
import com.example.table.Items
88
import com.example.table.Orders
9-
import com.example.util.ext.toFoodDto
109
import com.example.util.ext.toItemDto
1110
import com.example.util.ext.toOrderDto
11+
import kotlinx.coroutines.flow.*
1212
import org.jetbrains.exposed.sql.*
1313
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
1414
import java.util.*
@@ -23,6 +23,15 @@ class OrderServiceImpl : OrderService {
2323
GetActiveOrderDto(order.toOrderDto(), items)
2424
}
2525

26+
override suspend fun getActiveOrderFlow(userId: UUID): Result<Flow<GetActiveOrderDto>> = dbQuery {
27+
Orders.select {
28+
(Orders.userId eq userId) and (Orders.orderStatus eq OrderStatus.Started)
29+
}.map { order ->
30+
val items = Items.select { Items.orderId eq order[Orders.id] }.map { it.toItemDto() }
31+
GetActiveOrderDto(order.toOrderDto(), items)
32+
}.asFlow()
33+
}
34+
2635
override suspend fun addFoodToOrder(userId: UUID, foodDto: FoodDto, quantity: Int): Result<Int> = dbQuery {
2736
Orders.select {
2837
(Orders.userId eq userId) and (Orders.orderStatus eq OrderStatus.Started)

0 commit comments

Comments
 (0)