Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

appointment-diary-backend Final #15

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fd75449
Update prodoction env
kinginthenorthcodez Oct 2, 2022
22db428
Update prodcuction env
kinginthenorthcodez Oct 2, 2022
02c2d57
Update files
kinginthenorthcodez Oct 2, 2022
57692ff
Update bundler version to 2.3.10
kinginthenorthcodez Oct 2, 2022
8f84893
Downgrade bundler to 2.3.7
kinginthenorthcodez Oct 2, 2022
da00a7c
Downgrade bundler to 2.3.7
kinginthenorthcodez Oct 2, 2022
70f1085
Update Host
kinginthenorthcodez Oct 2, 2022
872c919
Remove auth in users controller
kinginthenorthcodez Oct 2, 2022
add141d
Update Swagger to single component
kinginthenorthcodez Oct 3, 2022
f8c9ede
Add heroku server to swagger docs
kinginthenorthcodez Oct 3, 2022
35744c4
Add root route
kinginthenorthcodez Oct 3, 2022
c13f9e4
Update default host for swagger docs
kinginthenorthcodez Oct 3, 2022
26331b4
Update swagger tests
kinginthenorthcodez Oct 3, 2022
6de8875
Fix linter
kinginthenorthcodez Oct 3, 2022
4f8c070
Fix Api docs
kinginthenorthcodez Oct 3, 2022
2763989
Fix crash issue,updated controllers
kinginthenorthcodez Oct 3, 2022
20d2ec4
Update swagger docs
kinginthenorthcodez Oct 3, 2022
70aedec
Update README with API LIVE link
kinginthenorthcodez Oct 3, 2022
5610ff9
Fix linter
kinginthenorthcodez Oct 3, 2022
d795d21
Remove comfirmable in users
kinginthenorthcodez Oct 3, 2022
7e22d27
Update vehicle model to include visible field
kinginthenorthcodez Oct 4, 2022
837cef4
Update and fix Tests
kinginthenorthcodez Oct 4, 2022
c6b7ab3
Update vehicle model, tests and API docs
kinginthenorthcodez Oct 4, 2022
eb0a61a
Merge pull request #14 from Fatima-hub333/feature/vehicle-model-update
kinginthenorthcodez Oct 4, 2022
95c669e
Fix linter and remove test dir
kinginthenorthcodez Oct 6, 2022
8cfdec3
Update README.md
kinginthenorthcodez Oct 6, 2022
3856d2a
Create license
kinginthenorthcodez Oct 6, 2022
15faae7
Update README.md
kinginthenorthcodez Oct 6, 2022
d0feda8
Update README.md
kinginthenorthcodez Oct 6, 2022
69cc16f
Update README.md
kinginthenorthcodez Oct 6, 2022
fa63987
Update README.md
kinginthenorthcodez Oct 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ gem 'bootsnap', require: false
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'

gem 'rswag'
gem 'rswag-api'
gem 'rswag-ui'

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand Down
13 changes: 2 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.5.0)
erubi (1.11.0)
ffi (1.15.5)
ffi (1.15.5-x64-mingw-ucrt)
globalid (1.0.0)
activesupport (>= 5.0)
Expand Down Expand Up @@ -125,15 +124,12 @@ GEM
net-smtp (0.3.2)
net-protocol
nio4r (2.5.8)
nokogiri (1.13.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.8-x64-mingw-ucrt)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.22.1)
parser (3.1.2.1)
ast (~> 2.4.1)
pg (1.4.3)
pg (1.4.3-x64-mingw-ucrt)
public_suffix (5.0.0)
puma (5.6.5)
Expand Down Expand Up @@ -196,10 +192,6 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.11.1)
rswag (2.6.0)
rswag-api (= 2.6.0)
rswag-specs (= 2.6.0)
rswag-ui (= 2.6.0)
rswag-api (2.6.0)
railties (>= 3.1, < 7.1)
rswag-specs (2.6.0)
Expand Down Expand Up @@ -238,9 +230,7 @@ GEM
zeitwerk (2.6.1)

PLATFORMS
arm64-darwin-21
x64-mingw-ucrt
x86_64-linux

DEPENDENCIES
bootsnap
Expand All @@ -255,8 +245,9 @@ DEPENDENCIES
rack-cors
rails (~> 7.0.4)
rspec-rails
rswag
rswag-api
rswag-specs
rswag-ui
rubocop (>= 1.0, < 2.0)
tzinfo-data

Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

- A friendly api to book vehicle reservations

