This proyect is a REST API with CRUD operations on restaurants. This API responds in JSON and ignores the requested format if provided.
Behavior Driven Development is guided with guard.
Testing with rspec.
Ruby style guide with rubocop.
Server running with rails as an
API,
using postgresql-9.5 database.
Deployment App is in Heroku
Data validation on database-level is austere as its requirements were not specified.
- Latitude
latcan't be empty. - Longitude
lngcan't be empty. local_idcan't be empty and has to be unique.
Validation on Rails::ActiveRecord model will check for the presence of
lat, lng and local_id.
It will also validate that the rating is between 0 and 4 inclusive.
Before the record is saved, a POINT is created using lat and lng if they
were changed. (It will happen on creation aswell as they chage from being empty).
The scope within was added to class Restaurant to easier find records within
a certain distance of one point, given in latitude, longitude and distance.
The attributes of the table restaurants (and thus the model Restaurant) are:
id: PK, integer (As default by Rails)rating: integerlocal_id: string, index: true, unique: truename: stringsite: stringemail: stringphone: stringstreet: stringcity: stringstate: stringlat: float, null: falselng: float, null: falsecreated_atdatetime, null: false (As default by Rails)updated_atdatetime, null: false (As deault by Rails)lonlat: st_point, srid: 4326, geographic: true (Datatype provided by PostGIS)
PostGIS is used to make spatial queries. To use it, an extension on
PostgreSQL is needed. This extension may be created manually or using
the command rails db:gis:setup after
the gem activerecord-postgis-adapter is installed.
The function ST_Distance used to calculate the distance between two points
uses meters as the distance unit by default.
All responses are in JSON format.
Available routes are:
GET /restaurantswill show all available restaurantsGET /restaurants/:local_idwill show all the attributes of the restaurat matching that local_id.POST /restaurantswill expect parameters named exactly as the restaurant attributes and create a new restaurant.PATCH/PUT /restaurants/:local_idwill update that restaurant with new data. Note that the parameterlocal_idin the new data will be ignored so that attribute will remain unchanged.DELETE /restaurants/:local_idwill delete the restaurant from the database.GET /restaurants/statisticsreceives the parameters:longitude,latitudeandradiusto return how many restaurants are in that area, and the average & standard deviation of their ratings.- The root
/redirects to/restaurants
ffaker gem is use to create random data for columns like city and email.
This random data is sent to FactoryBot to build restaurants using the model
Restaurant class.
Controller Specs assert correct response format, and changes in database.
Model Specs assert validity of records.
Routing Specs assert correct matching of url with controller actions.
Request Specs were eliminated as there is no need for complex user flows to assert.
For documentation on specific functionality refer to each spec.
Each restaurant record will have its own id in this database, as an incrementing integer.
This is used to separate database managing from data itself. This local_id must be unique
and has an index on the table restaurants.
rubocop is used as the style guide enforcer. All code in master is expected
to compel to its rules as long as Specs are still green.
Database configuration is not in this repo, as specified in the .gitignore file.
A local config/database.yml file may be required.
The column lonlat should be eliminated and introduce the attributes lng
and lat to create that point on each query.
The email should be validated to have a correct format in Restaurant class.
The telephone should be validated to have a correct format in Restaurant class.