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:

go
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.Slot

The 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 -90 and 90, its longitude is between -180 and 180, 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 PricePaise is positive, divisible by 100, and no greater than 100000. Prices represent whole-rupee amounts stored in paise.
  • The canteen has at least one opening window. Every OpenMin and CloseMin is between 0 and 1439, 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, OpenAt returns exactly [7].
  • Every slot returned by Slots(42) carries RestaurantID: 42.
  • The people include at least one restaurant and one rider. Every email contains @, emails are unique without regard to capitalization, and every role is one of customer, restaurant or rider.
  • No field in canteen.Person has a name containing pass, secret or token, 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 100 and no greater than 100000.
  • 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:

bash
cd backend
make test W=7B6

All 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.

Finished Exercise 7.10?

Implementation

Run locally

Write the code in your editor inside zomato-prep, then work through this list.

  1. make test W=7B6 passes all 10 tests.
  2. The canteen has a real location and at least 8 menu items across 3 categories.
  3. All menu prices are valid whole-rupee amounts stored in paise.
  4. Opening windows work with the existing Week 2 hours index.
  5. Restaurant and rider users have distinct emails without credentials in seed data.
  6. Repeated calls return identical canteen data.

Commands

terminal
cd backend && make test W=7B6

Tests

  • TestW7B6_CanteenHasANameAndARealLocation in backend/internal/canteen/canteen_test.go
  • TestW7B6_MenuHasEightItemsInThreeCategories in backend/internal/canteen/canteen_test.go
  • TestW7B6_ItemNamesAreUniqueAndNotBlank in backend/internal/canteen/canteen_test.go
  • TestW7B6_PricesAreWholeRupeesStoredInPaise in backend/internal/canteen/canteen_test.go
  • TestW7B6_OpeningWindowsAreValidMinutesOfTheDay in backend/internal/canteen/canteen_test.go
  • TestW7B6_OpeningWindowsDriveTheWeek2Index in backend/internal/canteen/canteen_test.go
  • TestW7B6_SlotsCarryTheRestaurantID in backend/internal/canteen/canteen_test.go
  • TestW7B6_HasARestaurantUserAndARiderWithDistinctEmails in backend/internal/canteen/canteen_test.go
  • TestW7B6_SeedDataCarriesNoPasswords in backend/internal/canteen/canteen_test.go
  • TestW7B6_CanteenIsDeterministic in backend/internal/canteen/canteen_test.go