Seed the Real Canteen and Operating Accounts
You build a deterministic canteen dataset containing a real location, menu, opening hours and operating users. Its opening windows integrate with the existing Week 2 hours index.
Ticket
Build the canteen seed dataset in backend/internal/canteen/canteen.go. It must describe a real restaurant or hostel canteen, including its location, menu, opening windows and operating users. Convert its opening windows into the existing Week 2 hours.Slot representation.
The preview APK needs believable restaurant data so testers can exercise the ordering workflow with realistic prices and opening hours. The restaurant and rider identities also provide the operating roles needed for the demonstration. The next exercise uses feedback from this application to prioritize and fix reported bugs.
The supplied tests use this exported contract:
type Item struct {
Name, Category string
PricePaise int
}
type Window struct {
OpenMin, CloseMin int
}
type Person struct {
Name, Email, Role string
}
type Place struct {
Name string
Lat, Lng float64
Hours []Window
Items []Item
People []Person
}
func Canteen() Place
func (p Place) Slots(restaurantID int64) []hours.SlotThe acceptance tests are already provided in backend/internal/canteen/canteen_test.go. Do not modify them.
Acceptance criteria
- The canteen has a non-empty name. Its latitude is between
-90and90, its longitude is between-180and180, and its coordinates are not(0, 0). - The menu contains at least 8 items across at least 3 distinct categories.
- Every item has a non-blank name and category. Item names are unique after trimming whitespace and ignoring capitalization.
- Every
PricePaiseis positive, divisible by100, and no greater than100000. Prices represent whole-rupee amounts stored in paise. - The canteen has at least one opening window. Every
OpenMinandCloseMinis between0and1439, and the two values are different. - The opening windows produce an index through
hours.Build(p.Slots(7))that reports at least one open minute and at least one closed minute. At an open minute,OpenAtreturns exactly[7]. - Every slot returned by
Slots(42)carriesRestaurantID: 42. - The people include at least one
restaurantand onerider. Every email contains@, emails are unique without regard to capitalization, and every role is one ofcustomer,restaurantorrider. - No field in
canteen.Personhas a name containingpass,secretortoken, regardless of capitalization. - Repeated calls to
canteen.Canteen()return identical logical data.
Constraints
- Choose a real hostel canteen or nearby restaurant. Use its actual geographic coordinates rather than
(0, 0). - Keep
Canteen()deterministic. Do not use randomness, the current time, generated identifiers or environment-dependent values. - Store prices as integer paise. Prices must be positive multiples of
100and no greater than100000. - Do not modify the provided tests.
Design direction
Keep the implementation in package canteen at backend/internal/canteen/canteen.go. Define the data structures around the business description rather than database records. Let Canteen() return fixed seed data, and let Slots(restaurantID) adapt its configured opening windows into the existing hours.Slot values. Any layout that meets the contract passes.
Reuse the Week 2 hours package for opening-time validation. Its bitset index already represents opening windows, so avoid creating another indexing implementation. Preserve the existing half-open interval semantics, including their handling of window boundaries and overnight windows.
Keep prices as integer paise rather than floating-point rupees. This avoids introducing rounding behaviour into the data that eventually enters the ordering and payment code.
Keep business identity separate from authentication. Names, email addresses and roles belong in the seed dataset. Passwords and tokens belong in the existing authentication flow. When you later create actual accounts, obtain passwords from environment variables.
Use realistic menu offerings and operating hours. A dataset that satisfies the minimum item count but does not resemble the place you selected defeats the purpose of testing the application with real users.
How to check your work
Run the supplied acceptance tests from the repository root:
cd backend
make test W=7B6All 10 tests must pass. When a test fails, read the first failing assertion to identify whether the problem is in the business data, opening-window conversion, operating identities or deterministic output.
The reference solution passes every check for this exercise. Try the hints first; reading the answer before you have struggled with the problem teaches much less.
Implementation
Run locally
Write the code in your editor inside zomato-prep, then work through this list.
make test W=7B6passes all 10 tests.- The canteen has a real location and at least 8 menu items across 3 categories.
- All menu prices are valid whole-rupee amounts stored in paise.
- Opening windows work with the existing Week 2 hours index.
- Restaurant and rider users have distinct emails without credentials in seed data.
- Repeated calls return identical canteen data.
Commands
cd backend && make test W=7B6Tests
TestW7B6_CanteenHasANameAndARealLocationinbackend/internal/canteen/canteen_test.goTestW7B6_MenuHasEightItemsInThreeCategoriesinbackend/internal/canteen/canteen_test.goTestW7B6_ItemNamesAreUniqueAndNotBlankinbackend/internal/canteen/canteen_test.goTestW7B6_PricesAreWholeRupeesStoredInPaiseinbackend/internal/canteen/canteen_test.goTestW7B6_OpeningWindowsAreValidMinutesOfTheDayinbackend/internal/canteen/canteen_test.goTestW7B6_OpeningWindowsDriveTheWeek2Indexinbackend/internal/canteen/canteen_test.goTestW7B6_SlotsCarryTheRestaurantIDinbackend/internal/canteen/canteen_test.goTestW7B6_HasARestaurantUserAndARiderWithDistinctEmailsinbackend/internal/canteen/canteen_test.goTestW7B6_SeedDataCarriesNoPasswordsinbackend/internal/canteen/canteen_test.goTestW7B6_CanteenIsDeterministicinbackend/internal/canteen/canteen_test.go