├── .gitignore ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app ├── channels │ ├── application_cable │ │ ├── channel.rb │ │ └── connection.rb │ └── web_notifications_channel.rb ├── controllers │ ├── application_controller.rb │ ├── avatar_images_controller.rb │ ├── concerns │ │ └── .keep │ ├── follow_suggestions_controller.rb │ ├── locations_controller.rb │ ├── posts │ │ ├── comments_controller.rb │ │ ├── likers_controller.rb │ │ └── likes_controller.rb │ ├── posts_controller.rb │ ├── relationships_controller.rb │ ├── tags │ │ └── posts_controller.rb │ ├── users │ │ ├── facebook_logins_controller.rb │ │ ├── followers_controller.rb │ │ ├── following_controller.rb │ │ ├── notification_counts_controller.rb │ │ ├── notifications_controller.rb │ │ ├── posts_controller.rb │ │ ├── public_profiles_controller.rb │ │ ├── registrations_controller.rb │ │ └── sessions_controller.rb │ └── users_controller.rb ├── jobs │ └── application_job.rb ├── mailers │ └── application_mailer.rb ├── models │ ├── application_record.rb │ ├── comment.rb │ ├── concerns │ │ └── .keep │ ├── like.rb │ ├── notification.rb │ ├── post.rb │ ├── relationship.rb │ ├── tag.rb │ ├── tagging.rb │ └── user.rb ├── serializers │ ├── comment_serializer.rb │ ├── current_user_serializer.rb │ ├── follow_suggestion_serializer.rb │ ├── notification_serializer.rb │ ├── post_serializer.rb │ ├── public_profile_serializer.rb │ └── user_serializer.rb ├── services │ ├── notification │ │ └── broadcaster.rb │ └── post │ │ └── create.rb ├── uploaders │ ├── avatar_uploader.rb │ └── photo_uploader.rb └── views │ └── layouts │ ├── mailer.html.erb │ └── mailer.text.erb ├── bin ├── bundle ├── rails ├── rake ├── setup ├── spring └── update ├── config.ru ├── config ├── application.rb ├── boot.rb ├── cable.yml ├── database.yml ├── environment.rb ├── environments │ ├── development.rb │ ├── production.rb │ └── test.rb ├── initializers │ ├── active_model_serializers.rb │ ├── application_controller_renderer.rb │ ├── backtrace_silencers.rb │ ├── carrierwave.rb │ ├── cors.rb │ ├── filter_parameter_logging.rb │ ├── inflections.rb │ ├── json_param_key_transform.rb │ ├── jwt.rb │ ├── mime_types.rb │ ├── new_framework_defaults.rb │ └── wrap_parameters.rb ├── locales │ └── en.yml ├── puma.rb ├── routes.rb ├── secrets.yml └── spring.rb ├── db ├── migrate │ ├── 20160731021925_create_users.rb │ ├── 20160801002722_add_avatar_to_users.rb │ ├── 20160802161527_create_posts.rb │ ├── 20160803055615_add_filter_to_post.rb │ ├── 20160806142213_add_location_to_posts.rb │ ├── 20160807024815_create_likes.rb │ ├── 20160807025335_add_likes_count_to_posts.rb │ ├── 20160808022245_create_comments.rb │ ├── 20160808022612_add_comments_count_to_posts.rb │ ├── 20160810060730_create_relationships.rb │ ├── 20160816063814_add_place_id_to_posts.rb │ ├── 20160822143951_create_notifications.rb │ ├── 20160902154839_add_facebook_to_users.rb │ ├── 20160908182001_create_tags.rb │ ├── 20160908182022_create_taggings.rb │ └── 20160930221520_add_filter_style_to_posts.rb ├── schema.rb └── seeds.rb ├── lib ├── json_web_token.rb └── tasks │ └── .keep ├── public └── robots.txt └── test ├── controllers ├── .keep ├── avatar_images_controller_test.rb ├── follow_suggestions_controller_test.rb ├── locations_controller_test.rb ├── posts │ ├── comments_controller_test.rb │ └── likes_controller_test.rb ├── posts_controller_test.rb ├── relationships_controller_test.rb ├── tags │ └── posts_controller_test.rb ├── users │ ├── facebook_logins_controller_test.rb │ ├── followers_controller_test.rb │ ├── following_controller_test.rb │ ├── notifications_controller_test.rb │ ├── posts_controller_test.rb │ ├── public_profiles_controller_test.rb │ ├── registrations_controller_test.rb │ ├── sessions_controller_test.rb │ └── unread_notification_counts_controller_test.rb └── users_controller_test.rb ├── fixtures ├── .keep ├── comments.yml ├── files │ └── .keep ├── likes.yml ├── notifications.yml ├── posts.yml ├── relationships.yml ├── taggings.yml ├── tags.yml └── users.yml ├── integration └── .keep ├── mailers └── .keep ├── models ├── .keep ├── comment_test.rb ├── like_test.rb ├── notification_test.rb ├── post_test.rb ├── relationship_test.rb ├── tag_test.rb ├── tagging_test.rb └── user_test.rb └── test_helper.rb /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files. 2 | # 3 | # If you find yourself ignoring temporary files generated by your text editor 4 | # or operating system, you probably want to add a global ignore instead: 5 | # git config --global core.excludesfile '~/.gitignore_global' 6 | 7 | # Ignore bundler config. 8 | /.bundle 9 | 10 | # Ignore all logfiles and tempfiles. 11 | /log/* 12 | /tmp/* 13 | !/log/.keep 14 | !/tmp/.keep 15 | 16 | # Ignore Byebug command history file. 17 | .byebug_history 18 | 19 | # Ignore uploaded images 20 | public/uploads/* 21 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | ruby '2.3.1' 4 | 5 | gem 'rails', '~> 5.0.0' 6 | gem 'pg', '~> 0.18' 7 | gem 'puma', '~> 3.0' 8 | gem 'jwt', '~> 1.5' 9 | gem 'bcrypt', '~> 3.1.7' 10 | gem 'rack-cors' 11 | gem 'active_model_serializers', '~> 0.10.2' 12 | gem 'carrierwave', '~> 0.11.2' 13 | gem 'will_paginate', '~> 3.1' 14 | gem 'redis', '~> 3.0' 15 | 16 | 17 | group :development, :test do 18 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console 19 | gem 'byebug', platform: :mri 20 | gem 'pry-rails', '~> 0.3.4' 21 | end 22 | 23 | group :development do 24 | gem 'listen', '~> 3.0.5' 25 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 26 | gem 'spring' 27 | gem 'spring-watcher-listen', '~> 2.0.0' 28 | end 29 | 30 | # Windows does not include zoneinfo files, so bundle the tzinfo-data gem 31 | gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 32 | 33 | group :production do 34 | gem 'fog', '~> 1.38' 35 | gem 'rails_12factor' 36 | end 37 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (2.3.2) 5 | actioncable (5.0.0) 6 | actionpack (= 5.0.0) 7 | nio4r (~> 1.2) 8 | websocket-driver (~> 0.6.1) 9 | actionmailer (5.0.0) 10 | actionpack (= 5.0.0) 11 | actionview (= 5.0.0) 12 | activejob (= 5.0.0) 13 | mail (~> 2.5, >= 2.5.4) 14 | rails-dom-testing (~> 2.0) 15 | actionpack (5.0.0) 16 | actionview (= 5.0.0) 17 | activesupport (= 5.0.0) 18 | rack (~> 2.0) 19 | rack-test (~> 0.6.3) 20 | rails-dom-testing (~> 2.0) 21 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 22 | actionview (5.0.0) 23 | activesupport (= 5.0.0) 24 | builder (~> 3.1) 25 | erubis (~> 2.7.0) 26 | rails-dom-testing (~> 2.0) 27 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 28 | active_model_serializers (0.10.2) 29 | actionpack (>= 4.1, < 6) 30 | activemodel (>= 4.1, < 6) 31 | jsonapi (~> 0.1.1.beta2) 32 | railties (>= 4.1, < 6) 33 | activejob (5.0.0) 34 | activesupport (= 5.0.0) 35 | globalid (>= 0.3.6) 36 | activemodel (5.0.0) 37 | activesupport (= 5.0.0) 38 | activerecord (5.0.0) 39 | activemodel (= 5.0.0) 40 | activesupport (= 5.0.0) 41 | arel (~> 7.0) 42 | activesupport (5.0.0) 43 | concurrent-ruby (~> 1.0, >= 1.0.2) 44 | i18n (~> 0.7) 45 | minitest (~> 5.1) 46 | tzinfo (~> 1.1) 47 | arel (7.1.1) 48 | bcrypt (3.1.11) 49 | builder (3.2.2) 50 | byebug (9.0.5) 51 | carrierwave (0.11.2) 52 | activemodel (>= 3.2.0) 53 | activesupport (>= 3.2.0) 54 | json (>= 1.7) 55 | mime-types (>= 1.16) 56 | mimemagic (>= 0.3.0) 57 | coderay (1.1.1) 58 | concurrent-ruby (1.0.2) 59 | erubis (2.7.0) 60 | excon (0.50.1) 61 | ffi (1.9.14) 62 | fission (0.5.0) 63 | CFPropertyList (~> 2.2) 64 | fog (1.38.0) 65 | fog-aliyun (>= 0.1.0) 66 | fog-atmos 67 | fog-aws (>= 0.6.0) 68 | fog-brightbox (~> 0.4) 69 | fog-cloudatcost (~> 0.1.0) 70 | fog-core (~> 1.32) 71 | fog-dynect (~> 0.0.2) 72 | fog-ecloud (~> 0.1) 73 | fog-google (<= 0.1.0) 74 | fog-json 75 | fog-local 76 | fog-openstack 77 | fog-powerdns (>= 0.1.1) 78 | fog-profitbricks 79 | fog-rackspace 80 | fog-radosgw (>= 0.0.2) 81 | fog-riakcs 82 | fog-sakuracloud (>= 0.0.4) 83 | fog-serverlove 84 | fog-softlayer 85 | fog-storm_on_demand 86 | fog-terremark 87 | fog-vmfusion 88 | fog-voxel 89 | fog-vsphere (>= 0.4.0) 90 | fog-xenserver 91 | fog-xml (~> 0.1.1) 92 | ipaddress (~> 0.5) 93 | fog-aliyun (0.1.0) 94 | fog-core (~> 1.27) 95 | fog-json (~> 1.0) 96 | ipaddress (~> 0.8) 97 | xml-simple (~> 1.1) 98 | fog-atmos (0.1.0) 99 | fog-core 100 | fog-xml 101 | fog-aws (0.9.4) 102 | fog-core (~> 1.38) 103 | fog-json (~> 1.0) 104 | fog-xml (~> 0.1) 105 | ipaddress (~> 0.8) 106 | fog-brightbox (0.10.1) 107 | fog-core (~> 1.22) 108 | fog-json 109 | inflecto (~> 0.0.2) 110 | fog-cloudatcost (0.1.2) 111 | fog-core (~> 1.36) 112 | fog-json (~> 1.0) 113 | fog-xml (~> 0.1) 114 | ipaddress (~> 0.8) 115 | fog-core (1.41.0) 116 | builder 117 | excon (~> 0.49) 118 | formatador (~> 0.2) 119 | fog-dynect (0.0.3) 120 | fog-core 121 | fog-json 122 | fog-xml 123 | fog-ecloud (0.3.0) 124 | fog-core 125 | fog-xml 126 | fog-google (0.1.0) 127 | fog-core 128 | fog-json 129 | fog-xml 130 | fog-json (1.0.2) 131 | fog-core (~> 1.0) 132 | multi_json (~> 1.10) 133 | fog-local (0.3.0) 134 | fog-core (~> 1.27) 135 | fog-openstack (0.1.7) 136 | fog-core (>= 1.40) 137 | fog-json (>= 1.0) 138 | ipaddress (>= 0.8) 139 | fog-powerdns (0.1.1) 140 | fog-core (~> 1.27) 141 | fog-json (~> 1.0) 142 | fog-xml (~> 0.1) 143 | fog-profitbricks (0.0.5) 144 | fog-core 145 | fog-xml 146 | nokogiri 147 | fog-rackspace (0.1.1) 148 | fog-core (>= 1.35) 149 | fog-json (>= 1.0) 150 | fog-xml (>= 0.1) 151 | ipaddress (>= 0.8) 152 | fog-radosgw (0.0.5) 153 | fog-core (>= 1.21.0) 154 | fog-json 155 | fog-xml (>= 0.0.1) 156 | fog-riakcs (0.1.0) 157 | fog-core 158 | fog-json 159 | fog-xml 160 | fog-sakuracloud (1.7.5) 161 | fog-core 162 | fog-json 163 | fog-serverlove (0.1.2) 164 | fog-core 165 | fog-json 166 | fog-softlayer (1.1.2) 167 | fog-core 168 | fog-json 169 | fog-storm_on_demand (0.1.1) 170 | fog-core 171 | fog-json 172 | fog-terremark (0.1.0) 173 | fog-core 174 | fog-xml 175 | fog-vmfusion (0.1.0) 176 | fission 177 | fog-core 178 | fog-voxel (0.1.0) 179 | fog-core 180 | fog-xml 181 | fog-vsphere (0.8.0) 182 | fog-core 183 | rbvmomi (~> 1.8) 184 | fog-xenserver (0.2.3) 185 | fog-core 186 | fog-xml 187 | fog-xml (0.1.2) 188 | fog-core 189 | nokogiri (~> 1.5, >= 1.5.11) 190 | formatador (0.2.5) 191 | globalid (0.3.7) 192 | activesupport (>= 4.1.0) 193 | i18n (0.7.0) 194 | inflecto (0.0.2) 195 | ipaddress (0.8.3) 196 | json (1.8.3) 197 | jsonapi (0.1.1.beta2) 198 | json (~> 1.8) 199 | jwt (1.5.4) 200 | listen (3.0.8) 201 | rb-fsevent (~> 0.9, >= 0.9.4) 202 | rb-inotify (~> 0.9, >= 0.9.7) 203 | loofah (2.0.3) 204 | nokogiri (>= 1.5.9) 205 | mail (2.6.4) 206 | mime-types (>= 1.16, < 4) 207 | method_source (0.8.2) 208 | mime-types (3.1) 209 | mime-types-data (~> 3.2015) 210 | mime-types-data (3.2016.0521) 211 | mimemagic (0.3.1) 212 | mini_portile2 (2.1.0) 213 | minitest (5.9.0) 214 | multi_json (1.12.1) 215 | nio4r (1.2.1) 216 | nokogiri (1.6.8) 217 | mini_portile2 (~> 2.1.0) 218 | pkg-config (~> 1.1.7) 219 | pg (0.18.4) 220 | pkg-config (1.1.7) 221 | pry (0.10.4) 222 | coderay (~> 1.1.0) 223 | method_source (~> 0.8.1) 224 | slop (~> 3.4) 225 | pry-rails (0.3.4) 226 | pry (>= 0.9.10) 227 | puma (3.6.0) 228 | rack (2.0.1) 229 | rack-cors (0.4.0) 230 | rack-test (0.6.3) 231 | rack (>= 1.0) 232 | rails (5.0.0) 233 | actioncable (= 5.0.0) 234 | actionmailer (= 5.0.0) 235 | actionpack (= 5.0.0) 236 | actionview (= 5.0.0) 237 | activejob (= 5.0.0) 238 | activemodel (= 5.0.0) 239 | activerecord (= 5.0.0) 240 | activesupport (= 5.0.0) 241 | bundler (>= 1.3.0, < 2.0) 242 | railties (= 5.0.0) 243 | sprockets-rails (>= 2.0.0) 244 | rails-dom-testing (2.0.1) 245 | activesupport (>= 4.2.0, < 6.0) 246 | nokogiri (~> 1.6.0) 247 | rails-html-sanitizer (1.0.3) 248 | loofah (~> 2.0) 249 | rails_12factor (0.0.3) 250 | rails_serve_static_assets 251 | rails_stdout_logging 252 | rails_serve_static_assets (0.0.5) 253 | rails_stdout_logging (0.0.5) 254 | railties (5.0.0) 255 | actionpack (= 5.0.0) 256 | activesupport (= 5.0.0) 257 | method_source 258 | rake (>= 0.8.7) 259 | thor (>= 0.18.1, < 2.0) 260 | rake (11.2.2) 261 | rb-fsevent (0.9.7) 262 | rb-inotify (0.9.7) 263 | ffi (>= 0.5.0) 264 | rbvmomi (1.8.2) 265 | builder 266 | nokogiri (>= 1.4.1) 267 | trollop 268 | redis (3.3.1) 269 | slop (3.6.0) 270 | spring (1.7.2) 271 | spring-watcher-listen (2.0.0) 272 | listen (>= 2.7, < 4.0) 273 | spring (~> 1.2) 274 | sprockets (3.7.0) 275 | concurrent-ruby (~> 1.0) 276 | rack (> 1, < 3) 277 | sprockets-rails (3.1.1) 278 | actionpack (>= 4.0) 279 | activesupport (>= 4.0) 280 | sprockets (>= 3.0.0) 281 | thor (0.19.1) 282 | thread_safe (0.3.5) 283 | trollop (2.1.2) 284 | tzinfo (1.2.2) 285 | thread_safe (~> 0.1) 286 | websocket-driver (0.6.4) 287 | websocket-extensions (>= 0.1.0) 288 | websocket-extensions (0.1.2) 289 | will_paginate (3.1.0) 290 | xml-simple (1.1.5) 291 | 292 | PLATFORMS 293 | ruby 294 | 295 | DEPENDENCIES 296 | active_model_serializers (~> 0.10.2) 297 | bcrypt (~> 3.1.7) 298 | byebug 299 | carrierwave (~> 0.11.2) 300 | fog (~> 1.38) 301 | jwt (~> 1.5) 302 | listen (~> 3.0.5) 303 | pg (~> 0.18) 304 | pry-rails (~> 0.3.4) 305 | puma (~> 3.0) 306 | rack-cors 307 | rails (~> 5.0.0) 308 | rails_12factor 309 | redis (~> 3.0) 310 | spring 311 | spring-watcher-listen (~> 2.0.0) 312 | tzinfo-data 313 | will_paginate (~> 3.1) 314 | 315 | RUBY VERSION 316 | ruby 2.3.1p112 317 | 318 | BUNDLED WITH 319 | 1.12.5 320 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hackafy API 2 | 3 | API server for [Hackafy](https://github.com/kenny-hibino/hackafy) (Instagram clone) built with Ruby on Rails 4 | 5 | Demo: [Hosted on Heroku](https://radiant-temple-15197.herokuapp.com/) 6 | 7 | ## Install 8 | 9 | Clone this repository and run PostgreSQL, Redis servers. 10 | Using Redis for ActionCable features. 11 | 12 | After cloning the repository, run 13 | 14 | ``` 15 | bundle install 16 | rails db:setup 17 | rails server -p 5000 18 | ``` 19 | 20 | Client side applications, both [Web](https://github.com/kenny-hibino/hackafy) and [Native](https://github.com/kenny-hibino/hackafy-native) are configured to use `localhost:5000` as an API endpoint 21 | 22 | ## Contribution 23 | 24 | Feedbacks, and issue reports are more than welcome :) 25 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require_relative 'config/application' 5 | 6 | Rails.application.load_tasks 7 | -------------------------------------------------------------------------------- /app/channels/application_cable/channel.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Channel < ActionCable::Channel::Base 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /app/channels/application_cable/connection.rb: -------------------------------------------------------------------------------- 1 | module ApplicationCable 2 | class Connection < ActionCable::Connection::Base 3 | identified_by :current_user 4 | 5 | def connect 6 | self.current_user = find_verified_user 7 | end 8 | 9 | protected 10 | 11 | def find_verified_user 12 | if current_user = User.find_by(id: auth_token[:user_id]) 13 | current_user 14 | else 15 | reject_unauthorized_connection 16 | end 17 | end 18 | 19 | def auth_token 20 | begin 21 | @auth_token ||= JsonWebToken.decode(request.params[:token]) 22 | rescue JWT::VerificationError, JWT::DecodeError 23 | return OpenStruct.new(user_id: nil) 24 | end 25 | end 26 | 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /app/channels/web_notifications_channel.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading. 2 | class WebNotificationsChannel < ApplicationCable::Channel 3 | def subscribed 4 | stream_from "web_notifications_#{current_user.id.to_s}" 5 | end 6 | 7 | def unsubscribed 8 | # Any cleanup needed when channel is unsubscribed 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::API 2 | include ActionController::HttpAuthentication::Token::ControllerMethods 3 | attr_reader :current_user 4 | 5 | def authenticate_user! 6 | authenticate_user_from_token || render_unauthorized 7 | end 8 | 9 | def pagination_dict(object) 10 | { 11 | current_page: object.current_page, 12 | next_page: object.next_page, 13 | prev_page: object.previous_page, 14 | total_pages: object.total_pages, 15 | total_count: object.total_entries 16 | } 17 | end 18 | 19 | protected 20 | 21 | def authenticate_user_from_token 22 | if user_id_in_token? 23 | @current_user ||= User.find_by(id: auth_token[:user_id]) 24 | else 25 | nil 26 | end 27 | end 28 | 29 | def render_unauthorized 30 | self.headers['WWW-Authenticate'] = 'Token realm="Application"' 31 | render json: { errors: ['Bad credentials'] }, status: 401 32 | end 33 | 34 | def user_id_in_token? 35 | http_token && auth_token && auth_token[:user_id] 36 | end 37 | 38 | def http_token 39 | authenticate_with_http_token do |token| 40 | @http_token = token 41 | end 42 | end 43 | 44 | def auth_token 45 | begin 46 | @auth_token ||= JsonWebToken.decode(http_token) 47 | rescue JWT::VerificationError, JWT::DecodeError 48 | return nil 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /app/controllers/avatar_images_controller.rb: -------------------------------------------------------------------------------- 1 | class AvatarImagesController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def update 5 | if current_user.update(avatar: params[:avatar]) 6 | render json: { url: current_user.avatar.url }, status: 200 7 | else 8 | render json: { errors: ['Oops something went wrong. Please try again'] }, status: 422 9 | end 10 | end 11 | end 12 | 13 | -------------------------------------------------------------------------------- /app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /app/controllers/follow_suggestions_controller.rb: -------------------------------------------------------------------------------- 1 | class FollowSuggestionsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | # TODO: find suggestions using graph search 6 | users = User.order(created_at: :desc).limit(10) - [current_user] # <-- this is temporary 7 | render json: users, each_serializer: FollowSuggestionSerializer, status: 200 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /app/controllers/locations_controller.rb: -------------------------------------------------------------------------------- 1 | class LocationsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def show 5 | posts = Post.where(place_id: params[:id]).order(created_at: :desc) 6 | render json: posts,status: 200 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /app/controllers/posts/comments_controller.rb: -------------------------------------------------------------------------------- 1 | class Posts::CommentsController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_post 4 | 5 | def index 6 | comments = @post.comments.latest.paginate(page: params[:page]) 7 | render json: comments, meta: pagination_dict(comments), status: 200 8 | end 9 | 10 | def create 11 | comment = @post.comments.build(comment_params.merge(user_id: current_user.id)) 12 | if comment.save 13 | create_notification 14 | render json: comment, status: 201 15 | else 16 | render json: { errors: comment.errors.full_messages }, status: 422 17 | end 18 | end 19 | 20 | def destroy 21 | comment = current_user.comments.find(params[:id]) 22 | comment.destroy 23 | head 204 24 | end 25 | 26 | private 27 | 28 | def set_post 29 | @post = Post.find(params[:post_id]) 30 | end 31 | 32 | def comment_params 33 | params.permit(:body) 34 | end 35 | 36 | def create_notification 37 | unless current_user.id == @post.user.id 38 | notification = Notification.create!(actor: current_user, recipient: @post.user, 39 | notifiable: @post, action_type: 'COMMENT_ON_POST') 40 | Notification::Broadcaster.new(notification, to: @post.user).broadcast 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /app/controllers/posts/likers_controller.rb: -------------------------------------------------------------------------------- 1 | class Posts::LikersController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_post 4 | 5 | def index 6 | likers = @post.likers.paginate(page: params[:page], per_page: 10) 7 | render json: likers, meta: pagination_dict(likers), status: 200 8 | end 9 | 10 | private 11 | 12 | def set_post 13 | @post = Post.find(params[:post_id]) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/controllers/posts/likes_controller.rb: -------------------------------------------------------------------------------- 1 | class Posts::LikesController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_post 4 | 5 | def create 6 | current_user.like!(@post) 7 | create_notification 8 | head 204 9 | end 10 | 11 | def destroy 12 | current_user.dislike!(@post) 13 | head 204 14 | end 15 | 16 | private 17 | 18 | def set_post 19 | @post = Post.find(params[:post_id]) 20 | end 21 | 22 | def create_notification 23 | unless current_user.id == @post.user.id 24 | notification = Notification.create!(actor: current_user, recipient: @post.user, 25 | notifiable: @post, action_type: 'LIKE_POST') 26 | Notification::Broadcaster.new(notification, to: @post.user).broadcast 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class PostsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | posts = Post.get_page(params[:page]) 6 | render json: posts, meta: pagination_dict(posts), status: 200 7 | end 8 | 9 | def create 10 | post = current_user.posts.build(post_params) 11 | post_builder = Post::Create.new(post) 12 | if post_builder.run 13 | render json: post_builder.post, status: 201 14 | else 15 | render json: { errors: post_builder.post.errors.full_messages }, status: 422 16 | end 17 | end 18 | 19 | private 20 | 21 | def post_params 22 | params.permit(:photo, :caption, :filter, :address, :lat, :lng, :place_id, :filter_style) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/controllers/relationships_controller.rb: -------------------------------------------------------------------------------- 1 | class RelationshipsController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_user 4 | 5 | def create 6 | if current_user.follow(@user) 7 | create_notification 8 | render json: @user, status: 200 9 | else 10 | render json: { errors: ['Could not follow user'] }, status: 422 11 | end 12 | end 13 | 14 | def destroy 15 | if current_user.unfollow(@user) 16 | render json: @user, status: 200 17 | else 18 | render json: { errors: ['Could not unfollow user'] }, status: 422 19 | end 20 | end 21 | 22 | private 23 | 24 | def set_user 25 | @user = User.find(params[:user_id]) 26 | end 27 | 28 | def create_notification 29 | notification = Notification.create!(actor: current_user, recipient: @user, 30 | notifiable: @user, action_type: 'START_FOLLOWING') 31 | Notification::Broadcaster.new(notification, to: @user).broadcast 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /app/controllers/tags/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class Tags::PostsController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_tag 4 | 5 | def index 6 | if @tag.present? 7 | posts = @tag.posts.get_page(params[:page], 9) 8 | render json: posts, meta: pagination_dict(posts), status: 200 9 | else 10 | render json: { errors: ["Tag #{params[:tag_name]} not found"] }, status: 422 11 | end 12 | end 13 | 14 | private 15 | 16 | def set_tag 17 | @tag = Tag.find_by(name: params[:tag_name]) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/controllers/users/facebook_logins_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::FacebookLoginsController < ApplicationController 2 | def create 3 | @user = User.find_by(facebook_id: params[:facebook_id]) if params[:facebook_id].present? 4 | if @user 5 | render json: @user, serializer: CurrentUserSerializer, status: 200 6 | else 7 | @user = User.create!(user_params) 8 | render json: @user, serializer: CurrentUserSerializer, status: 201 9 | end 10 | end 11 | 12 | private 13 | 14 | def user_params 15 | username = generate_unique_username 16 | params.permit(:facebook_id).merge(username: username) 17 | end 18 | 19 | def generate_unique_username 20 | name = params[:username].split.join('-').downcase 21 | loop do 22 | username = "#{name}#{SecureRandom.random_number(1000..9999).to_s}" 23 | break username unless User.exists?(username: username) 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /app/controllers/users/followers_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::FollowersController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_user 4 | 5 | def index 6 | followers = @user.followers.paginate(page: params[:page], per_page: 10) 7 | render json: followers, meta: pagination_dict(followers), status: 200 8 | end 9 | 10 | private 11 | 12 | def set_user 13 | @user = User.find_by(username: params[:username]) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/controllers/users/following_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::FollowingController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_user 4 | 5 | def index 6 | following = @user.following.paginate(page: params[:page], per_page: 10) 7 | render json: following, meta: pagination_dict(following), status: 200 8 | end 9 | 10 | private 11 | 12 | def set_user 13 | @user = User.find_by(username: params[:username]) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/controllers/users/notification_counts_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::NotificationCountsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def show 5 | notification_count = current_user.notifications.pristine.count 6 | render json: { count: notification_count }, status: 200 7 | end 8 | 9 | def destroy 10 | current_user.notifications.update_all(pristine: false) 11 | head 204 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/users/notifications_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::NotificationsController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def index 5 | notifications = current_user.notifications. 6 | order(created_at: :desc). 7 | paginate(page: params[:page], per_page: 20) 8 | render json: notifications, meta: pagination_dict(notifications), status: 200 9 | end 10 | 11 | def update 12 | notification = current_user.notifications.find(params[:id]) 13 | notification.update(read_at: Time.zone.now) 14 | head 204 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /app/controllers/users/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::PostsController < ApplicationController 2 | before_action :authenticate_user! 3 | before_action :set_user 4 | 5 | def index 6 | if @user.present? 7 | posts = @user.posts.get_page(params[:page], 9) 8 | render json: posts, meta: pagination_dict(posts), status: 200 9 | else 10 | render json: { errors: ["User not found"] }, status: 422 11 | end 12 | end 13 | 14 | private 15 | 16 | def set_user 17 | @user = User.find_by(username: params[:username]) 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /app/controllers/users/public_profiles_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::PublicProfilesController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def show 5 | user = User.find_by(username: params[:username]) 6 | if user.present? 7 | render json: user, serializer: PublicProfileSerializer, status: 200 8 | else 9 | render json: { errors: ["User not found"] }, status: 422 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/controllers/users/registrations_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::RegistrationsController < ApplicationController 2 | # POST '/api/users/signup' 3 | # BODY: { 4 | # email: String, 5 | # username: String, 6 | # password: String 7 | # } 8 | def create 9 | user = User.new(user_params) 10 | if user.save 11 | render json: user, serializer: CurrentUserSerializer, status: 201 12 | else 13 | render json: { errors: user.errors.full_messages }, status: 422 14 | end 15 | end 16 | 17 | private 18 | 19 | def user_params 20 | params.permit(:username, :email, :password) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/controllers/users/sessions_controller.rb: -------------------------------------------------------------------------------- 1 | class Users::SessionsController < ApplicationController 2 | def create 3 | if user = User.authenticate(email_or_username, params[:password]) 4 | render json: user, serializer: CurrentUserSerializer, status: 200 5 | else 6 | render json: { errors: ['Invalid email and password'] }, status: 422 7 | end 8 | end 9 | 10 | private 11 | 12 | def email_or_username 13 | params[:email] || params[:username] 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /app/controllers/users_controller.rb: -------------------------------------------------------------------------------- 1 | class UsersController < ApplicationController 2 | before_action :authenticate_user! 3 | 4 | def update 5 | if current_user.update(user_params) 6 | render json: current_user, serializer: CurrentUserSerializer, status: 200 7 | else 8 | render json: { errors: current_user.errors.full_messages }, status: 422 9 | end 10 | end 11 | 12 | private 13 | 14 | def user_params 15 | params.permit(:avatar, :username, :email) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /app/jobs/application_job.rb: -------------------------------------------------------------------------------- 1 | class ApplicationJob < ActiveJob::Base 2 | end 3 | -------------------------------------------------------------------------------- /app/mailers/application_mailer.rb: -------------------------------------------------------------------------------- 1 | class ApplicationMailer < ActionMailer::Base 2 | default from: 'from@example.com' 3 | layout 'mailer' 4 | end 5 | -------------------------------------------------------------------------------- /app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | end 4 | -------------------------------------------------------------------------------- /app/models/comment.rb: -------------------------------------------------------------------------------- 1 | class Comment < ApplicationRecord 2 | belongs_to :post, counter_cache: true 3 | belongs_to :user 4 | 5 | scope :latest, -> { order(created_at: :desc) } 6 | 7 | self.per_page = 5 8 | end 9 | -------------------------------------------------------------------------------- /app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/app/models/concerns/.keep -------------------------------------------------------------------------------- /app/models/like.rb: -------------------------------------------------------------------------------- 1 | class Like < ApplicationRecord 2 | belongs_to :user 3 | belongs_to :post, counter_cache: true 4 | end 5 | -------------------------------------------------------------------------------- /app/models/notification.rb: -------------------------------------------------------------------------------- 1 | class Notification < ApplicationRecord 2 | belongs_to :recipient, class_name: "User" 3 | belongs_to :actor, class_name: "User" 4 | belongs_to :notifiable, polymorphic: true 5 | 6 | scope :unread, -> { where(read_at: nil) } 7 | scope :pristine, -> { where(pristine: true) } 8 | end 9 | -------------------------------------------------------------------------------- /app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ApplicationRecord 2 | belongs_to :user 3 | has_many :likes, dependent: :destroy 4 | has_many :likers, through: :likes, source: :user 5 | has_many :comments, dependent: :destroy 6 | has_many :taggings, dependent: :destroy 7 | has_many :tags, through: :taggings 8 | 9 | validates :user_id, presence: true 10 | validates :photo, presence: true 11 | 12 | mount_uploader :photo, PhotoUploader 13 | 14 | scope :get_page, -> (page, per_page = 10) { 15 | includes(:user, :comments).order(created_at: :desc).paginate(page: page, per_page: per_page) 16 | } 17 | end 18 | -------------------------------------------------------------------------------- /app/models/relationship.rb: -------------------------------------------------------------------------------- 1 | class Relationship < ApplicationRecord 2 | belongs_to :follower, class_name: "User" 3 | belongs_to :followed, class_name: "User" 4 | 5 | validates :follower_id, presence: true 6 | validates :followed_id, presence: true 7 | end 8 | -------------------------------------------------------------------------------- /app/models/tag.rb: -------------------------------------------------------------------------------- 1 | class Tag < ApplicationRecord 2 | has_many :taggings, dependent: :destroy 3 | has_many :posts, through: :taggings 4 | 5 | validates :name, presence: true 6 | end 7 | -------------------------------------------------------------------------------- /app/models/tagging.rb: -------------------------------------------------------------------------------- 1 | class Tagging < ApplicationRecord 2 | belongs_to :post 3 | belongs_to :tag 4 | end 5 | -------------------------------------------------------------------------------- /app/models/user.rb: -------------------------------------------------------------------------------- 1 | class User < ApplicationRecord 2 | has_many :posts, dependent: :destroy 3 | has_many :likes, dependent: :destroy 4 | has_many :liked_posts, through: :likes, source: :post 5 | has_many :comments, dependent: :destroy 6 | has_many :active_relationships, class_name: "Relationship", 7 | foreign_key: "follower_id", 8 | dependent: :destroy 9 | has_many :following, through: :active_relationships, source: :followed 10 | 11 | has_many :passive_relationships, class_name: "Relationship", 12 | foreign_key: "followed_id", 13 | dependent: :destroy 14 | has_many :followers, through: :passive_relationships, source: :follower 15 | 16 | has_many :notifications, dependent: :destroy, foreign_key: :recipient_id 17 | 18 | has_secure_password validations: false 19 | EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i 20 | USERNAME_REGEX = /\A[a-zA-Z0-9_-]{3,30}\z/ 21 | validates :email, presence: true, uniqueness: { case_sensitive: false }, 22 | format: { with: EMAIL_REGEX }, unless: :facebook_login? 23 | validates :username, presence: true, uniqueness: { case_sensitive: false }, 24 | format: { with: USERNAME_REGEX, message: "should be one word" }, unless: :facebook_login? 25 | validates :password, presence: true, length: { minimum: 8 }, unless: :facebook_login? 26 | 27 | mount_uploader :avatar, AvatarUploader 28 | 29 | def self.authenticate(email_or_username, password) 30 | user = User.find_by(email: email_or_username) || User.find_by(username: email_or_username) 31 | user && user.authenticate(password) 32 | end 33 | 34 | def like!(post) 35 | likes.where(post_id: post.id).first_or_create! 36 | end 37 | 38 | def dislike!(post) 39 | likes.where(post_id: post.id).destroy_all 40 | end 41 | 42 | def follow(other_user) 43 | return false if self.id == other_user.id 44 | active_relationships.create(followed_id: other_user.id) 45 | end 46 | 47 | def unfollow(other_user) 48 | active_relationships.find_by(followed_id: other_user.id).destroy 49 | end 50 | 51 | def following?(other_user) 52 | following_ids.include?(other_user.id) 53 | end 54 | 55 | def facebook_login? 56 | facebook_id.present? 57 | end 58 | 59 | def avatar_url 60 | if facebook_login? && avatar.url.nil? 61 | "https://graph.facebook.com/#{facebook_id}/picture?type=large" 62 | else 63 | avatar.url 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /app/serializers/comment_serializer.rb: -------------------------------------------------------------------------------- 1 | class CommentSerializer < ActiveModel::Serializer 2 | attributes :id, :body, :created_at, :user_id, :username 3 | 4 | def username 5 | object.user.username 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/serializers/current_user_serializer.rb: -------------------------------------------------------------------------------- 1 | class CurrentUserSerializer < ActiveModel::Serializer 2 | attributes :id, :created_at, :authentication_token, 3 | :attrs, :post_ids, :liked_post_ids, :following_ids, :follower_ids 4 | 5 | has_many :posts 6 | 7 | def authentication_token 8 | JsonWebToken.encode({ user_id: object.id }) 9 | end 10 | 11 | def attrs 12 | { 13 | email: object.email, 14 | username: object.username, 15 | avatar_url: object.avatar_url 16 | } 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /app/serializers/follow_suggestion_serializer.rb: -------------------------------------------------------------------------------- 1 | class FollowSuggestionSerializer < ActiveModel::Serializer 2 | attributes :id, :username, :posts, :avatar_url 3 | has_many :posts 4 | 5 | def posts 6 | object.posts.order(created_at: :desc).first(3) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /app/serializers/notification_serializer.rb: -------------------------------------------------------------------------------- 1 | class NotificationSerializer < ActiveModel::Serializer 2 | attributes :id, :actor, :action_type, :read_at, :notifiable_id, :notifiable_type, 3 | :photoUrl, :metadata 4 | 5 | def actor 6 | { 7 | 'username' => object.actor.username, 8 | 'id' => object.actor_id, 9 | 'avatarUrl' => object.actor.avatar_url 10 | } 11 | end 12 | 13 | def photoUrl 14 | if object.notifiable_type == 'Post' 15 | object.notifiable.photo.url 16 | end 17 | end 18 | 19 | def metadata 20 | case object.action_type 21 | when 'LIKE_POST' 22 | like_post_meatadata 23 | when 'START_FOLLOWING' 24 | start_following_metadata 25 | when 'COMMENT_ON_POST' 26 | comment_on_post_metadata 27 | end 28 | end 29 | 30 | private 31 | def like_post_meatadata 32 | { 'likesCount' => object.notifiable.reload.likes_count } 33 | end 34 | 35 | def start_following_metadata 36 | { 'followerIds' => object.notifiable.follower_ids } 37 | end 38 | 39 | def comment_on_post_metadata 40 | ActiveModelSerializers::SerializableResource.new(object.notifiable.comments.last) 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /app/serializers/post_serializer.rb: -------------------------------------------------------------------------------- 1 | class PostSerializer < ActiveModel::Serializer 2 | attributes :id, :photo_url, :filter, :caption, :created_at, :user_id, 3 | :lat_lng, :address, :place_id, :likes_count, :comments_count, 4 | :filter_style, :comment_pagination 5 | 6 | belongs_to :user, serializer: UserSerializer 7 | has_many :comments 8 | 9 | def photo_url 10 | object.photo.url 11 | end 12 | 13 | def lat_lng 14 | { lat: object.lat, lng: object.lng } 15 | end 16 | 17 | def filter_style 18 | if object.filter_style.nil? 19 | '' 20 | else 21 | object.filter_style 22 | end 23 | end 24 | 25 | def comments 26 | object.comments.latest.paginate(page: 1) 27 | end 28 | 29 | def comment_pagination 30 | { 31 | 'currentPage' => self.comments.current_page, 32 | 'nextPage' => self.comments.next_page, 33 | 'prevPage' => self.comments.previous_page, 34 | 'totalPages' => self.comments.total_pages, 35 | 'totalCount' => self.comments.total_entries 36 | } 37 | end 38 | 39 | end 40 | -------------------------------------------------------------------------------- /app/serializers/public_profile_serializer.rb: -------------------------------------------------------------------------------- 1 | class PublicProfileSerializer < ActiveModel::Serializer 2 | attributes :id, :created_at, :avatar_url, :username, :followers_count, 3 | :following_count 4 | 5 | def avatar_url 6 | object.avatar_url 7 | end 8 | 9 | def followers_count 10 | object.followers.count 11 | end 12 | 13 | def following_count 14 | object.following.count 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /app/serializers/user_serializer.rb: -------------------------------------------------------------------------------- 1 | class UserSerializer < ActiveModel::Serializer 2 | attributes :id, :username, :avatar_url 3 | 4 | def avatar_url 5 | object.avatar_url 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/services/notification/broadcaster.rb: -------------------------------------------------------------------------------- 1 | class Notification::Broadcaster 2 | def initialize(notification, to:) 3 | @notification = notification 4 | @receiver = to 5 | end 6 | 7 | def broadcast 8 | ActionCable.server.broadcast( 9 | "web_notifications_#{@receiver.id}", 10 | serializable_notification 11 | ) 12 | end 13 | 14 | private 15 | 16 | attr_reader :notification, :receiver 17 | 18 | def serializable_notification 19 | ActiveModelSerializers::SerializableResource.new(notification) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /app/services/post/create.rb: -------------------------------------------------------------------------------- 1 | class Post::Create 2 | attr_reader :post 3 | 4 | def initialize(post) 5 | @post = post 6 | end 7 | 8 | def run 9 | if post.save 10 | create_tags 11 | post 12 | else 13 | false 14 | end 15 | end 16 | 17 | private 18 | 19 | def create_tags 20 | post.tags = post.caption.scan(/#\w+/).map do |tag_name| 21 | Tag.where(name: tag_name[1..-1]).first_or_create 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /app/uploaders/avatar_uploader.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | class AvatarUploader < CarrierWave::Uploader::Base 4 | 5 | # Include RMagick or MiniMagick support: 6 | # include CarrierWave::RMagick 7 | # include CarrierWave::MiniMagick 8 | 9 | if Rails.env.production? 10 | storage :fog 11 | else 12 | storage :file 13 | end 14 | 15 | # Override the directory where uploaded files will be stored. 16 | # This is a sensible default for uploaders that are meant to be mounted: 17 | def store_dir 18 | "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 19 | end 20 | 21 | # Provide a default URL as a default if there hasn't been a file uploaded: 22 | # def default_url 23 | # # For Rails 3.1+ asset pipeline compatibility: 24 | # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 25 | # 26 | # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 27 | # end 28 | 29 | # Process files as they are uploaded: 30 | # process :scale => [200, 300] 31 | # 32 | # def scale(width, height) 33 | # # do something 34 | # end 35 | 36 | # Create different versions of your uploaded files: 37 | # version :thumb do 38 | # process :resize_to_fit => [50, 50] 39 | # end 40 | 41 | # Add a white list of extensions which are allowed to be uploaded. 42 | # For images you might use something like this: 43 | def extension_white_list 44 | %w(jpg jpeg gif png) 45 | end 46 | 47 | # Override the filename of the uploaded files: 48 | # Avoid using model.id or version_name here, see uploader/store.rb for details. 49 | # def filename 50 | # "something.jpg" if original_filename 51 | # end 52 | 53 | end 54 | -------------------------------------------------------------------------------- /app/uploaders/photo_uploader.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | class PhotoUploader < CarrierWave::Uploader::Base 4 | 5 | # Include RMagick or MiniMagick support: 6 | # include CarrierWave::RMagick 7 | # include CarrierWave::MiniMagick 8 | 9 | if Rails.env.production? 10 | storage :fog 11 | else 12 | storage :file 13 | end 14 | 15 | # Override the directory where uploaded files will be stored. 16 | # This is a sensible default for uploaders that are meant to be mounted: 17 | def store_dir 18 | "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 19 | end 20 | 21 | # Provide a default URL as a default if there hasn't been a file uploaded: 22 | # def default_url 23 | # # For Rails 3.1+ asset pipeline compatibility: 24 | # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_')) 25 | # 26 | # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 27 | # end 28 | 29 | # Process files as they are uploaded: 30 | # process :scale => [200, 300] 31 | # 32 | # def scale(width, height) 33 | # # do something 34 | # end 35 | 36 | # Create different versions of your uploaded files: 37 | # version :thumb do 38 | # process :resize_to_fit => [50, 50] 39 | # end 40 | 41 | # Add a white list of extensions which are allowed to be uploaded. 42 | # For images you might use something like this: 43 | def extension_white_list 44 | %w(jpg jpeg gif png) 45 | end 46 | 47 | # Override the filename of the uploaded files: 48 | # Avoid using model.id or version_name here, see uploader/store.rb for details. 49 | # def filename 50 | # "something.jpg" if original_filename 51 | # end 52 | 53 | end 54 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/views/layouts/mailer.text.erb: -------------------------------------------------------------------------------- 1 | <%= yield %> 2 | -------------------------------------------------------------------------------- /bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | APP_PATH = File.expand_path('../config/application', __dir__) 8 | require_relative '../config/boot' 9 | require 'rails/commands' 10 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | begin 3 | load File.expand_path('../spring', __FILE__) 4 | rescue LoadError => e 5 | raise unless e.message.include?('spring') 6 | end 7 | require_relative '../config/boot' 8 | require 'rake' 9 | Rake.application.run 10 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a starting point to setup your application. 15 | # Add necessary setup steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | # puts "\n== Copying sample files ==" 22 | # unless File.exist?('config/database.yml') 23 | # cp 'config/database.yml.sample', 'config/database.yml' 24 | # end 25 | 26 | puts "\n== Preparing database ==" 27 | system! 'bin/rails db:setup' 28 | 29 | puts "\n== Removing old logs and tempfiles ==" 30 | system! 'bin/rails log:clear tmp:clear' 31 | 32 | puts "\n== Restarting application server ==" 33 | system! 'bin/rails restart' 34 | end 35 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast. 4 | # It gets overwritten when you run the `spring binstub` command. 5 | 6 | unless defined?(Spring) 7 | require 'rubygems' 8 | require 'bundler' 9 | 10 | if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m)) 11 | Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) } 12 | gem 'spring', match[1] 13 | require 'spring/binstub' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /bin/update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | require 'fileutils' 4 | include FileUtils 5 | 6 | # path to your application root. 7 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | chdir APP_ROOT do 14 | # This script is a way to update your development environment automatically. 15 | # Add necessary update steps to this file. 16 | 17 | puts '== Installing dependencies ==' 18 | system! 'gem install bundler --conservative' 19 | system('bundle check') || system!('bundle install') 20 | 21 | puts "\n== Updating database ==" 22 | system! 'bin/rails db:migrate' 23 | 24 | puts "\n== Removing old logs and tempfiles ==" 25 | system! 'bin/rails log:clear tmp:clear' 26 | 27 | puts "\n== Restarting application server ==" 28 | system! 'bin/rails restart' 29 | end 30 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative 'config/environment' 4 | 5 | run Rails.application 6 | -------------------------------------------------------------------------------- /config/application.rb: -------------------------------------------------------------------------------- 1 | require_relative 'boot' 2 | 3 | require "rails" 4 | # Pick the frameworks you want: 5 | require "active_model/railtie" 6 | require "active_job/railtie" 7 | require "active_record/railtie" 8 | require "action_controller/railtie" 9 | require "action_mailer/railtie" 10 | require "action_view/railtie" 11 | require "action_cable/engine" 12 | # require "sprockets/railtie" 13 | require "rails/test_unit/railtie" 14 | 15 | # Require the gems listed in Gemfile, including any gems 16 | # you've limited to :test, :development, or :production. 17 | Bundler.require(*Rails.groups) 18 | 19 | module HackafyApi 20 | class Application < Rails::Application 21 | # Settings in config/environments/* take precedence over those specified here. 22 | # Application configuration should go into files in config/initializers 23 | # -- all .rb files in that directory are automatically loaded. 24 | 25 | # Only loads a smaller set of middleware suitable for API only apps. 26 | # Middleware like session, flash, cookies can be added back manually. 27 | # Skip views, helpers and assets when generating a new resource. 28 | config.api_only = true 29 | 30 | config.autoload_paths << "#{Rails.root}/app/services" 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | url: redis://localhost:6379/ 4 | 5 | test: 6 | adapter: async 7 | 8 | production: 9 | adapter: redis 10 | url: redis://redistogo:d903cf95651a8756c394a1c8bb203261@sculpin.redistogo.com:9345/ 11 | -------------------------------------------------------------------------------- /config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.1 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On OS X with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On OS X with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem 'pg' 16 | # 17 | default: &default 18 | adapter: postgresql 19 | encoding: unicode 20 | # For details on connection pooling, see rails configuration guide 21 | # http://guides.rubyonrails.org/configuring.html#database-pooling 22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 23 | 24 | development: 25 | <<: *default 26 | database: hackafy-api_development 27 | 28 | # The specified database role being used to connect to postgres. 29 | # To create additional roles in postgres see `$ createuser --help`. 30 | # When left blank, postgres will use the default role. This is 31 | # the same name as the operating system user that initialized the database. 32 | #username: hackafy-api 33 | 34 | # The password associated with the postgres role (username). 35 | #password: 36 | 37 | # Connect on a TCP socket. Omitted by default since the client uses a 38 | # domain socket that doesn't need configuration. Windows does not have 39 | # domain sockets, so uncomment these lines. 40 | #host: localhost 41 | 42 | # The TCP port the server listens on. Defaults to 5432. 43 | # If your server runs on a different port number, change accordingly. 44 | #port: 5432 45 | 46 | # Schema search path. The server defaults to $user,public 47 | #schema_search_path: myapp,sharedapp,public 48 | 49 | # Minimum log levels, in increasing order: 50 | # debug5, debug4, debug3, debug2, debug1, 51 | # log, notice, warning, error, fatal, and panic 52 | # Defaults to warning. 53 | #min_messages: notice 54 | 55 | # Warning: The database defined as "test" will be erased and 56 | # re-generated from your development database when you run "rake". 57 | # Do not set this db to the same as development or production. 58 | test: 59 | <<: *default 60 | database: hackafy-api_test 61 | 62 | # As with config/secrets.yml, you never want to store sensitive information, 63 | # like your database password, in your source code. If your source code is 64 | # ever seen by anyone, they now have access to your database. 65 | # 66 | # Instead, provide the password as a unix environment variable when you boot 67 | # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database 68 | # for a full rundown on how to provide these environment variables in a 69 | # production deployment. 70 | # 71 | # On Heroku and other platform providers, you may have a full connection URL 72 | # available as an environment variable. For example: 73 | # 74 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 75 | # 76 | # You can use this database configuration with: 77 | # 78 | # production: 79 | # url: <%= ENV['DATABASE_URL'] %> 80 | # 81 | production: 82 | <<: *default 83 | database: hackafy-api_production 84 | username: hackafy-api 85 | password: <%= ENV['HACKAFY-API_DATABASE_PASSWORD'] %> 86 | -------------------------------------------------------------------------------- /config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative 'application' 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports. 13 | config.consider_all_requests_local = true 14 | 15 | # Enable/disable caching. By default caching is disabled. 16 | if Rails.root.join('tmp/caching-dev.txt').exist? 17 | config.action_controller.perform_caching = true 18 | 19 | config.cache_store = :memory_store 20 | config.public_file_server.headers = { 21 | 'Cache-Control' => 'public, max-age=172800' 22 | } 23 | else 24 | config.action_controller.perform_caching = false 25 | 26 | config.cache_store = :null_store 27 | end 28 | 29 | # Don't care if the mailer can't send. 30 | config.action_mailer.raise_delivery_errors = false 31 | 32 | config.action_mailer.perform_caching = false 33 | 34 | # Print deprecation notices to the Rails logger. 35 | config.active_support.deprecation = :log 36 | 37 | # Raise an error on page load if there are pending migrations. 38 | config.active_record.migration_error = :page_load 39 | 40 | 41 | # Raises error for missing translations 42 | # config.action_view.raise_on_missing_translations = true 43 | 44 | # Use an evented file watcher to asynchronously detect changes in source code, 45 | # routes, locales, etc. This feature depends on the listen gem. 46 | config.file_watcher = ActiveSupport::EventedFileUpdateChecker 47 | end 48 | -------------------------------------------------------------------------------- /config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Disable serving static files from the `/public` folder by default since 18 | # Apache or NGINX already handles this. 19 | config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 20 | 21 | 22 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 23 | # config.action_controller.asset_host = 'http://assets.example.com' 24 | 25 | # Specifies the header that your server uses for sending files. 26 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 27 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 28 | 29 | # Mount Action Cable outside main process or domain 30 | # config.action_cable.mount_path = '/api/cable' 31 | config.action_cable.url = 'wss://enigmatic-mountain-38641.herokuapp.com/api/cable' 32 | config.action_cable.allowed_request_origins = [ 'https://radiant-temple-15197.herokuapp.com', 'http://radiant-temple-15197.herokuapp.com' ] 33 | 34 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 35 | # config.force_ssl = true 36 | 37 | # Use the lowest log level to ensure availability of diagnostic information 38 | # when problems arise. 39 | config.log_level = :debug 40 | 41 | # Prepend all log lines with the following tags. 42 | config.log_tags = [ :request_id ] 43 | 44 | # Use a different cache store in production. 45 | # config.cache_store = :mem_cache_store 46 | 47 | # Use a real queuing backend for Active Job (and separate queues per environment) 48 | # config.active_job.queue_adapter = :resque 49 | # config.active_job.queue_name_prefix = "hackafy-api_#{Rails.env}" 50 | config.action_mailer.perform_caching = false 51 | 52 | # Ignore bad email addresses and do not raise email delivery errors. 53 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 54 | # config.action_mailer.raise_delivery_errors = false 55 | 56 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 57 | # the I18n.default_locale when a translation cannot be found). 58 | config.i18n.fallbacks = true 59 | 60 | # Send deprecation notices to registered listeners. 61 | config.active_support.deprecation = :notify 62 | 63 | # Use default logging formatter so that PID and timestamp are not suppressed. 64 | config.log_formatter = ::Logger::Formatter.new 65 | 66 | # Use a different logger for distributed setups. 67 | # require 'syslog/logger' 68 | # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 69 | 70 | if ENV["RAILS_LOG_TO_STDOUT"].present? 71 | logger = ActiveSupport::Logger.new(STDOUT) 72 | logger.formatter = config.log_formatter 73 | config.logger = ActiveSupport::TaggedLogging.new(logger) 74 | end 75 | 76 | # Do not dump schema after migrations. 77 | config.active_record.dump_schema_after_migration = false 78 | end 79 | -------------------------------------------------------------------------------- /config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure public file server for tests with Cache-Control for performance. 16 | config.public_file_server.enabled = true 17 | config.public_file_server.headers = { 18 | 'Cache-Control' => 'public, max-age=3600' 19 | } 20 | 21 | # Show full error reports and disable caching. 22 | config.consider_all_requests_local = true 23 | config.action_controller.perform_caching = false 24 | 25 | # Raise exceptions instead of rendering exception templates. 26 | config.action_dispatch.show_exceptions = false 27 | 28 | # Disable request forgery protection in test environment. 29 | config.action_controller.allow_forgery_protection = false 30 | config.action_mailer.perform_caching = false 31 | 32 | # Tell Action Mailer not to deliver emails to the real world. 33 | # The :test delivery method accumulates sent emails in the 34 | # ActionMailer::Base.deliveries array. 35 | config.action_mailer.delivery_method = :test 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /config/initializers/active_model_serializers.rb: -------------------------------------------------------------------------------- 1 | # Response document will have a root key 2 | ActiveModelSerializers.config.adapter = :json 3 | 4 | # JSON response will have camelCased keys 5 | ActiveModelSerializers.config.key_transform = :camel_lower 6 | 7 | -------------------------------------------------------------------------------- /config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ApplicationController.renderer.defaults.merge!( 4 | # http_host: 'example.org', 5 | # https: false 6 | # ) 7 | -------------------------------------------------------------------------------- /config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /config/initializers/carrierwave.rb: -------------------------------------------------------------------------------- 1 | require 'carrierwave/orm/activerecord' 2 | 3 | if Rails.env.production? 4 | CarrierWave.configure do |config| 5 | config.fog_credentials = { 6 | :provider => 'AWS', 7 | :aws_access_key_id => ENV['S3_ACCESS_KEY'], 8 | :aws_secret_access_key => ENV['S3_SECRET_KEY'], 9 | :region => ENV['S3_REGION'] 10 | } 11 | config.fog_directory = ENV['S3_BUCKET'] 12 | end 13 | end 14 | 15 | -------------------------------------------------------------------------------- /config/initializers/cors.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Avoid CORS issues when API is called from the frontend app. 4 | # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. 5 | 6 | # Read more: https://github.com/cyu/rack-cors 7 | 8 | Rails.application.config.middleware.insert_before 0, Rack::Cors do 9 | allow do 10 | origins '*' 11 | 12 | resource '*', 13 | headers: :any, 14 | methods: [:get, :post, :put, :patch, :delete, :options, :head] 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /config/initializers/json_param_key_transform.rb: -------------------------------------------------------------------------------- 1 | # Transform JSON request param keys from JSON-conventional camelCase to 2 | # Rails-conventional snake_case: 3 | ActionDispatch::Request.parameter_parsers[:json] = -> (raw_post) { 4 | # Modified from action_dispatch/http/parameters.rb 5 | data = ActiveSupport::JSON.decode(raw_post) 6 | data = {:_json => data} unless data.is_a?(Hash) 7 | 8 | # Transform camelCase param keys to snake_case: 9 | data.deep_transform_keys!(&:underscore) 10 | } 11 | -------------------------------------------------------------------------------- /config/initializers/jwt.rb: -------------------------------------------------------------------------------- 1 | require 'json_web_token' 2 | 3 | -------------------------------------------------------------------------------- /config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /config/initializers/new_framework_defaults.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | # 3 | # This file contains migration options to ease your Rails 5.0 upgrade. 4 | # 5 | # Read the Rails 5.0 release notes for more info on each option. 6 | 7 | # Make Ruby 2.4 preserve the timezone of the receiver when calling `to_time`. 8 | # Previous versions had false. 9 | ActiveSupport.to_time_preserves_timezone = true 10 | 11 | # Require `belongs_to` associations by default. Previous versions had false. 12 | Rails.application.config.active_record.belongs_to_required_by_default = true 13 | 14 | # Do not halt callback chains when a callback returns false. Previous versions had true. 15 | ActiveSupport.halt_callback_chains_on_return_false = false 16 | 17 | # Configure SSL options to enable HSTS with subdomains. Previous versions had false. 18 | Rails.application.config.ssl_options = { hsts: { subdomains: true } } 19 | -------------------------------------------------------------------------------- /config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /config/puma.rb: -------------------------------------------------------------------------------- 1 | # Puma can serve each request in a thread from an internal thread pool. 2 | # The `threads` method setting takes two numbers a minimum and maximum. 3 | # Any libraries that use thread pools should be configured to match 4 | # the maximum value specified for Puma. Default is set to 5 threads for minimum 5 | # and maximum, this matches the default thread size of Active Record. 6 | # 7 | threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i 8 | threads threads_count, threads_count 9 | 10 | # Specifies the `port` that Puma will listen on to receive requests, default is 3000. 11 | # 12 | port ENV.fetch("PORT") { 3000 } 13 | 14 | # Specifies the `environment` that Puma will run in. 15 | # 16 | environment ENV.fetch("RAILS_ENV") { "development" } 17 | 18 | # Specifies the number of `workers` to boot in clustered mode. 19 | # Workers are forked webserver processes. If using threads and workers together 20 | # the concurrency of the application would be max `threads` * `workers`. 21 | # Workers do not work on JRuby or Windows (both of which do not support 22 | # processes). 23 | # 24 | # workers ENV.fetch("WEB_CONCURRENCY") { 2 } 25 | 26 | # Use the `preload_app!` method when specifying a `workers` number. 27 | # This directive tells Puma to first boot the application and load code 28 | # before forking the application. This takes advantage of Copy On Write 29 | # process behavior so workers use less memory. If you use this option 30 | # you need to make sure to reconnect any threads in the `on_worker_boot` 31 | # block. 32 | # 33 | # preload_app! 34 | 35 | # The code in the `on_worker_boot` will be called if you are using 36 | # clustered mode by specifying a number of `workers`. After each worker 37 | # process is booted this block will be run, if you are using `preload_app!` 38 | # option you will want to use this block to reconnect to any threads 39 | # or connections that may have been created at application boot, Ruby 40 | # cannot share connections between processes. 41 | # 42 | # on_worker_boot do 43 | # ActiveRecord::Base.establish_connection if defined?(ActiveRecord) 44 | # end 45 | 46 | # Allow puma to be restarted by `rails restart` command. 47 | plugin :tmp_restart 48 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | scope '/api' do 3 | namespace :users do 4 | resources :notifications, only: [:index, :update] 5 | resource :notification_counts, only: [:show, :destroy] 6 | post 'signup' => 'registrations#create' 7 | post 'signin' => 'sessions#create' 8 | post 'facebook/login' => 'facebook_logins#create' 9 | get ':username/posts' => 'posts#index' 10 | get ':username/public_profile' => 'public_profiles#show' 11 | get ':username/followers' => 'followers#index' 12 | get ':username/following' => 'following#index' 13 | end 14 | 15 | patch 'me/avatar' => 'avatar_images#update' 16 | patch 'me' => 'users#update' 17 | 18 | post 'follow/:user_id' => 'relationships#create' 19 | delete 'unfollow/:user_id' => 'relationships#destroy' 20 | 21 | get 'posts/tags/:tag_name' => 'tags/posts#index' 22 | 23 | resources :posts, only: [:index, :create] do 24 | resource :likes, only: [:create, :destroy], module: :posts 25 | resources :comments, only: [:index, :create, :destroy], module: :posts 26 | resources :likers, only: [:index], module: :posts 27 | end 28 | 29 | resources :locations, only: [:show] 30 | 31 | resources :follow_suggestions, only: [:index] 32 | 33 | mount ActionCable.server => '/cable' 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rails secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: b9727e992215566a7428c5c3e35522d499bd4302cfcc41e7f5f0706b1c3731052b1ec98dbdd16b8fd00af5b2e22e833e87c539a1dbc9630de942cd6fb6de4580 15 | 16 | test: 17 | secret_key_base: 4f339d90e6401d060a0fb11c410a34dbd6461a0a12e4c424353ca41298941c242260522dc007dcd3a1267fb2fe1c27dcf60b88a879596ac456b3e797b31dcd14 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /config/spring.rb: -------------------------------------------------------------------------------- 1 | %w( 2 | .ruby-version 3 | .rbenv-vars 4 | tmp/restart.txt 5 | tmp/caching-dev.txt 6 | ).each { |path| Spring.watch(path) } 7 | -------------------------------------------------------------------------------- /db/migrate/20160731021925_create_users.rb: -------------------------------------------------------------------------------- 1 | class CreateUsers < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :users do |t| 4 | t.string :username 5 | t.string :email 6 | t.string :password_digest 7 | 8 | t.timestamps 9 | end 10 | add_index :users, :username, unique: true 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20160801002722_add_avatar_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddAvatarToUsers < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :users, :avatar, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160802161527_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :posts do |t| 4 | t.string :photo 5 | t.text :caption 6 | t.references :user, foreign_key: true 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160803055615_add_filter_to_post.rb: -------------------------------------------------------------------------------- 1 | class AddFilterToPost < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :posts, :filter, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160806142213_add_location_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddLocationToPosts < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :posts, :address, :string 4 | add_column :posts, :lat, :float 5 | add_column :posts, :lng, :float 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /db/migrate/20160807024815_create_likes.rb: -------------------------------------------------------------------------------- 1 | class CreateLikes < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :likes do |t| 4 | t.references :user, foreign_key: true 5 | t.references :post, foreign_key: true 6 | 7 | t.timestamps 8 | end 9 | add_index :likes, [:user_id, :post_id], unique: true 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160807025335_add_likes_count_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddLikesCountToPosts < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :posts, :likes_count, :integer, default: 0 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160808022245_create_comments.rb: -------------------------------------------------------------------------------- 1 | class CreateComments < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :comments do |t| 4 | t.references :post, foreign_key: true 5 | t.references :user, foreign_key: true 6 | t.text :body 7 | 8 | t.timestamps 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /db/migrate/20160808022612_add_comments_count_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddCommentsCountToPosts < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :posts, :comments_count, :integer, default: 0 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/migrate/20160810060730_create_relationships.rb: -------------------------------------------------------------------------------- 1 | class CreateRelationships < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :relationships do |t| 4 | t.integer :follower_id 5 | t.integer :followed_id 6 | 7 | t.timestamps 8 | end 9 | add_index :relationships, :followed_id 10 | add_index :relationships, :follower_id 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /db/migrate/20160816063814_add_place_id_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddPlaceIdToPosts < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :posts, :place_id, :string 4 | add_index :posts, :place_id 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160822143951_create_notifications.rb: -------------------------------------------------------------------------------- 1 | class CreateNotifications < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :notifications do |t| 4 | t.integer :actor_id 5 | t.integer :recipient_id 6 | t.datetime :read_at 7 | t.integer :notifiable_id 8 | t.string :notifiable_type 9 | t.boolean :pristine, default: true 10 | t.string :action_type 11 | 12 | t.timestamps 13 | end 14 | 15 | add_index :notifications, :recipient_id 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /db/migrate/20160902154839_add_facebook_to_users.rb: -------------------------------------------------------------------------------- 1 | class AddFacebookToUsers < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :users, :facebook_id, :integer, limit: 8 4 | add_index :users, :facebook_id 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /db/migrate/20160908182001_create_tags.rb: -------------------------------------------------------------------------------- 1 | class CreateTags < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :tags do |t| 4 | t.string :name 5 | 6 | t.timestamps 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20160908182022_create_taggings.rb: -------------------------------------------------------------------------------- 1 | class CreateTaggings < ActiveRecord::Migration[5.0] 2 | def change 3 | create_table :taggings do |t| 4 | t.references :post, foreign_key: true 5 | t.references :tag, foreign_key: true 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /db/migrate/20160930221520_add_filter_style_to_posts.rb: -------------------------------------------------------------------------------- 1 | class AddFilterStyleToPosts < ActiveRecord::Migration[5.0] 2 | def change 3 | add_column :posts, :filter_style, :json 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # Note that this schema.rb definition is the authoritative source for your 6 | # database schema. If you need to create the application database on another 7 | # system, you should be using db:schema:load, not running all the migrations 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 20160930221520) do 14 | 15 | # These are extensions that must be enabled in order to support this database 16 | enable_extension "plpgsql" 17 | 18 | create_table "comments", force: :cascade do |t| 19 | t.integer "post_id" 20 | t.integer "user_id" 21 | t.text "body" 22 | t.datetime "created_at", null: false 23 | t.datetime "updated_at", null: false 24 | t.index ["post_id"], name: "index_comments_on_post_id", using: :btree 25 | t.index ["user_id"], name: "index_comments_on_user_id", using: :btree 26 | end 27 | 28 | create_table "likes", force: :cascade do |t| 29 | t.integer "user_id" 30 | t.integer "post_id" 31 | t.datetime "created_at", null: false 32 | t.datetime "updated_at", null: false 33 | t.index ["post_id"], name: "index_likes_on_post_id", using: :btree 34 | t.index ["user_id", "post_id"], name: "index_likes_on_user_id_and_post_id", unique: true, using: :btree 35 | t.index ["user_id"], name: "index_likes_on_user_id", using: :btree 36 | end 37 | 38 | create_table "notifications", force: :cascade do |t| 39 | t.integer "actor_id" 40 | t.integer "recipient_id" 41 | t.datetime "read_at" 42 | t.integer "notifiable_id" 43 | t.string "notifiable_type" 44 | t.boolean "pristine", default: true 45 | t.string "action_type" 46 | t.datetime "created_at", null: false 47 | t.datetime "updated_at", null: false 48 | t.index ["recipient_id"], name: "index_notifications_on_recipient_id", using: :btree 49 | end 50 | 51 | create_table "posts", force: :cascade do |t| 52 | t.string "photo" 53 | t.text "caption" 54 | t.integer "user_id" 55 | t.datetime "created_at", null: false 56 | t.datetime "updated_at", null: false 57 | t.string "filter" 58 | t.string "address" 59 | t.float "lat" 60 | t.float "lng" 61 | t.integer "likes_count", default: 0 62 | t.integer "comments_count", default: 0 63 | t.string "place_id" 64 | t.json "filter_style" 65 | t.index ["place_id"], name: "index_posts_on_place_id", using: :btree 66 | t.index ["user_id"], name: "index_posts_on_user_id", using: :btree 67 | end 68 | 69 | create_table "relationships", force: :cascade do |t| 70 | t.integer "follower_id" 71 | t.integer "followed_id" 72 | t.datetime "created_at", null: false 73 | t.datetime "updated_at", null: false 74 | t.index ["followed_id"], name: "index_relationships_on_followed_id", using: :btree 75 | t.index ["follower_id"], name: "index_relationships_on_follower_id", using: :btree 76 | end 77 | 78 | create_table "taggings", force: :cascade do |t| 79 | t.integer "post_id" 80 | t.integer "tag_id" 81 | t.datetime "created_at", null: false 82 | t.datetime "updated_at", null: false 83 | t.index ["post_id"], name: "index_taggings_on_post_id", using: :btree 84 | t.index ["tag_id"], name: "index_taggings_on_tag_id", using: :btree 85 | end 86 | 87 | create_table "tags", force: :cascade do |t| 88 | t.string "name" 89 | t.datetime "created_at", null: false 90 | t.datetime "updated_at", null: false 91 | end 92 | 93 | create_table "users", force: :cascade do |t| 94 | t.string "username" 95 | t.string "email" 96 | t.string "password_digest" 97 | t.datetime "created_at", null: false 98 | t.datetime "updated_at", null: false 99 | t.string "avatar" 100 | t.bigint "facebook_id" 101 | t.index ["facebook_id"], name: "index_users_on_facebook_id", using: :btree 102 | t.index ["username"], name: "index_users_on_username", unique: true, using: :btree 103 | end 104 | 105 | add_foreign_key "comments", "posts" 106 | add_foreign_key "comments", "users" 107 | add_foreign_key "likes", "posts" 108 | add_foreign_key "likes", "users" 109 | add_foreign_key "posts", "users" 110 | add_foreign_key "taggings", "posts" 111 | add_foreign_key "taggings", "tags" 112 | end 113 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) 7 | # Character.create(name: 'Luke', movie: movies.first) 8 | -------------------------------------------------------------------------------- /lib/json_web_token.rb: -------------------------------------------------------------------------------- 1 | class JsonWebToken 2 | def self.encode(payload) 3 | JWT.encode(payload, Rails.application.secrets.secret_key_base) 4 | end 5 | 6 | def self.decode(token) 7 | begin 8 | HashWithIndifferentAccess.new(JWT.decode(token, Rails.application.secrets.secret_key_base).first) 9 | rescue 10 | nil 11 | end 12 | end 13 | end 14 | 15 | -------------------------------------------------------------------------------- /lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/lib/tasks/.keep -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/test/controllers/.keep -------------------------------------------------------------------------------- /test/controllers/avatar_images_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class AvatarImagesControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/follow_suggestions_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class FollowSuggestionsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/locations_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LocationsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/posts/comments_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Posts::CommentsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/posts/likes_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Posts::LikesControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/posts_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PostsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/relationships_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class RelationshipsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/tags/posts_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Tags::PostsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/facebook_logins_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::FacebookLoginsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/followers_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::FollowersControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/following_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::FollowingControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/notifications_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::NotificationsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/posts_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::PostsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/public_profiles_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::PublicProfilesControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/registrations_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::RegistrationsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/sessions_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::SessionsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users/unread_notification_counts_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class Users::UnreadNotificationCountsControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/controllers/users_controller_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class UsersControllerTest < ActionDispatch::IntegrationTest 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/fixtures/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/test/fixtures/.keep -------------------------------------------------------------------------------- /test/fixtures/comments.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | post: one 5 | user: one 6 | body: MyText 7 | 8 | two: 9 | post: two 10 | user: two 11 | body: MyText 12 | -------------------------------------------------------------------------------- /test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/test/fixtures/files/.keep -------------------------------------------------------------------------------- /test/fixtures/likes.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | user: one 5 | post: one 6 | 7 | two: 8 | user: two 9 | post: two 10 | -------------------------------------------------------------------------------- /test/fixtures/notifications.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | actor: one 5 | recipient: one 6 | readt_at: 2016-08-22 07:39:51 7 | notifiable_id: 1 8 | notifiable_type: MyString 9 | pristine: false 10 | 11 | two: 12 | actor: two 13 | recipient: two 14 | readt_at: 2016-08-22 07:39:51 15 | notifiable_id: 1 16 | notifiable_type: MyString 17 | pristine: false 18 | -------------------------------------------------------------------------------- /test/fixtures/posts.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | photo: MyString 5 | caption: MyText 6 | user: one 7 | 8 | two: 9 | photo: MyString 10 | caption: MyText 11 | user: two 12 | -------------------------------------------------------------------------------- /test/fixtures/relationships.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | follower_id: 1 5 | followed_id: 1 6 | 7 | two: 8 | follower_id: 1 9 | followed_id: 1 10 | -------------------------------------------------------------------------------- /test/fixtures/taggings.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | post: one 5 | tag: one 6 | 7 | two: 8 | post: two 9 | tag: two 10 | -------------------------------------------------------------------------------- /test/fixtures/tags.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | name: MyString 5 | 6 | two: 7 | name: MyString 8 | -------------------------------------------------------------------------------- /test/fixtures/users.yml: -------------------------------------------------------------------------------- 1 | # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html 2 | 3 | one: 4 | username: MyString 5 | email: MyString 6 | password_digest: MyString 7 | 8 | two: 9 | username: MyString 10 | email: MyString 11 | password_digest: MyString 12 | -------------------------------------------------------------------------------- /test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/test/integration/.keep -------------------------------------------------------------------------------- /test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/test/mailers/.keep -------------------------------------------------------------------------------- /test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hibiken/hackafy-api/48a6bfaa0d1ac62741b138a07abfcc1d0a411b88/test/models/.keep -------------------------------------------------------------------------------- /test/models/comment_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class CommentTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/like_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class LikeTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/notification_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class NotificationTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/post_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class PostTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/relationship_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class RelationshipTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/tag_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TagTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/tagging_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class TaggingTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/models/user_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class UserTest < ActiveSupport::TestCase 4 | # test "the truth" do 5 | # assert true 6 | # end 7 | end 8 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. 7 | fixtures :all 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | --------------------------------------------------------------------------------