Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit ccad114

Browse files
author
Frank Davis Condezo Fabian
authored
Merge pull request #57 from codeableorg/release-5
Release 5
2 parents 5ac011f + ce3a863 commit ccad114

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+557
-75
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ client/yarn-debug.log*
4949
client/yarn-error.log*
5050

5151
client/.env
52+
api/.env

api/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
STRIPE_SECRET_KEY=""
2+
STRIPE_PUBLISHABLE_KEY=""

api/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ group :development do
4040
gem 'spring-watcher-listen', '~> 2.0.0'
4141
end
4242

43+
gem 'stripe'
4344

4445
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
4546
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
4647
gem 'active_model_serializers'
4748
gem 'rspec-rails'
49+
50+
gem 'dotenv-rails', groups: [:development, :test]

api/Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,16 @@ GEM
5656
case_transform (0.2)
5757
activesupport
5858
concurrent-ruby (1.1.5)
59+
connection_pool (2.2.2)
5960
crass (1.0.4)
6061
diff-lcs (1.3)
62+
dotenv (2.7.5)
63+
dotenv-rails (2.7.5)
64+
dotenv (= 2.7.5)
65+
railties (>= 3.2, < 6.1)
6166
erubi (1.8.0)
67+
faraday (0.15.4)
68+
multipart-post (>= 1.2, < 3)
6269
ffi (1.11.1)
6370
globalid (0.4.2)
6471
activesupport (>= 4.2.0)
@@ -82,6 +89,9 @@ GEM
8289
mini_portile2 (2.4.0)
8390
minitest (5.11.3)
8491
msgpack (1.3.0)
92+
multipart-post (2.1.1)
93+
net-http-persistent (3.1.0)
94+
connection_pool (~> 2.2)
8595
nio4r (2.4.0)
8696
nokogiri (1.10.3)
8797
mini_portile2 (~> 2.4.0)
@@ -148,6 +158,9 @@ GEM
148158
actionpack (>= 4.0)
149159
activesupport (>= 4.0)
150160
sprockets (>= 3.0.0)
161+
stripe (4.22.0)
162+
faraday (~> 0.13)
163+
net-http-persistent (~> 3.0)
151164
thor (0.20.3)
152165
thread_safe (0.3.6)
153166
tzinfo (1.2.5)
@@ -164,6 +177,7 @@ DEPENDENCIES
164177
bcrypt (~> 3.1.7)
165178
bootsnap (>= 1.1.0)
166179
byebug
180+
dotenv-rails
167181
listen (>= 3.0.5, < 3.2)
168182
pg (>= 0.18, < 2.0)
169183
puma (~> 3.11)
@@ -172,6 +186,7 @@ DEPENDENCIES
172186
rspec-rails
173187
spring
174188
spring-watcher-listen (~> 2.0.0)
189+
stripe
175190
tzinfo-data
176191

177192
RUBY VERSION
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
256 KB
Loading
214 KB
Loading
71.1 KB
Loading
76.6 KB
Loading

api/app/controllers/application_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ def render_unauthorized(message)
2020

2121
def authenticate_token
2222
user = User.find_by_token(cookies.signed[:auth_token])
23-
regenerate_and_signed_token(user) if user
2423
end
2524

2625
def regenerate_and_signed_token(user)
2726
user.regenerate_token
28-
cookies.signed[:auth_token] = { value: user.token, httponly: true }
27+
cookies.signed[:auth_token] = { value: user.token, httponly: true, expires: Time.now + 7.day }
2928
user
3029
end
3130
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class BookingsController < ApplicationController
2+
before_action :set_booking, only: [:show]
3+
4+
def index
5+
render json: Booking.all
6+
end
7+
8+
def show
9+
render json: @booking
10+
end
11+
12+
def create
13+
booking = current_user.bookings.new(booking_params)
14+
if booking.save
15+
render json: booking, status: :created
16+
else
17+
render json: { errors: booking.errors.full_messages}, status: :unprocessable_entity
18+
end
19+
end
20+
21+
private
22+
23+
def set_booking
24+
@booking = Booking.find(params[:id])
25+
end
26+
27+
def booking_params
28+
params.permit(:date, :start_hour, :end_hour, :amount, :sport_field_id)
29+
end
30+
31+
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class ChargesController < ApplicationController
2+
def create
3+
4+
charge = Stripe::Charge.create({
5+
amount: params[:amount] * 100,
6+
description: "Kampu - Sports Field booking",
7+
currency: "usd",
8+
source: params[:token]
9+
})
10+
11+
booking = current_user.bookings.create(
12+
date: params[:date],
13+
start_hour: params[:start_hour],
14+
end_hour: params[:end_hour],
15+
amount: params[:amount],
16+
sport_field_id: params[:sport_field_id]
17+
)
18+
if booking.save
19+
render json: booking, status: :created
20+
else
21+
render json: { errors: booking.errors.full_messages}, status: :unprocessable_entity
22+
end
23+
24+
rescue Stripe::CardError => e
25+
render json: { errors: e.message }, status: :unprocessable_entity
26+
end
27+
end

