Skip to content

babelsh/mission-us-backend

Repository files navigation

Mission Us Rails API

API-Missao-Us GitHub top language Build Status Coverage Status

Dependencies

  • Ruby >= 2.5.1
  • PostgreSQL 10.4

MacOS

brew update
brew install postgres
gem install bundler

Ubuntu

sudo apt-get update
sudo apt-get install postgresql postgresql-contrib postgresql-server-dev-all cmake
gem install bundler

Setup

bundle install
cp config/database.example.yml config/database.yml

echo "POSTGRESQL_PASSWORD='YourPassword'" >> .env
echo "POSTGRESQL_USERNAME='YourUserName'" >> .env

bin/rails db:setup
bin/rails db:migrate
bin/rails db:seed

Testing

Test

We use rspec framework to test our rails api:

bundle exec rspec

Development

Run the local server api at http://localhost:3000 with:

bin/rails s

Models

Creating new Model

bundle exec rails generate model ModelName column_name1:column_type1 column_name1:column_type1 ... column_name1:column_type1

see rails generate

Do correct associations.

Testing

Write that were created by the rails generate.

Controlles/end-points

Creating new Controller/end-point

We are on v1, when create a new end-point create with api::v1::.

bundle exec rails generate scaffold_controller api::v1::name

This makes the code look like this:

module Api
  module V1
    class NameController < ApplicationController
      ...
    end
  end
end

Add resources to routes.rb file:

namespace 'api' do
  namespace 'v1' do
    ...
    resources :yor_controller_name
    ...
  end
end

Testing

Write the tests in the files that were created by the rails generate.

  • test controller
  • test requests
  • test routing

see rails generate

Usage

Requests

Trails

  • index

List all trails that current_user has association

do

http GET http://www.your_domain/api/v1/trails

returns

[
    {
        "created_at": "2018-09-17T04:53:30.281Z",
        "description": "Frankly, my dear, I don’t give a damn.",
        "duration": 3,
        "id": 35,
        "updated_at": "2018-09-17T04:53:30.281Z"
    },
    {
        "created_at": "2018-09-17T04:53:30.525Z",
        "description": "You talking to me?",
        "duration": 4,
        "id": 36,
        "updated_at": "2018-09-17T04:53:30.525Z"
    }
]
  • show

Get informations of one trail that current_user has association

do

http GET http://www.your_domain/api/v1/trails/4

returns

{
    "created_at": "2018-09-17T04:53:30.281Z",
    "description": "Frankly, my dear, I don’t give a damn.",
    "duration": 3,
    "id": 35,
    "updated_at": "2018-09-17T04:53:30.281Z"
}
  • create [WIP] (will be used by professional profiles)

  • update [WIP] (will be used by professional profiles)

  • delete [WIP] (will be used by professional profiles)

Tails/Activities

  • index

List all activities that current_user and trial:id has association

do

http GET http://www.your_domain/api/v1/trails/1/activities

returns

[
    {
        "created_at": "2018-09-17T04:53:30.281Z",
        "description":"this is a description",
        "id":2,
        "title":"this title is cool",
        "updated_at": "2018-09-17T04:53:30.281Z"
    },
    {
        "created_at": "2018-09-17T04:53:30.281Z",
        "description":"this is another description",
        "id":15,
        "title":"this tile isn't cool",
        "updated_at": "2018-09-17T04:53:30.281Z"
    }
]
  • index

Activities

  • index [WIP] (will be used by professional profiles)

  • show [WIP] (will be used by professional profiles)

  • create [WIP] (will be used by professional profiles)

  • update [WIP] (will be used by professional profiles)

  • delete [WIP] (will be used by professional profiles)

Deploy

[WIP]

Guides

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published