On this project, I created an API to get houses information for an App. The idea is to create a simplified version of AirBnb. For now, the API manages creating and signing users (utilizing tokens for validating the sessions/saving the machine login), each user can create, edit, and delete their own places. A table for the places and one for images, to link how many pictures you want on each place and favorite places for the users. The API has also prepared a table for creating and cancel reservations on places.
- Installation
- API calls
- Tests
- Built With
- Live Version
- Future Implementations
- Contributing
- Acknowledgments
- Authors
- License
You can get a local copy of the repository please run the following commands on your terminal:
$ cd <folder>
$ git clone https://github.com/Stricks1/HousesApi.git
The API (server side) is on the folder server. In order to run the server go to the folder run $ bundle install
to get install the gems needed. After that we need to migrate the db with $ rails db:migrate
, and finally you can run the server using the command $ rails server
.
You are ready to access the API on the address http://localhost:3000/
Alternatively you can use our already deployed version with an existing database here
Ruby: >= 2.6.5 - Rails >=5.2.4.3
This API requires a login user to be accessible, so when the user is created or login, one JSON property returned is a token that needs to be used on the Header of any Authenticated calls for it to work. The token is also utilized to know what user is accessing the API in order to know if he have access for editing a place/favorite. The following calls/actions are valid for the API (look the code for more information on detailed returned objects/accepted params):
TYPE | URL | EXPECTED |
---|---|---|
POST | /v1/users | JSON (user info) |
POST | /v1/login | JSON (user info) |
Every Authenticated call, requires a header named
Authorization
with information Bearer [token received on login]
TYPE | URL | EXPECTED |
---|---|---|
GET | /v1/auto_login | JSON (user info) |
GET | /v1/user_is_authed | Info if token is valid |
GET | /v1/logout | Change valid token |
GET | /v1/places | JSON (all places) |
POST | /v1/places | JSON (create place) |
GET | /v1/places/:id | JSON (place info) |
PATCH | /v1/places/:id | JSON (updated place if user is owner) |
PUT | /v1/places/:id | JSON (updated place if user is owner) |
DELETE | /v1/places/:id | Remove place if user is owner |
GET | /v1/rent_dates/ | JSON (rent dates info for user) |
POST | /v1/rent_dates/:id | JSON (Create rent date for user) |
DELETE | /v1/rent_dates/:id | Remove the rent date for user/place |
POST | /v1/images/:id | JSON (Create image for place) |
DELETE | /v1/images/:id | Remove the image from place |
GET | /v1/favorites/ | JSON (Favorite places for user) |
POST | /v1/favorites/ | Create favorite place for user |
DELETE | /v1/favorites/:id | Remove the favorite place from user |
POST | /v1/occupied/:id | Get occupied dates from place between param dates |
To RoR RSpec tests we have the following files:
rspec spec/controllers/auth_spec.rb
rspec spec/controllers/favorites_spec.rb
rspec spec/controllers/images_spec.rb
rspec spec/controllers/places_spec.rb
rspec spec/controllers/rent_dates_spec.rb
rspec spec/controllers/users_spec.rb
rspec spec/models/favorites_spec.rb
rspec spec/models/images_spec.rb
rspec spec/models/places_spec.rb
rspec spec/models/rent_dates_spec.rb
rspec spec/models/users_spec.rb
- Ruby on Rails
- Rspec
- Faker
- FactoryBot
- For future implementations, I consider creating a table for a chat between users so the owner and the renter can speak.
Contributions, issues and feature requests are welcome!
You can do it on issues page.
This project was inspired by this behance project idea by Alexey Savitskiy
Special thanks to code reviewers.
Give a ⭐️ if you like this project!
👤 Gabriel Malheiros Silveira
- Github: @Stricks1
- Linkedin: Gabriel Silveira
- Twitter: @Gabriel_Stricks
Creative Commons 2020