api/app/controllers/sessions_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def login
1515
def register
1616
user = User.new(user_params)
1717
if user.save
18+
regenerate_and_signed_token(user)
1819
render json: user
1920
else
2021
render json: { errors: user.errors.full_messages}, status: :bad_request
@@ -24,7 +25,7 @@ def register
2425

2526
def destroy
2627
current_user.invalidate_token
27-
cookies.delete :auth_token
28+
cookies.update(response.cookies)
2829
head :ok
2930
end
3031

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
class UsersController < ApplicationController
22

33
def me
4-
render json: current_user.as_json(only: %i[name email role]), status: :ok
4+
render json: current_user.as_json(only: %i[id name email role]), status: :ok
5+
end
6+
7+
def user_with_bookings
8+
render json: current_user
59
end
610

711
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class UserSerializer < ActiveModel::Serializer
2+
3+
attributes :id, :name, :email, :role, :bookings
4+
5+
def bookings
6+
object.bookings.map do |booking|
7+
booking.attributes.merge({
8+
sport_field_name: booking.sport_field.name,
9+
club_id: booking.sport_field.club.id,
10+
club_name: booking.sport_field.club.name
11+
})
12+
end
13+
end
14+
15+
end

api/config/initializers/stripe.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Rails.configuration.stripe = {
2+
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
3+
:secret_key => ENV['STRIPE_SECRET_KEY']
4+
}
5+
6+
Stripe.api_key = Rails.configuration.stripe[:secret_key]

api/config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
get '/schedule/:id', to: 'sport_fields#schedule'
77
get '/report/:id', to: 'clubs#report'
88
get '/me', to: 'users#me'
9+
get '/userinfo', to: 'users#user_with_bookings'
10+
post '/booking', to: 'bookings#create'
911
resources :clubs do
1012
resource :favorites, only: [:create, :destroy]
1113
end
1214
resources :sport_fields do
1315
get 'schedule', on: :member
1416
get 'times', on: :member
1517
end
18+
19+
post '/charge', to: 'charges#create'
1620
end
1721
end

api/db/seeds.rb

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,69 @@
1-
puts "Init seed"
1+
puts "Init seed 🙈🙉🙊"
22

33
def get_image(file_name)
44
{ io: File.open(File.join(Rails.root, "/app/assets/images/#{file_name}")), filename: file_name }
55
end
66

