Skip to content

QultureRocks/qr-challenge-api

Repository files navigation

Qulture.Rocks challenge API

This API is intended to help people doing the frontend challenge. It creates a simple database with enough endpoints to do every required task.

About

This API offers you 2 models that you can use in your application. Every field is updatable (except the timestamps generated by the server) via a PUT request to the API.

User

String name          (required)
String email         (required)
String job_title     (required)
Date admission_date  (required)
String photo_url     (required)
Timestamp created_at (generated by the server)
Timestamp updated_at (generated by the server)

Comment

Int user_id          (required, foreign_key)
String value         (required)
Timestamp created_at (generated by the server)
Timestamp updated_at (generated by the server)

The user_id field points to an existing user in which the comment was made.

Running locally

If you don't want to use the API hosted on heroku, you can run it by yourself:

Installing dependencies

Linux

  1. Install RVM (\curl -sSL https://get.rvm.io | bash -s stable)
  2. cd to the QultureApp folder, RVM will install the right Ruby version automatic
  3. Install gem bundler (gem install bundler , in the QultureApp folder)
  4. Run bundler (bundle install)
  • There might be an issue with pg, to correct that run sudo apt-get install libpq-dev and bundle install again)
  1. Install Postgrsql-10.1, if there is some problems:
  • Install Postgrsql 10.1
  • Run /etc/init.d/postgresql stop to ensure that you don't have postgresql running at the moment
  • Run sudo apt-get update
  • Run sudo apt-get install postgresql-10.1
  • Run sudo apt-get upgrade

MacOS

  1. Install RVM (\curl -sSL https://get.rvm.io | bash -s stable)
  2. Run rvm scripts (source /Users/{YOUR_USER_HERE}/.rvm/scripts/rvm)
  • In my case source /Users/qulturerocks/.rvm/scripts/rvm
  1. Install Brew (/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)")
  2. Go to folder cd QultureApp
  • Install Ruby if not automatic: rvm install ruby-2.5.3
  1. Install postgresql (brew install postgresql)
  • Run /etc/init.d/postgresql stop to ensure that you don't have postgresql running at the moment
  • Start postgresql with pg_ctl -D /usr/local/var/postgres start
  1. Install bundler (gem install bundler)
  • If it cannot find bundler try gem install bundler --source http://rubygems.org
  1. Run bundler (bundle install)

Configuring database

  1. Create a super user with the same name of the computer account (sudo -u postgres createuser --interactive)
  2. Run rake db:create
  3. Run rake db:migrate
  4. Run rake db:seed

Running the api

Run rails s (this will run the server on port 3000)

Routes

You can always run rails routes to see all the routes, but here they are:

User

GET    /api/v1/users                     api/v1/users#index
POST   /api/v1/users                     api/v1/users#create
GET    /api/v1/users/:id                 api/v1/users#show
PATCH  /api/v1/users/:id                 api/v1/users#update
PUT    /api/v1/users/:id                 api/v1/users#update
DELETE /api/v1/users/:id                 api/v1/users#destroy

Comments

GET    /api/v1/users/:user_id/comments   api/v1/comments#index
POST   /api/v1/comments                  api/v1/comments#create
GET    /api/v1/comments/:id              api/v1/comments#show
PATCH  /api/v1/comments/:id              api/v1/comments#update
PUT    /api/v1/comments/:id              api/v1/comments#update
DELETE /api/v1/comments/:id              api/v1/comments#destroy

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •