chore: remove rails app

This commit is contained in:
Juan Rodriguez
2024-05-12 15:07:56 +02:00
parent 8eb27f2c8a
commit 720b70c6a0
101 changed files with 0 additions and 10276 deletions
@@ -1,7 +0,0 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
def authenticate
@current_user = User.find_by(id: session[:user_id])
end
end
-49
View File
@@ -1,49 +0,0 @@
# frozen_string_literal: true
class LinksController < ApplicationController
include LinksHelper
before_action :authenticate, only: %i[create]
before_action :set_link, only: %i[redirect counter]
def redirect
if @link
@link.increment!(:click_counter) # rubocop:disable Rails/SkipsModelValidations
redirect_to @link.parsed_url
else
render file: Rails.root.join('/public/404'), status: :not_found
end
end
def counter
if @link
render json: @link.click_counter
else
render json: nil, status: :not_found
end
end
def create
url = stripped_url(link_params[:url])
@link = Link.find_or_create_by(url: url) do |link|
link.user = @current_user if @current_user
end
if @link.errors.any?
render json: @link.errors, status: :unprocessable_entity
else
render partial: 'links/show', locals: { link: @link }, status: :ok
end
end
private
def set_link
@link = Link.find_by(slug: params[:slug])
end
def link_params
params.require(:link).permit(:url)
end
end
-31
View File
@@ -1,31 +0,0 @@
# frozen_string_literal: true
class SessionsController < ApplicationController
before_action :authenticate, except: %i[create]
before_action :set_user, only: %i[create]
def create
if @user&.authenticate(session_params[:password])
session[:user_id] = @user.id
session[:username] = @user.username
render json: nil, status: :ok
else
render json: { username: ['Credentials not valid, try again or create an account'] }, status: :unauthorized
end
end
def destroy
reset_session
render json: nil, status: :ok
end
private
def set_user
@user = User.find_by(username: session_params[:username])
end
def session_params
params.permit(:username, :password)
end
end
-30
View File
@@ -1,30 +0,0 @@
# frozen_string_literal: true
class UsersController < ApplicationController
around_action :confirm_password_validation, only: %i[create]
def create
@user = User.create(user_params)
if @user.errors.any?
render json: @user.errors, status: :unprocessable_entity
else
session[:user_id] = @user.id
session[:username] = @user.username
render json: nil, status: :ok
end
end
private
def confirm_password_validation
if user_params[:password] == params[:user][:confirm_password]
yield
else
render json: { password: ['Password not match with Confirm Password'] }, status: :bad_request
end
end
def user_params
params.require(:user).permit(:username, :password)
end
end