- CategoryLive.Index: browse categories with business counts - CategoryLive.Show: view businesses filtered by category - BusinessLive.Index: search/filter businesses with geolocation - BusinessLive.Show: detailed business profile with hours - BusinessLive.New: submission form for new businesses - BusinessLive.Map: interactive Leaflet.js map view - Seed data with sample Columbus, OH businesses 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
202 lines
5.5 KiB
Elixir
202 lines
5.5 KiB
Elixir
# Script for populating the database. You can run it as:
|
|
#
|
|
# mix run priv/repo/seeds.exs
|
|
#
|
|
# Inside the script, you can read and write to any of your
|
|
# repositories directly:
|
|
#
|
|
# Localspot.Repo.insert!(%Localspot.SomeSchema{})
|
|
#
|
|
# We recommend using the bang functions (`insert!`, `update!`
|
|
# and so on) as they will fail if something goes wrong.
|
|
|
|
alias Localspot.Repo
|
|
alias Localspot.Businesses.{Category, Business, BusinessHour, BusinessPhoto}
|
|
|
|
# Clear existing data
|
|
Repo.delete_all(BusinessPhoto)
|
|
Repo.delete_all(BusinessHour)
|
|
Repo.delete_all(Business)
|
|
Repo.delete_all(Category)
|
|
|
|
# Create categories
|
|
categories =
|
|
[
|
|
%{
|
|
name: "Restaurants",
|
|
slug: "restaurants",
|
|
description: "Local dining establishments",
|
|
icon: "hero-cake"
|
|
},
|
|
%{
|
|
name: "Coffee Shops",
|
|
slug: "coffee-shops",
|
|
description: "Cafes and coffee houses",
|
|
icon: "hero-cup-soda"
|
|
},
|
|
%{name: "Retail", slug: "retail", description: "Shops and stores", icon: "hero-shopping-bag"},
|
|
%{
|
|
name: "Services",
|
|
slug: "services",
|
|
description: "Professional services",
|
|
icon: "hero-wrench-screwdriver"
|
|
},
|
|
%{
|
|
name: "Arts & Entertainment",
|
|
slug: "arts-entertainment",
|
|
description: "Galleries, theaters, and venues",
|
|
icon: "hero-paint-brush"
|
|
}
|
|
]
|
|
|> Enum.map(fn attrs ->
|
|
%Category{}
|
|
|> Category.changeset(attrs)
|
|
|> Repo.insert!()
|
|
end)
|
|
|
|
[restaurants, coffee, retail, services, arts] = categories
|
|
|
|
# Sample businesses - using Columbus, OH area coordinates
|
|
businesses_data = [
|
|
%{
|
|
name: "The Cozy Bean",
|
|
slug: "the-cozy-bean",
|
|
description:
|
|
"A family-owned coffee shop serving locally roasted beans and homemade pastries since 1998.",
|
|
street_address: "123 High Street",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zip_code: "43215",
|
|
latitude: Decimal.new("39.9612"),
|
|
longitude: Decimal.new("-82.9988"),
|
|
phone: "6145551234",
|
|
email: "hello@cozybean.example",
|
|
website: "https://cozybean.example",
|
|
locally_owned: true,
|
|
category_id: coffee.id
|
|
},
|
|
%{
|
|
name: "Mama Rosa's Kitchen",
|
|
slug: "mama-rosas-kitchen",
|
|
description:
|
|
"Authentic Italian cuisine made with recipes passed down through four generations.",
|
|
street_address: "456 Main Street",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zip_code: "43215",
|
|
latitude: Decimal.new("39.9650"),
|
|
longitude: Decimal.new("-83.0020"),
|
|
phone: "6145555678",
|
|
email: "reservations@mamarosas.example",
|
|
website: "https://mamarosas.example",
|
|
locally_owned: true,
|
|
category_id: restaurants.id
|
|
},
|
|
%{
|
|
name: "Buckeye Books",
|
|
slug: "buckeye-books",
|
|
description: "Independent bookstore specializing in local authors and rare finds.",
|
|
street_address: "789 Oak Avenue",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zip_code: "43215",
|
|
latitude: Decimal.new("39.9580"),
|
|
longitude: Decimal.new("-82.9950"),
|
|
phone: "6145559012",
|
|
locally_owned: true,
|
|
category_id: retail.id
|
|
},
|
|
%{
|
|
name: "Short North Gallery",
|
|
slug: "short-north-gallery",
|
|
description: "Contemporary art gallery featuring works by Ohio artists.",
|
|
street_address: "321 Short North Ave",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zip_code: "43201",
|
|
latitude: Decimal.new("39.9750"),
|
|
longitude: Decimal.new("-83.0030"),
|
|
locally_owned: true,
|
|
category_id: arts.id
|
|
},
|
|
%{
|
|
name: "Fix-It Fred's",
|
|
slug: "fix-it-freds",
|
|
description:
|
|
"Family-owned repair shop for electronics, appliances, and more. If it's broken, Fred can fix it!",
|
|
street_address: "555 Repair Lane",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zip_code: "43215",
|
|
latitude: Decimal.new("39.9520"),
|
|
longitude: Decimal.new("-83.0100"),
|
|
phone: "6145553456",
|
|
email: "fred@fixitfreds.example",
|
|
locally_owned: true,
|
|
category_id: services.id
|
|
},
|
|
%{
|
|
name: "German Village Bakery",
|
|
slug: "german-village-bakery",
|
|
description: "Traditional German pastries and breads baked fresh daily.",
|
|
street_address: "888 Schiller Park",
|
|
city: "Columbus",
|
|
state: "OH",
|
|
zip_code: "43206",
|
|
latitude: Decimal.new("39.9430"),
|
|
longitude: Decimal.new("-82.9920"),
|
|
phone: "6145557890",
|
|
locally_owned: true,
|
|
category_id: restaurants.id
|
|
}
|
|
]
|
|
|
|
businesses =
|
|
businesses_data
|
|
|> Enum.map(fn attrs ->
|
|
%Business{}
|
|
|> Business.changeset(attrs)
|
|
|> Repo.insert!()
|
|
end)
|
|
|
|
# Add hours for each business (most open 9-5 or similar)
|
|
for business <- businesses do
|
|
# Monday through Friday: 9 AM - 5 PM (or restaurant hours)
|
|
is_restaurant = business.category_id == restaurants.id
|
|
|
|
for day <- 1..5 do
|
|
%BusinessHour{}
|
|
|> BusinessHour.changeset(%{
|
|
business_id: business.id,
|
|
day_of_week: day,
|
|
opens_at: if(is_restaurant, do: ~T[11:00:00], else: ~T[09:00:00]),
|
|
closes_at: if(is_restaurant, do: ~T[21:00:00], else: ~T[17:00:00]),
|
|
closed: false
|
|
})
|
|
|> Repo.insert!()
|
|
end
|
|
|
|
# Saturday: shorter hours
|
|
%BusinessHour{}
|
|
|> BusinessHour.changeset(%{
|
|
business_id: business.id,
|
|
day_of_week: 6,
|
|
opens_at: ~T[10:00:00],
|
|
closes_at: ~T[15:00:00],
|
|
closed: false
|
|
})
|
|
|> Repo.insert!()
|
|
|
|
# Sunday: closed (except restaurants)
|
|
%BusinessHour{}
|
|
|> BusinessHour.changeset(%{
|
|
business_id: business.id,
|
|
day_of_week: 0,
|
|
opens_at: if(is_restaurant, do: ~T[12:00:00], else: nil),
|
|
closes_at: if(is_restaurant, do: ~T[20:00:00], else: nil),
|
|
closed: !is_restaurant
|
|
})
|
|
|> Repo.insert!()
|
|
end
|
|
|
|
IO.puts("Seeded #{length(categories)} categories and #{length(businesses)} businesses")
|