7-
User.destroy_all
8-
regular_user = User.create(name: 'Lian Nivin', email: '[email protected]', role: "regular", password: '123456')
9-
owner_user = User.create(name: 'Cristian Berly', email: '[email protected]', role: "owner", password: '123456')
10-
11-
clubs = Club.create([{name: "Club #1", image: get_image("cancha1.jpg"), address: 'Jr cayumba 440', district: "Lince", latitude: -12.1199378, longitude: -77.0373161,
12-
schedule: {
13-
'monday-friday': {
14-
start: '8',
15-
end: '22'
16-
},
17-
'saturday': {
18-
start: '10',
19-
end: '22'
7+
clubs = [
8+
{
9+
name: "La Diez",
10+
address: "La Calera de la Merced 178, Distrito de Lima 15038",
11+
district: "Surquillo",
12+
latitude: -12.1135125,
13+
longitude: -77.0113851,
14+
num_img: 4
2015
},
21-
'sunday': {
22-
start: '14',
23-
end: '22'
24-
},
25-
}}, {name: "Club #2", image: get_image("cancha2.jpg"), address: 'Av. Jorge Chavez 184', district: "Miraflores", latitude: -13.1199378, longitude: -77.0353161,
26-
schedule: {
27-
'monday-friday': {
28-
start: '8',
29-
end: '22'
16+
{
17+
name: "Depor plaza Puericultorio",
18+
address: "Av. del Ejército 700",
19+
district: "Magdalena",
20+
latitude: -12.1003595,
21+
longitude: -77.0646032,
22+
num_img: 4
3023
},
31-
'saturday': {
32-
start: '8',
33-
end: '22'
24+
{
25+
name: "Depor Plaza Costa Verde",
26+
address: "Costa Verde Magdalena del Mar",
27+
district: "Magdalena",
28+
latitude: -12.1053237,
29+
longitude: -77.0652807,
30+
num_img: 4
3431
},
35-
'sunday': {
36-
start: '8',
37-
end: '22'
32+
{
33+
name: "Complejo Deportivo - Municipalidad de San Isidro",
34+
address: "Av. Augusto Pérez Araníbar 1355",
35+
district: "San Isidro",
36+
latitude: -12.1078158,
37+
longitude: -77.053914,
38+
num_img: 3
39+
},
40+
{
41+
name: "Cancha de Futbol 6",
42+
address: "Jirón Rio Piura 481",
43+
district: "Cercado de Lima",
44+
latitude: -12.0778519,
45+
longitude: -77.0023999,
46+
num_img: 2
3847
},
39-
}}, {name: "Club #3", image: get_image("cancha1.jpg"), address: 'Jr General Artigas 440', district: "Pueblo Libre", latitude: -14.1199378, longitude: -77.0373261,
40-
schedule: {
48+
{
49+
name: "Fanatic Soccer Fir",
50+
address: "Av Bolivia 148",
51+
district: "Cercado de Lima",
52+
latitude: -12.054698,
53+
longitude: -77.036893,
54+
num_img: 2
55+
},
56+
{
57+
name: "Complejo Deportivo Chino Vasquez",
58+
address: "Malecón de la Marina 9, Miraflores 15074",
59+
district: "Miraflores",
60+
latitude: -12.1137559,
61+
longitude: -77.0493404,
62+
num_img: 2
63+
},
64+
]
65+
66+
schedule = {
4167
'monday-friday': {
4268
start: '8',
4369
end: '22'
@@ -49,11 +75,21 @@ def get_image(file_name)
4975
'sunday': {
5076
start: '8',
5177
end: '22'
52-
},
53-
}}])
78+
}
79+
}
80+
81+
regular_user = User.create(name: 'Lian Nivin', email: '[email protected]', role: "regular", password: '123456')
82+
owner_user = User.create(name: 'Cristian Berly', email: '[email protected]', role: "owner", password: '123456')
83+
84+
clubs.each do |club|
85+
image = club[:num_img].times.map { |i| get_image("#{club[:name]}/gallery_#{i + 1}.jpg") }
86+
club.delete(:num_img)
87+
Club.create(club.merge({image: image, schedule: schedule}))
88+
end
5489

5590
sportfield1 = SportField.create(name: "SportField #1", description: "Soccer 5vs5", price_day: 20, price_night: 40, club_id: 1)
56-
sportfield2 = SportField.create(name: "SportField #2", club_id: 2); SportField.create(name: "SportField #2", description: "Soccer 6vs6", price_day: 30, price_night: 60, club_id: 2)
91+
sportfield2 = SportField.create(name: "SportField #2", club_id: 2);
92+
SportField.create(name: "SportField #2", description: "Soccer 6vs6", price_day: 30, price_night: 60, club_id: 2)
5793
sportfield3 = SportField.create(name: "SportField #3", club_id: 1); SportField.create(name: "SportField #3", description: "Soccer 5vs5", price_day: 20, price_night: 40, club_id: 1)
5894

5995
# favorites
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe ChargesController, type: :controller do
4+
5+
end

client/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ REACT_APP_VERSION=$npm_package_version
22
REACT_APP_API_URL=http://localhost:4000/api
33
REACT_APP_API_URL_PRODUCTION=
44
REACT_APP_OPEN_CAGE_DATA_KEY=
5+
REACT_APP_STRIPE_KEY=

client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"react-leaflet": "^2.4.0",
2020
"react-redux": "^7.1.0",
2121
"react-scripts": "3.0.1",
22+
"react-stripe-elements": "^4.0.0",
2223
"redux": "^4.0.1",
2324
"redux-thunk": "^2.3.0"
2425
},

client/public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<meta name="author" content="Team Codeable">
2525
<title>Kampu</title>
2626
<link href="https://fonts.googleapis.com/css?family=Rubik&display=swap" rel="stylesheet">
27+
<script src="https://js.stripe.com/v3/"></script>
2728
</head>
2829

2930
<body>

0 commit comments

Comments
 (0)