Problem Statement
- Create an API backend for a restaurant app, using Godspeed Framework.
-
which has below REST API’s:
Method URL Description GET /restaurant/:restaurantId Fetch a restaurant by restaurantId POST /restaurant Createa a new restaurant PUT /restaurant Update an existing restaurant DELETE /restaurant/:restaurantId Delete an existing restaurant POST /restaurant/search Fetch restaurants of a particular city, and have Menu Items also in the response, If `couponCode` is provided, it should filter only those menu items which are for that code. -
Populate database with atleast 5 restaurants
-
Some coupon codes are
HUNGRY25
,HUNGRY50
Steps
- Install Godspeed CLI in your local machine. Here is a detailed guide.
- Create a new godspeed project
restaurant-app
using Godspeed CLI, You can follow this, Selectpostgres
as database. and then Open it in VSCode. - Inside VSCode click on
Open in Container
. Now you newly created project is running in dev container. - From the terminal, run
godspeed build
and thengodspeed dev
. Your documentation will be served in selected port [default 3000]. - Copy below prisma schema in
src/datasources/postgres.prisma
. You can read about Prisma ORM and Schema.
generator client {
provider = "prisma-client-js"
output = "./generated-clients/postgres"
previewFeatures = ["metrics"]
}
datasource db {
provider = "postgresql"
url = env("POSTGRES_URL")
}
model Owner {
id Int @id @default(autoincrement())
email String @unique
name String?
}
model Restaurant {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
name String
since DateTime
isOpen Boolean @default(false)
opsStartTime DateTime
opsEndTime DateTime
ownerId Int?
slug String @unique
description String?
location String
menuItems MenuItems[]
}
model Category {
id Int @id @default(autoincrement())
name String
}
model MenuItems {
id Int @id @default(autoincrement())
name String
description String?
price Int
couponCode String[]
restaurant Restaurant @relation(fields: [restaurantId], references: id)
restaurantId Int
}
model Order {
id Int @id @default(autoincrement())
frmoRestaurant Int
orderStatus OrderStatus @default(NOT_INITIATED)
placedAt DateTime?
fulfilledAt DateTime?
orderItems OrderItem[]
}
model OrderItem {
id Int @id @default(autoincrement())
menuItemId Int
quantity Int
order Order @relation(fields: [orderId], references: id)
orderId Int
}
enum OrderStatus {
INITIATED
NOT_INITIATED
WAITING_FOR_APPROVAL_FROM_RESTAURANT
WAITING_FOR_DELIVERY_PARTNER
PLACED
PICKUP_BY_DELIVERY_PARTNER
DELIVERED
READY_TO_PICKUP
}
- You can use
godspeed gen-crud-api
to auto-generate REST api based on your schema. - For the last API in
problem statement
, These things might be helpful:
Evaluation
Your solution will be only evaluated if
- Your code is hosted in a public repository.
- You follow the GodspeedSystems github org.
- You star the gs-node-service repository of Godspeed.
References
- Getting started guide
- Documentation
- Demo video of the Godspeed framework part one, part two