This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.routes.draw do | |
| # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.routes.draw do | |
| # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | |
| root 'application#index', format: 'json' | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ApplicationController < ActionController::API | |
| def index | |
| render json: { status: 200, message: 'Hello World'} | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http | role | route | |
|---|---|---|---|
| GET | Get an app | /v1/apps/{int:id} | |
| GET | Get all apps | /v1/apps/ | |
| POST | Create an app | /v1/apps/ | |
| PATCH | Update an app | /v1/apps/{int:id} | |
| DELETE | Delete an app | /v1/apps/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class V1::AppsController < ApplicationController | |
| before_action :set_app, only: [:show, :update, :destroy] | |
| # GET /v1/apps | |
| def index | |
| @apps = App.all | |
| render json: @apps | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Rails.application.routes.draw do | |
| # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | |
| root 'application#index', format: 'json' | |
| namespace :v1 do | |
| resource :apps | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App < ApplicationRecord | |
| validates :name, uniqueness: true | |
| validates :token, uniqueness: true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'test_helper' | |
| class AppTest < ActiveSupport::TestCase | |
| # 1 | |
| test "app should save with unqiue name and token" do | |
| app1 = App.new(name: 'Hello World', token: '13456') | |
| app2 = App.new(name: 'Goodbye World', token: 'abcdef') | |
| assert app1.save | |
| assert app2.save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| flake8 --exit-zero --count --max-line-length 120 --exclude=node_modules,.cache,.serverless_plugins,.circleci,.pytest_cache,postman,sls,.serverless |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Given an array of integers, return a new array such that | |
| # each element at index i of the new array is the product of all the | |
| # numbers in the original array except the one at i. | |
| input = [1, 2, 3, 4, 5] | |
| input2 = [3, 2, 1] | |
| def sum_array(input) | |
| total = input.reduce(1, :*) | |
| out = [] |