Gear-UP
Logistics for group adventures outdoors can be complicated, especially when it comes to getting all of your gear in order. Gear Up simplifies this by giving users a platform to easily organize trips, decide who is bringing what gear, then determine what the group still needs and who might have that gear already!
-Gear Up BE is the "Back End" application that acts as a microservice for the Gear UP FE web application.
-Consultancy Competition
-MiroBoard
- Background and Description
- Schema
- Learning Goals
- Requirements and Setup (for Mac):
- Heroku Setup
- Endpoints
- Contributors
Our “Back End” application will be an API built in Rails. It will act as the interface layer to our database, and it will handle our API consumption.
* Rails Backend
* this is a `rails new --api` project
* it will have more thorough testing, follow our Facade and Service design patterns, and make use of Serializers
* There is no ERB, HTML or CSS, JavaScript, anywhere in this project
* All input is received as JSON data; it only responds with JSON data
* we recommend eager loading where possible, and use of the “bullet” gem to detect N+1 queries
* Extensions:
1. using Rails caching and/or memoization to cache/memoize data retrieved from external APIs
2. hosted on an alternate service provider (AWS, Digital Ocean, etc)
3. use background worker
- Ruby Version 2.7.2
- Rails Version 5.2.8
- capybara
- faker
- factory_bot_rails
- faraday
- figaro
- jsonapi-serializer
- jsonl
- launchy
- pry
- shoulda-matchers
- simplecov
- rspec_junit_formatter
- rspec
- Create a Base Directory
- On your local machine open a terminal session and enter the following commands to create a base directory for the app.
$ mkdir gear_up
$ cd gear_up
- Clone these repositories:
- On your local machine open a terminal session and enter the following commands for SSH or HTTPS to clone the back end repositiory.
- using ssh key
$ git clone [email protected]:ShermanA-13/gear-up-be.git
- using https
$ git clone https://github.com/ShermanA-13/gear-up-be.git
- Once cloned, enter the following commands for SSH or HTTPS to clone the front end repositiory.
- using ssh key
$ git clone [email protected]:ShermanA-13/gear-up-fe.git
- using https
$ git clone https://github.com/ShermanA-13/gear-up-fe.git
- Once cloned, you'll have a new local copies of the directories you ran the clone command in. You can check what is in the directory by running the following command
$ ls
#ex.
gear-up-be gear-up-fe
- Install required Gems utilizing Bundler:
In terminal, use Bundler to install any missing Gems. If Bundler is not installed, first run the following command.
$ gem install bundler
- If Bundler is already installed or after it has been installed, run the following command.
$ bundle install
- There should be be verbose text diplayed of the installation process that looks similar to below. (this is not an actual copy of what will be output).
Click to see example!
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.6
Using concurrent-ruby 1.1.10
...
...
...
Using simplecov_json_formatter 0.1.4
Using simplecov 0.21.2
Using spring 2.1.1
Using spring-watcher-listen 2.0.1
Using standard 1.12.1
Bundle complete! 23 Gemfile dependencies, 94 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
- If there are any errors, verify that bundler, Rails, and your ruby environment are correctly setup.
- Figaro installation
- Follow the figaro installation with the docs and get your openweather.org key. Add the open weather api key to your newly created
config/application.yml
file and add it to your.gitignore
file. Be sure to read the open weather API docs for a deeper undestanding of the app.
$ bundle exec figaro install
- Database Migration
Before using the web application you will need to setup your databases locally by running the following command
$ rails db:{:drop,:create,:migrate}
Click to see example!
Created database 'gear_up_be_development'
Created database 'gear_up_be_test'
== 20220602171308 CreateUsers: migrating ======================================
-- create_table(:users)
-> 0.0051s
== 20220602171308 CreateUsers: migrated (0.0051s) =============================
== 20220602171328 CreateItems: migrating ======================================
-- create_table(:items)
-> 0.0081s
== 20220602171328 CreateItems: migrated (0.0081s) =============================
== 20220602171337 CreateTrips: migrating ======================================
-- create_table(:trips)
-> 0.0020s
== 20220602171337 CreateTrips: migrated (0.0020s) =============================
== 20220602171347 CreateTripUsers: migrating ==================================
-- create_table(:trip_users)
-> 0.0036s
== 20220602171347 CreateTripUsers: migrated (0.0036s) =========================
== 20220602171355 CreateTripItems: migrating ==================================
-- create_table(:trip_items)
-> 0.0028s
== 20220602171355 CreateTripItems: migrated (0.0028s) =========================
== 20220604204302 CreateAreas: migrating ======================================
-- create_table(:areas)
-> 0.0015s
== 20220604204302 CreateAreas: migrated (0.0016s) =============================
== 20220604214856 AddAreaToTrip: migrating ====================================
-- add_reference(:trips, :area, {:foreign_key=>true})
-> 0.0016s
== 20220604214856 AddAreaToTrip: migrated (0.0017s) ===========================
== 20220604220355 RemoveLocationFromTrip: migrating ===========================
-- remove_column(:trips, :location, :string)
-> 0.0003s
== 20220604220355 RemoveLocationFromTrip: migrated (0.0003s) ==================
- Seeding Database
In terminal, use$ rake load_areas:areas
to parse through theopenbeta-conus-areas.jsonlines
and seed into your database.
$ rake load_areas:areas
- Then run the command:
$ rails db:seed
- Startup and Access
In `/config/puma.rb`, you'll notice that the port has changed from 3000 to 5000. This should be on or around line 12.
port ENV.fetch("PORT") { 5000 }
We do this because [Gear Up BE](https://github.com/ShermanA-13/gear-up-be) is not in production or hosted somewhere other than localhost. If Gear Up BE is running on `port 3000`, our front end will need to have a different port so they can run at the same time. Now, when we do `rails s`, our back end application will automatically use port 5000. You can also do this manually every time you start your server by passing the port number with a `-p` flag like so:
`rails s -p 5000`.
- You should see that your server is
"listening on tcp://localhost:5000"
now instead of the usual 3000.
In order for your frontend to properly get data from your backend Gear Up API, you must keep your backend server running locally at the same time.
- Finally, in order to use the web app you will have to start the both Gear Up BE and Gear Up FE servers
- Start the back end server
$ rails s
Click to see example!
=> Booting Puma
=> Rails 5.2.8 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.6 (ruby 2.7.2-p137), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:5000
Use Ctrl-C to stop
- Switch to a new tab
CMD + T
in your terminal then navigate to the front end directory with the command:
$ cd ../gear-up-fe
- Your file patch in your new tab in terminal should be
./gear_up/gear-up-fe
. Start the front end server
$ rails s
-
Open web browser and visit link to access the front end application http://localhost:3000
-
At this point you should be taken an index page with clickable links to different data sets with the ability to create, read, update, and delete data.
- If this is your first time setting up a Heroku server. Take your time to read these documents Heroku Getting Started w/ Rails to familiarize yourself.
- Deploy Application to Heroku is where you want to be after an account is created because your app already exists. You want to repeat the process for the front end application as well. You can check if your app is added on heroku with this command:
$ git remote -v
Click to see example!
heroku https://git.heroku.com/<your app name>.git (fetch)
heroku https://git.heroku.com/<your app name>.git (push)
origin [email protected]:<your github username>/gear-up-be.git (fetch)
origin [email protected]:<your github username>/gear-up-be.git (push)
- If your terminal doesn't reflect the example above input this command
$ heroku git:remote -a <yourapp>
- Deploy your code:
$ git push heroku main
- Migrate and seed your database:
$ heroku run rails db:{create,migrate}
- Once your migrations are finished run this command and after awhile your terminal will produce a similar result in the example below
heroku run rake load_areas:areas
- Ensure your API keys are set up on your web app
From your Heroku dashboard, click on the project you just created, then Settings. In the Config Vars section, click Reveal Config Vars. Here, you can add any API keys with the constant name you gave them in the application.yml file created from the figaro gem.
Download the test suites for Postman:
Click to see example!
api_v1_users GET /api/v1/users(.:format) api/v1/users#index
GET /api/v1/users/:user_id(.:format) api/v1/users#show
POST /api/v1/users(.:format) api/v1/users#create
GET /api/v1/users/:user_id/items(.:format) api/v1/items#index
GET /api/v1/users/:user_id/items/:item_id(.:format) api/v1/items#show
POST /api/v1/users/:user_id/items(.:format) api/v1/items#create
PATCH /api/v1/users/:user_id/items/:item_id(.:format) api/v1/items#update
DELETE /api/v1/users/:user_id/items/:item_id(.:format) api/v1/items#destroy
GET /api/v1/trips/:trip_id/info(.:format) api/v1/trips#info
GET /api/v1/users/:user_id/trips(.:format) api/v1/trips#index
GET /api/v1/trips/:trip_id(.:format) api/v1/trips#show
POST /api/v1/users/:user_id/trips(.:format) api/v1/trips#create
PATCH /api/v1/trips/:trip_id(.:format) api/v1/trips#update
DELETE /api/v1/trips/:trip_id(.:format) api/v1/trips#destroy
GET /api/v1/trips/:trip_id/users(.:format) api/v1/trip_users#index
POST /api/v1/trips/:trip_id/users(.:format) api/v1/trip_users#create
PATCH /api/v1/trips/:trip_id/users(.:format) api/v1/trip_users#update
GET /api/v1/trips/:trip_id/items/:user_id(.:format) api/v1/trip_items#index
GET /api/v1/trips/:trip_id/items(.:format) api/v1/trip_items#show
POST /api/v1/trips/:trip_id/items(.:format) api/v1/trip_items#create
PATCH /api/v1/trips/:trip_id/items(.:format) api/v1/trip_items#update
DELETE /api/v1/trips/:trip_id/items/:trip_item_id(.:format) api/v1/trip_items#destroy
GET /api/v1/areas/:area_id/weather(.:format) api/v1/weathers#index
api_v1_areas_find_all GET /api/v1/areas/find_all(.:format) api/v1/areas#find_all
GET /api/v1/areas/:id(.:format) api/v1/areas#show
Thanks go to these wonderful people (emoji key):
Sherman A. (he/him) 💻 � |
Susan B. (she/her) 💻 � |
Phillp K. (he/him) 💻 � |
Sandiz T. (he/him) 💻 � |
Johnny B. (he/him) 💻 � |
Alicia W. (she/her) 💻 � |
This project follows the all-contributors specification.