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

Commit f69894e

Browse files
author
condef5
committed
Refactor backend
1 parent e321e32 commit f69894e

6 files changed

Lines changed: 53 additions & 6 deletions

File tree

api/app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ def regenerate_and_signed_token(user)
2828
cookies.signed[:auth_token] = { value: user.token, httponly: true }
2929
user
3030
end
31-
end
31+
end

api/app/controllers/sessions_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def register
1717
if user.save
1818
render json: user
1919
else
20-
render json: { errors: user.errors}
20+
render json: { errors: user.errors}, status: :bad_request
2121
end
2222

2323
end
@@ -32,4 +32,4 @@ def destroy
3232
def user_params
3333
params.permit(:name, :email, :password, :role)
3434
end
35-
end
35+
end

api/app/controllers/sport_fields_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class SportFieldsController < ApplicationController
22

3+
def index
4+
render json: SportField.all
5+
end
6+
37
def create
48
sport_field = SportField.new(sport_field_params)
59
if sport_field.save

api/app/serializers/sport_field_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class SportFieldSerializer < ActiveModel::Serializer
22
include Rails.application.routes.url_helpers
33

4-
attributes :id, :name, :description, :image, :price_day, :price_night
4+
attributes :id, :name, :description, :image, :price_day, :price_night, :club_id
55

66
def image
77
url_for(object.image) if self.object.image.attached?

api/config/initializers/cors.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
methods: [:get, :post, :put, :patch, :delete, :options, :head],
88
credentials: true
99
end
10-
end
10+
end

api/db/seeds.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,50 @@
33
User.create(name: 'Lian Nivin', email: 'liam@kampu.pe', role: "regular", password: '123456')
44
User.create(name: 'Cristian Berly', email: 'berli@kampu.pe', role: "owner", password: '123456')
55

6-
clubs = Club.create([{name: "Club #1"}, {name: "Club #2"}, {name: "Club #3"}])
6+
clubs = Club.create([{name: "Club #1", address: 'Jr cayumba 440',
7+
schedule: {
8+
'monday-friday': {
9+
start: '8',
10+
end: '22'
11+
},
12+
'saturday': {
13+
start: '8',
14+
end: '22'
15+
},
16+
'sunday': {
17+
start: '8',
18+
end: '22'
19+
},
20+
}}, {name: "Club #2", address: 'Jr cayumba 440',
21+
schedule: {
22+
'monday-friday': {
23+
start: '8',
24+
end: '22'
25+
},
26+
'saturday': {
27+
start: '8',
28+
end: '22'
29+
},
30+
'sunday': {
31+
start: '8',
32+
end: '22'
33+
},
34+
}}, {name: "Club #3", address: 'Jr cayumba 440',
35+
schedule: {
36+
'monday-friday': {
37+
start: '8',
38+
end: '22'
39+
},
40+
'saturday': {
41+
start: '8',
42+
end: '22'
43+
},
44+
'sunday': {
45+
start: '8',
46+
end: '22'
47+
},
48+
}}])
49+
750
SportField.create(name: "SportField #1", club_id: 1);
851
SportField.create(name: "SportField #2", club_id: 2);
952
SportField.create(name: "SportField #3", club_id: 1);

0 commit comments

Comments
 (0)