Skip to content

Commit

Permalink
feature(signup): Signup a new business
Browse files Browse the repository at this point in the history
Allows a new business to create their primary business location, add additional locations, and add additional employees
  • Loading branch information
mrmod committed Apr 19, 2020
1 parent 9ebf163 commit 557e347
Show file tree
Hide file tree
Showing 35 changed files with 875 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ yarn-debug.log*
mapdata/n*
mapdata/*.rb
!mapdata/mapdata.json
.env
.env.development
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ gem 'jbuilder', '~> 2.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

gem 'pg'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
pg (1.2.3)
public_suffix (4.0.3)
puma (4.3.3)
nio4r (~> 2.0)
Expand Down Expand Up @@ -239,6 +240,7 @@ DEPENDENCIES
foreman
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
pg
puma (~> 4.1)
rails (~> 6.0.2, >= 6.0.2.1)
rgeo-shapefile
Expand Down
19 changes: 15 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Things look good so far. Below are the things we talked about and wanted to get

# Things

* Posts don't need tags right now
* Posts don't need tags right now [Done]
* Ability to create locations for a business
* Posts should be sortable by post.created_at and latest commented
* Posts should be the default view
* Who commented and when they commented
Expand All @@ -28,13 +29,24 @@ Things look good so far. Below are the things we talked about and wanted to get
* Posts should show up for the Neighboorhoods selected
* A side bar allowing the Neighborhood selection in Posts and Events

## Feature: Neighborhood creation
## Feature: Check if Business Location in Region

When a Business joins and gives their address, a check should be done to see if that addresses Lat/Long are within an existing Region. If it is, then their Location gets put in that region. If it isn't, they should be able to create a new Region.

### Migrations

```
rails g migration AddGooglePlacesToLocation places_id:string places_neighborhood:string
rails g migration AddEmailToEmployee email:string
```

## Feature: Neighborhood creation [Done]

When a business creates a location for itself and it isn't inside of any Region then the business should be allowed to draw a new region and be set as the leader of that region.

A location belongs to a Region
```
# A REgion has many location
# A Region has many location
rails g model Region name:string points:text
rails g migration AddRegionToLocation region:references
rails g migration AddLatLongToLocation lat:decimal long:decimal
Expand All @@ -52,7 +64,6 @@ Restricted to Maps Javascript API from localhost or localhost/*

* Ability to create regions [Done]
* Ability to see regions for business locations [Done]
* Ability to create locations for a business

# Locality

Expand Down
13 changes: 13 additions & 0 deletions app/controllers/api/v1/businesses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ def show
render json: @business, include: [:locations]
end

def update
@business = Business.find params[:id]
unless @business.present?
render json: null, status: 404
return
end
@business.update valid_params
render json: @business
end

# GET /businesses/:business_id/locations
def show_locations
@business = Business.find_by_id params[:business_id]
Expand Down Expand Up @@ -45,6 +55,7 @@ def valid_params
:website,
:employee_business,
:handle,
:type,
)
end
def valid_location_params
Expand All @@ -60,6 +71,8 @@ def valid_location_params
:long,
:primary,
:region_id,
:places_id,
:places_neighborhood,
)
end
end
19 changes: 19 additions & 0 deletions app/controllers/api/v1/employees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Api::V1::EmployeesController < ApplicationController
def index
render json: Employee.all
end

def show
@employee = Employee.find_by_id params[:id]
if @employee.present?
Expand All @@ -12,11 +13,29 @@ def show
end

def create
@employee = Employee.create valid_params

if @employee.invalid?
render json: @employee.errors, status: 400
else
render json: @mployee
end
end

def delete
end

def update
end

private
def valid_params
params.require(:employee).permit(
:name,
:email,
:business_id,
:handle,
:role,
)
end
end
22 changes: 15 additions & 7 deletions app/controllers/api/v1/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,28 @@ def index
end

def create
@location = Location.create valid_params
if @location.invalid?
render json: @location.errors, status: 400
else
render json: @location
end
end

def delete
end

def update
@location = Location.find_by_id params[:id]
if @location.present?
if @location.update valid_params
render json: @location
else
render json: @location.errors, status: 400
end
else
unless @location.present?
render json: null, status: 404
return
end

if @location.update valid_params
render json: @location
else
render json: @location.errors, status: 400
end
end

Expand Down Expand Up @@ -48,6 +55,7 @@ def valid_params
:lat,
:long,
:primary,
:business_id,
)
end
end
15 changes: 12 additions & 3 deletions app/controllers/api/v1/regions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
class Api::V1::RegionsController < ApplicationController
def index
if params[:name]
render json: Region.find_by_name(params[:name])
else
render json: Region.all
end
end

def create
@region = Region.create valid_params
File.open(File.join(Rails.root, 'sample_regions.json'), 'a+') do |samples|
samples.write JSON.dump(valid_params['points']) + ","
end
# Save regions to create fake regions
# File.open(File.join(Rails.root, 'sample_regions.json'), 'a+') do |samples|
# samples.write JSON.dump(valid_params['points']) + ","
# end
if @region.invalid?
render json: @region.errors, status: 400
else
Expand Down
4 changes: 0 additions & 4 deletions app/javascript/components/EditableEvent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default {
})
},
invitedBusiness: function(eventInvitation) {
console.log(`Adding invitation`, eventInvitation)
this.invitations.push(eventInvitation)
this.businesses = this.businesses.filter(b => b.id !== eventInvitation.guest_business_id)
},
Expand All @@ -124,11 +123,8 @@ export default {
this.$emit('saveEvent')
},
deletedInvitation: function(id) {
console.log(`Deleting invitation ${id} from ${this.invitations.length}`)
let invitation = this.invitations.find(i => i.id === id)
console.log('Removing', invitation)
this.invitations = this.invitations.filter(i => i.id !== invitation.id)
console.log('There are now ', this.invitations.length)
},
initializeData: function() {
this.name = ''
Expand Down
16 changes: 16 additions & 0 deletions app/javascript/components/GoogleMapInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<template>
<md-input>
</md-input>
</template>
<script>
import initGoogle from '../services/google'
export default {
name: 'GoogleMapInput',
mounted() {
let vm = this
initGoogle.then(google => {
let autocomplete = new google.maps.places.Autocomplete(vm.$refs.placesSearch)
})
},
}
</script>
57 changes: 57 additions & 0 deletions app/javascript/components/LocationFinder.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div id="location-finder">
<div id="search-result" ref="searchResult">
</div>
<md-field>
<label>Business Name and City</label>
<md-input @keypress='addressSearch' v-model='address' />
</md-field>
</div>
</template>
<script>
import initGoogle from '../services/google'
export default {
name: 'LocationFinder',
data() {
return {
places: null,
address: '',
}
},
mounted() {
initGoogle.then(google => {
this.places = new google.maps.places.PlacesService(this.$refs.searchResult)
})
},
methods: {
addressSearch(e) {
if (e.key !== 'Enter') {
return
}
e.preventDefault()
if (this.address.length > 3 && this.address.indexOf(' ') > 0) {
// https://developers.google.com/maps/documentation/javascript/reference/places-service#FindPlaceFromQueryRequest
// Uses the Basic Data SKU https://developers.google.com/maps/billing/gmp-billing#basic-data
let searchRequest = {
fields: [
// 'address_components',
'formatted_address',
'name',
'place_id',
// 'url',
// 'utc_offset',
// 'vicinity',
],
query: this.address,
}
if (this.places) {
this.places.findPlaceFromQuery(searchRequest, (results) => {
this.$emit('results', results)
})
}
}
}
}
}
</script>
52 changes: 52 additions & 0 deletions app/javascript/components/LocationSelector.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div id="location-selector">
<LocationFinder v-on:results='handleResults' />
<md-list>
<md-list-item
v-for='(l, id) in locationResults'
:key='l.place_id'
@click='() => selectBusinessLocation(id, l)'
:class='selectedLocationIndex === id ? "selected-location": ""'
>
<div class="md-list-item-text">
<span>{{l.name}}</span>
<span>{{l.formatted_address}}</span>
</div>
</md-list-item>
</md-list>
</div>
</template>
<script>
import LocationFinder from './LocationFinder.vue'
export default {
name: 'LocationSelector',
components: {LocationFinder},
data() {
return {
selectedLocationIndex: -1,
location: null,
locationResults: [],
}
},
methods: {
handleResults(locationResults) {
this.locationResults = locationResults
},
selectBusinessLocation(index, googlePlacesLocation) {
if (this.selectedLocationIndex === index) {
this.selectedLocationIndex = -1
this.$emit('locationSelected', null)
return
}
this.selectedLocationIndex = index
this.$emit('locationSelected', googlePlacesLocation)
},
}
}
</script>
<style scoped>
.selected-location {
background-color: rgba(255, 201,135, .3);
}
</style>
1 change: 0 additions & 1 deletion app/javascript/components/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export default {
return []
}
}
console.log('no region found for', location.region_id)
return []
},
}
Expand Down
Loading

0 comments on commit 557e347

Please sign in to comment.