Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhamiid committed Jan 12, 2024
1 parent 9b472d8 commit 3ef18a8
Show file tree
Hide file tree
Showing 68 changed files with 192 additions and 95 deletions.
32 changes: 0 additions & 32 deletions .stylelintrc

This file was deleted.

4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down Expand Up @@ -89,6 +91,6 @@ group :test do
gem 'webdrivers'
end

gem "sassc-rails"
gem 'sassc-rails'

gem 'active_model_serializers', '~> 0.10.13'
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v1/authentication_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Api
module V1
class AuthenticationController < ApiController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v1/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Api
module V1
class CommentsController < AuthenticationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v1/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Api
module V1
class PostsController < AuthenticationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Api
module V1
class UsersController < AuthenticationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApiController < ActionController::API
include ActionController::HttpAuthentication::Token::ControllerMethods
def authorize_request
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
before_action :authenticate_user!

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CommentsController < ApplicationController
def index
@user = User.includes(posts: [:comments]).find(params[:user_id])
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class LikesController < ApplicationController
def new; end

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PostsController < ApplicationController
def index
@user = User.find(params[:user_id].to_i)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class UsersController < ApplicationController
def index
@users = User.all
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
2 changes: 2 additions & 0 deletions app/helpers/posts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module PostsHelper
end
2 changes: 2 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module UsersHelper
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
Expand Down
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
Expand Down
2 changes: 2 additions & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Ability
include CanCan::Ability

Expand Down
2 changes: 2 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
2 changes: 2 additions & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Comment < ApplicationRecord
belongs_to :author, class_name: 'User'
belongs_to :post
Expand Down
2 changes: 2 additions & 0 deletions app/models/like.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Like < ApplicationRecord
belongs_to :author, class_name: 'User'
belongs_to :post
Expand Down
2 changes: 2 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Post < ApplicationRecord
belongs_to :author, class_name: 'User'
has_many :likes, dependent: :destroy
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class User < ApplicationRecord
ROLES = %w[user admin].freeze

Expand Down
2 changes: 2 additions & 0 deletions app/serializers/comment_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CommentSerializer < ActiveModel::Serializer
attributes :id, :text
end
2 changes: 2 additions & 0 deletions app/serializers/like_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class LikeSerializer < ActiveModel::Serializer
attributes :id
end
2 changes: 2 additions & 0 deletions app/serializers/post_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PostSerializer < ActiveModel::Serializer
attributes :id, :title, :text, :comments_counter
has_many :likes
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class UserSerializer < ActiveModel::Serializer
attributes :id, :name, :bio, :photo, :role, :posts_counter
has_many :posts
Expand Down
4 changes: 3 additions & 1 deletion app/services/authentication_token_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

class AuthenticationTokenService
HMAC_SECRET = 'my$ecretK3y'.freeze
HMAC_SECRET = 'my$ecretK3y'
def self.encode(id)
payload = { user_id: id }
JWT.encode payload, HMAC_SECRET, 'HS256'
Expand Down
2 changes: 2 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'
Expand Down
4 changes: 2 additions & 2 deletions config/importmap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
pin '@hotwired/stimulus-loading', to: 'stimulus-loading.js', preload: true
pin_all_from 'app/javascript/controllers', under: 'controllers'

pin "bootstrap", to: "bootstrap.min.js", preload: true
pin "@popperjs/core", to: "popper.js", preload: true
pin 'bootstrap', to: 'bootstrap.min.js', preload: true
pin '@popperjs/core', to: 'popper.js', preload: true
4 changes: 3 additions & 1 deletion config/initializers/active_model_serializer.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ActiveModelSerializers.config.adapter = :json_api
# frozen_string_literal: true

ActiveModelSerializers.config.adapter = :json_api
2 changes: 1 addition & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# Rails.application.config.assets.precompile += %w( admin.js admin.css )

# config/initializers/assets.rb
Rails.application.config.assets.precompile += %w(bootstrap.min.js popper.js)
Rails.application.config.assets.precompile += %w[bootstrap.min.js popper.js]
9 changes: 4 additions & 5 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

Rails.application.routes.draw do

namespace :api do
namespace :v1 do
post 'authenticate', to: 'authentication#create'
Expand All @@ -14,16 +13,16 @@
end

devise_for :users
devise_scope :user do
devise_scope :user do
get '/users/sign_out' => 'devise/sessions#destroy'
end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
root "users#index"
root 'users#index'

resources :users, only: [:index, :show] do
resources :users, only: %i[index show] do
resources :posts do
resources :comments
resources :likes, only: [:new, :create]
resources :likes, only: %i[new create]
end
end
# Defines the root path route ("/")
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220922173956_create_users.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923072124_create_posts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreatePosts < ActiveRecord::Migration[7.0]
def change
create_table :posts do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923073719_add_user_ref_to_posts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddUserRefToPosts < ActiveRecord::Migration[7.0]
def change
add_reference :posts, :user, null: false, foreign_key: true, index: true
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923075125_create_likes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateLikes < ActiveRecord::Migration[7.0]
def change
create_table :likes, &:timestamps
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923075205_add_user_ref_to_likes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddUserRefToLikes < ActiveRecord::Migration[7.0]
def change
add_reference :likes, :user, null: false, foreign_key: true, index: true
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923075818_add_posts_ref_to_likes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddPostsRefToLikes < ActiveRecord::Migration[7.0]
def change
add_reference :likes, :post, null: false, foreign_key: true, index: true
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923075848_create_comments.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CreateComments < ActiveRecord::Migration[7.0]
def change
create_table :comments do |t|
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923075906_add_users_ref_to_comments.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddUsersRefToComments < ActiveRecord::Migration[7.0]
def change
add_reference :comments, :user, null: false, foreign_key: true, index: true
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220923075931_add_posts_ref_to_comments.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddPostsRefToComments < ActiveRecord::Migration[7.0]
def change
add_reference :comments, :post, null: false, foreign_key: true, index: true
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220924011718_rename_column_in_posts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RenameColumnInPosts < ActiveRecord::Migration[7.0]
def change
rename_column :posts, :user_id, :author_id
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220924011808_rename_column_in_comments.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RenameColumnInComments < ActiveRecord::Migration[7.0]
def change
rename_column :comments, :user_id, :author_id
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20220924011859_rename_column_in_likes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class RenameColumnInLikes < ActiveRecord::Migration[7.0]
def change
rename_column :likes, :user_id, :author_id
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20221007101943_add_devise_to_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class AddDeviseToUsers < ActiveRecord::Migration[7.0]
def self.up
change_table :users do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''

## Recoverable
t.string :reset_password_token
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20221013055601_add_role_to_users.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddRoleToUsers < ActiveRecord::Migration[7.0]
def change
add_column :users, :role, :string
Expand Down
Loading

0 comments on commit 3ef18a8

Please sign in to comment.