![image](https://user-images.githubusercontent.com/94127418/194410472-85325ac9-67d0-4409-97cf-21090ccedc73.png)
![image](https://user-images.githubusercontent.com/94127418/194410576-8f1d6ae6-bcaa-4860-a31d-51b83b37e88c.png)


## LINK to front-end
- This Project has a React Front-end you can work with
> [React front-end](https://github.com/Fatima-hub333/appointment-diary-front-end) << open

## Backend API LIVE
> [API LIVE](https://book-vehicle.herokuapp.com/)

### Built With

- Ruby on Rails
Expand All @@ -16,6 +23,14 @@
- API Swagger documentation
- Bullet N + 1 queries

### Kanban Board
- [kanban](https://github.com/Fatima-hub333/appointment-diary/issues/56#issuecomment-1254172387)
- [Project]https://github.com/Fatima-hub333/appointment-diary-backend/tree/main)
-
🥇 We are a group of 3 people:
- @basem909
- @kinginthenorthcodez
- @Fatima-hub333
> git clone <https://github.com/Fatima-hub333/appointment-diary-backend>

- Move into project directory
Expand Down Expand Up @@ -78,7 +93,8 @@ GitHub: @Fatima-hub333
- Feel free to check the issues page.
<https://github.com/Fatima-hub333/appointment-diary-backend/issues>

### [Api documentation]()
### [Api documentation](https://book-vehicle.herokuapp.com/)


> Note: To release latest 24-10-2022

Expand All @@ -87,4 +103,4 @@ GitHub: @Fatima-hub333
Give a ⭐️ if you like this project!

📝 License
This project is MIT licensed.
This project is [MIT](https://github.com/Fatima-hub333/appointment-diary-backend/blob/dev/license).
3 changes: 0 additions & 3 deletions app/controllers/api/v1/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
class Api::V1::UsersController < ApplicationController
before_action :tokenized
before_action :authenticate_user!

def index
@users = User.all
render json: { status: 'Success', message: 'Loaded users', data: @users }, status: :ok
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/vehicles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ def set_vehicle
end

def vehicle_params
params.permit(:brand, :model, :price, :image, :description)
params.permit(:brand, :model, :price, :image, :visible, :description)
end
end
5 changes: 5 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class HomeController < ApplicationController
def index
redirect_to '/api-docs'
end
end
2 changes: 1 addition & 1 deletion app/controllers/users/omniauth_callbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class User::OmniauthCallbacksController < Devise::OmniauthCallbacksController
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/passwords_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class User::PasswordsController < Devise::PasswordsController
class Users::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create
def destroy
@user = current_user
if @user
render json: { status: 'Success', message: 'signed out', data: @user }, status: :ok
render json: { status: 'Success', message: 'signed out', data: @user }, status: 200
sign_out(@user)
else
render json: { status: 'Failed', message: 'There is no user to sign out' }, status: :unauthorized
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/unlocks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class User::UnlocksController < Devise::UnlocksController
class Users::UnlocksController < Devise::UnlocksController
# GET /resource/unlock/new
# def new
# super
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable, :confirmable
:recoverable, :rememberable, :validatable

before_create :generate_authentication_token

Expand Down
2 changes: 1 addition & 1 deletion app/models/vehicle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Vehicle < ApplicationRecord
validates :brand, :model, :description, :image, presence: true
validates :brand, :model, :description, :image, :visible, presence: true
validates :price, numericality: { greater_than_or_equal_to: 0 }

has_many :reservations, dependent: :destroy
Expand Down
4 changes: 0 additions & 4 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
config.action_mailer.default_url_options = { 'https://appointment-diary-backend.herokuapp.com/'}
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.perform_deliveries = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
Expand Down Expand Up @@ -59,7 +56,6 @@
# Use a real queuing backend for Active Job (and separate queues per environment).
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "appointment_diary_backend_production"

config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

Rails.application.routes.draw do
root to: 'home#index'
mount Rswag::Ui::Engine => '/api-docs'
mount Rswag::Api::Engine => '/api-docs'
devise_for :users, controllers: {
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20221004054904_add_visble_to_vehicle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVisbleToVehicle < ActiveRecord::Migration[7.0]
def change
add_column :vehicles, :visible, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

user1 = User.create!(name: 'John Doe', email: '[email protected]', password: 'test123', roles: ['admin'])
user2 = User.create!(name: 'Jane Doe', email: '[email protected]', password: 'test123', roles: ['admin'])
user1.confirm
user2.confirm
veh1 = Vehicle.create!(brand: 'BWM', model: 'BMW-30', image: 'image-bmw', price: 80, description: 'good and lightspeed with low consumptiom')
veh2 = Vehicle.create!(brand: 'Macendiz', model: 'Benz-30', image: 'image-Benz', price: 90, description: 'good and lightspeed with low consumptiom')
veh3 = Vehicle.create!(brand: 'G-Wagon', model: 'G-wagon-15', image: 'image-wagon', price: 95, description: 'good and lightspeed with low consumptiom')
veh1 = Vehicle.create!(brand: 'BWM', model: 'BMW-30', image: 'image-bmw', price: 80, visible: true, description: 'good and lightspeed with low consumptiom')
veh2 = Vehicle.create!(brand: 'Macendiz', model: 'Benz-30', image: 'image-Benz', price: 90, visible: true,description: 'good and lightspeed with low consumptiom')
veh3 = Vehicle.create!(brand: 'G-Wagon', model: 'G-wagon-15', image: 'image-wagon', price: 95, visible: true, description: 'good and lightspeed with low consumptiom')
res1 = Reservation.create!(user: user1, vehicle: veh1, date: '24-09-2022', city: 'bravos')
res1 = Reservation.create!(user: user2, vehicle: veh1,date: '24-09-2022', city: 'capetown')
res1 = Reservation.create!(user: user2, vehicle: veh3,date: '24-09-2022', city: 'lusaka')
Expand Down
21 changes: 21 additions & 0 deletions license
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Isaac, Bassem and Fatima

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 12 additions & 7 deletions spec/requests/api/v1/vehicles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
model: 'Benz-30',
price: '90.0',
image: 'image-Benz',
visible: 'true',
description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.296Z',
updated_at: '2022-10-01T04:51:07.296Z'
Expand All @@ -35,6 +36,7 @@
brand: 'G-Wagon',
model: 'G-wagon-15',
price: '95.0',
visible: 'true',
image: 'image-wagon',
description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.302Z',
Expand All @@ -45,6 +47,7 @@
brand: 'Farari',
model: 'BMW',
price: '450.0',
visible: 'true',
image: 'farari.png',
description: 'Some text here',
created_at: '2022-10-01T12:39:00.705Z',
Expand Down Expand Up @@ -75,6 +78,7 @@
model: { type: :string },
image: { type: :string },
price: { type: :decimal },
visible: { type: :boolean },
description: { type: :text }
},
required: %w[authenticate_token brand model image price description]
Expand All @@ -83,7 +87,7 @@
let(:params) do
{ authentication_token: User.last.authentication_token,
brand: 'Mecedz', model: 'benz-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
end
example 'application/json', 'success', {
status: 'Success',
Expand All @@ -93,6 +97,7 @@
brand: 'G-Wagon',
model: 'G-wagon-15',
price: '95.0',
visible: 'true',
image: 'image-wagon',
description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T22:01:18.479Z',
Expand Down Expand Up @@ -121,7 +126,7 @@
let(:params) { { authentication_token: User.first.authentication_token } }
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand All @@ -144,11 +149,11 @@
let(:params) do
{ authentication_token: User.first.authentication_token,
brand: 'Lambo', model: 'lambo-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
end
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand All @@ -171,11 +176,11 @@
let(:params) do
{ authentication_token: User.first.authentication_token,
brand: 'Lambo', model: 'lambo-30', image: 'image-bmw',
price: 80, description: 'good and lightspeed with low consumptiom' }
price: 80, visible: true, description: 'good and lightspeed with low consumptiom' }
end
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0',
data: { id: 4, brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand All @@ -199,7 +204,7 @@
example 'application/json', 'success', {
status: 'Success', message: 'Loaded vehicle',
data: { id: 4,
brand: 'BWM', model: 'BMW-30', price: '80.0',
brand: 'BWM', model: 'BMW-30', price: '80.0', visible: 'true',
image: 'image-bmw', description: 'good and lightspeed with low consumptiom',
created_at: '2022-10-01T04:51:07.286Z', updated_at: '2022-10-01T04:51:07.286Z' }
}
Expand Down
6 changes: 2 additions & 4 deletions spec/requests/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
RSpec.describe 'users/sign_in', type: :request do
context 'sign_in' do
before(:each) do
Rails.application.load_seed
User.find_by(email: '[email protected]').confirm
post user_session_path, params: { email: '[email protected]', password: 'test123' }
post user_session_path, params: { email: '[email protected]', password: 'test123' }
end
it 'Responds with ok status' do
puts response
Expand All @@ -18,7 +16,7 @@
end
it 'Responds data has the email of the user signed in' do
data = JSON.parse(response.body)['data']
expect(data['email']).to eq('john@gmail.com')
expect(data['email']).to eq('john123@gmail.com')
end
end
end
4 changes: 0 additions & 4 deletions spec/requests/reservation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
RSpec.describe '/api/v1/reservation', type: :request do
context 'Create Reservation ' do
before(:each) do
Rails.application.load_seed
User.first.confirm
get api_v1_reservations_path, params: { authentication_token: User.first.authentication_token }
end

Expand All @@ -29,8 +27,6 @@
end
context 'Unauthorized access' do
before(:each) do
Rails.application.load_seed
User.first.confirm
get api_v1_reservations_path
end
it 'Respnse unauthrozed' do
Expand Down
Loading