-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from fmanimashaun/features/models-generation
Features/models generation
- Loading branch information
Showing
59 changed files
with
873 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
class ApplicationController < ActionController::API | ||
before_action :configure_permitted_parameters, if: :devise_controller? | ||
|
||
protected | ||
|
||
def configure_permitted_parameters | ||
devise_parameter_sanitizer.permit(:sign_up, keys: %i[name username email]) | ||
devise_parameter_sanitizer.permit(:account_update, keys: %i[name username email]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module RackSessionFix | ||
extend ActiveSupport::Concern | ||
class FakeRackSession < Hash | ||
def enabled? | ||
false | ||
end | ||
end | ||
included do | ||
before_action :set_fake_rack_session_for_devise | ||
|
||
private | ||
|
||
def set_fake_rack_session_for_devise | ||
request.env['rack.session'] ||= FakeRackSession.new | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Users::CurrentUserController < ApplicationController | ||
before_action :authenticate_user! | ||
def index | ||
render json: UserSerializer.new(current_user).serializable_hash[:data][:attributes], status: :ok | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Users::RegistrationsController < Devise::RegistrationsController | ||
include RackSessionFix | ||
respond_to :json | ||
|
||
private | ||
|
||
def respond_with(resource, _opts = {}) | ||
if request.method == 'POST' && resource.persisted? | ||
render json: { | ||
status: { | ||
code: 200, | ||
message: 'Signed up sucessfully.' | ||
}, | ||
data: | ||
UserSerializer.new(resource).serializable_hash[:data][ | ||
:attributes | ||
] | ||
}, | ||
status: :ok | ||
elsif request.method == 'DELETE' | ||
render json: { | ||
status: { | ||
code: 200, | ||
message: 'Account deleted successfully.' | ||
} | ||
}, | ||
status: :ok | ||
else | ||
render json: { | ||
status: { | ||
code: 422, | ||
message: | ||
"User couldn't be created successfully. #{resource.errors.full_messages.to_sentence}" | ||
} | ||
}, | ||
status: :unprocessable_entity | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Users::SessionsController < Devise::SessionsController | ||
include RackSessionFix | ||
respond_to :json | ||
|
||
private | ||
|
||
def respond_with(resource, _opts = {}) | ||
render json: { | ||
status: { code: 200, message: 'Logged in sucessfully.' }, | ||
data: UserSerializer.new(resource).serializable_hash[:data][:attributes] | ||
}, status: :ok | ||
end | ||
|
||
def respond_to_on_destroy | ||
if current_user | ||
render json: { | ||
status: 200, | ||
message: 'logged out successfully' | ||
}, status: :ok | ||
else | ||
render json: { | ||
status: 401, | ||
message: "Couldn't find an active session." | ||
}, status: :unauthorized | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Car < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class CarDetail < ApplicationRecord | ||
belongs_to :car | ||
belongs_to :engine_type | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
class City < ApplicationRecord | ||
validates :name, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class EngineType < ApplicationRecord | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Reservation < ApplicationRecord | ||
belongs_to :city | ||
belongs_to :car | ||
belongs_to :user | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class User < ApplicationRecord | ||
include Devise::JWT::RevocationStrategies::JTIMatcher | ||
|
||
devise :database_authenticatable, :registerable, :recoverable, :validatable, :jwt_authenticatable, | ||
jwt_revocation_strategy: self | ||
|
||
has_many :reservations | ||
|
||
enum role: { user: 0, admin: 1 } | ||
|
||
after_initialize :set_default_role, if: :new_record? | ||
|
||
# constants for validation | ||
PASSWORD_INVALID_MESSAGE = 'must include at least one lowercase letter, one uppercase letter, and one digit'.freeze | ||
USERNAME_INVALID_MESSAGE = 'only allows alphanumeric characters and underscores'.freeze | ||
USERNAME_REGEX = /\A[a-zA-Z0-9_.]+\z/ | ||
PASSWORD_REGEX = /\A(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}\z/ | ||
|
||
validates :username, presence: true, uniqueness: true | ||
validates :name, presence: true | ||
validates :email, presence: true, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP } | ||
validates :username, format: { with: USERNAME_REGEX, message: USERNAME_INVALID_MESSAGE } | ||
validates :password, length: { minimum: 8 }, format: { with: PASSWORD_REGEX, message: PASSWORD_INVALID_MESSAGE } | ||
|
||
roles.keys.each do |role_name| | ||
define_method("#{role_name}?") do | ||
role == role_name | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_default_role | ||
self.role ||= :user | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CarDetailSerializer | ||
include JSONAPI::Serializer | ||
attributes :horsepower, :torque, :fuel_economy, :seating_capacity, :cargo_space, :infotainment_system, | ||
:safety_rating, :tech_features, :special_features | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class CarSerializer | ||
include JSONAPI::Serializer | ||
attributes :name, :description | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class CitySerializer | ||
include JSONAPI::Serializer | ||
attributes :name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class EngineTypeSerializer | ||
include JSONAPI::Serializer | ||
attributes :name | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class ReservationSerializer | ||
include JSONAPI::Serializer | ||
attributes :date | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class UserSerializer | ||
include JSONAPI::Serializer | ||
attributes :id, :email, :username, :name, :role | ||
|
||
attribute :created_date do |user| | ||
user.created_at&.strftime('%m/%d/%Y') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
P0XtMJLb09AL5rF2nRhXmeIQvSw6Lpc5cLwk9LKqKpZZmDb0en1Rzb1diXsAHCB5l/K9G+hEepPcVeCqRgoZbdD+i2FB3yleO0hMCBYC9KGC69iPzh/joBNOuWrKbEDTGZi8Ma2BO7W8aii+OmkhPhBxxNXwaHdhZAdQko+jcvn/1FlEkeeZ+7TNpwtXL95aDdTsgm9IQu1m7EJ9zPfmyp9LF6sEp09eqhqBIwsc+Lg6B/EutyQKhwZVoiR6gRa3xKH68sHZWdGDRrS2iagwF4aoJikY6MsRI47YegZ8B0QmDoiMJqrJ9O7w7acCV6nR5tjmf8AB7oyMWw9WvbFAZnR0zrrV0tc1kqc4NoHqerp6SyB0A1FS6okk2C5nAXLpo+5UaAKoNkrVyQOxH09Z+PNxNR/C--cELd5wJ9HCqSGcYl--JH/7Osq4NkZaK6+UyN8Sxw== | ||
HplnKCaSqUE0Mzc9OgrBtnQRXmkt1XzNzilIg60jli7oHQ9MuMiZC0pO0cYla85p7dL5bGGJ5uOkx4s2h2MpOjaDaNiqJor4wxd0Qz9GGmrHXlaUbsLvtfaDDHYxooXm8qQoF7BkW3d036n6v8S+MWTznFOQwthXvwVFJkW2mOcGiSG3IDeFSNrI8/mt2zQ0NCJ1ykOuANB+JLhhFeVwaquxjA0PhJwUpuOm25xs+wxp5bDLjZJyG56w203kRCumrgqgIdCZV7Y7/xSW3O6L0kIoLseTC6jpORu8v7d0zIkgOvJwEdC8513JpVhNknB58W8J7gnDlwrlt6tO+JojC0RDEiiGR3DC7TeW1dZUiLTTHIPR8kUd2vny3hR14t45xe40+iK11bCEPVefj9azkbGXp2Ghlv2xjdn3giiRP3Ec5spFyrMNqZyNi8lDAwpV4Xo1mmcoSbGnGBMdwes3k2vaTa7Mvq758piDm3LWYS51llYlxMdihzMK2pRP4qdwy9cWjTPjgrnFxUk6RPcdmmVEhf4pqmUMCb0jEaXnPIcI2g==--Y0jwt/38HBhybFAB--Uxjp7y0/24KQ6NMGLGuLMA== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.