Skip to content

Commit a9dc9b8

Browse files
Initial scaffold and routes
1 parent c83bd03 commit a9dc9b8

Some content is hidden

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

49 files changed

+943
-40
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/.bundle
99

1010
# Ignore bundle files
11-
/vendor/bundle /*
11+
/vendor/bundle/*
1212

1313
# Ignore the default SQLite database.
1414
/db/*.sqlite3
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class AppointmentsController < ApplicationController
2+
before_action :set_appointment, only: %i[ show update destroy ]
3+
4+
# GET /appointments
5+
def index
6+
@appointments = Appointment.all
7+
8+
render json: @appointments
9+
end
10+
11+
# GET /appointments/1
12+
def show
13+
render json: @appointment
14+
end
15+
16+
# POST /appointments
17+
def create
18+
@appointment = Appointment.new(appointment_params)
19+
20+
if @appointment.save
21+
render json: @appointment, status: :created, location: @appointment
22+
else
23+
render json: @appointment.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /appointments/1
28+
def update
29+
if @appointment.update(appointment_params)
30+
render json: @appointment
31+
else
32+
render json: @appointment.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /appointments/1
37+
def destroy
38+
@appointment.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_appointment
44+
@appointment = Appointment.find(params[:id])
45+
end
46+
47+
# Only allow a list of trusted parameters through.
48+
def appointment_params
49+
params.require(:appointment).permit(:medic_id, :patient_id, :date, :type, :finished)
50+
end
51+
end

app/controllers/especialidades_controller.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/controllers/medics_controller.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class MedicsController < ApplicationController
2+
before_action :set_medic, only: %i[ show update destroy ]
3+
4+
# GET /medics
5+
def index
6+
@medics = Medic.all
7+
8+
render json: @medics, include: [:user, :specialty, :schedules]
9+
end
10+
11+
# GET /medics/1
12+
def show
13+
render json: @medic, include: [:user, :specialty, :schedules]
14+
end
15+
16+
# POST /medics
17+
def create
18+
@medic = Medic.new(medic_params)
19+
20+
if @medic.save
21+
render json: @medic, status: :created, location: @medic
22+
else
23+
render json: @medic.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /medics/1
28+
def update
29+
if @medic.update(medic_params)
30+
render json: @medic
31+
else
32+
render json: @medic.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /medics/1
37+
def destroy
38+
@medic.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_medic
44+
@medic = Medic.find(params[:id])
45+
end
46+
47+
# Only allow a list of trusted parameters through.
48+
def medic_params
49+
params.require(:medic).permit(:user_id, :specialty_id, :registry)
50+
end
51+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class PatientsController < ApplicationController
2+
before_action :set_patient, only: %i[ show update destroy ]
3+
4+
# GET /patients
5+
def index
6+
@patients = Patient.all
7+
8+
render json: @patients
9+
end
10+
11+
# GET /patients/1
12+
def show
13+
render json: @patient
14+
end
15+
16+
# POST /patients
17+
def create
18+
@patient = Patient.new(patient_params)
19+
20+
if @patient.save
21+
render json: @patient, status: :created, location: @patient
22+
else
23+
render json: @patient.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /patients/1
28+
def update
29+
if @patient.update(patient_params)
30+
render json: @patient
31+
else
32+
render json: @patient.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /patients/1
37+
def destroy
38+
@patient.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_patient
44+
@patient = Patient.find(params[:id])
45+
end
46+
47+
# Only allow a list of trusted parameters through.
48+
def patient_params
49+
params.require(:patient).permit(:user_id, :dob, :sex, :cpf)
50+
end
51+
end

app/controllers/records_controller.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class RecordsController < ApplicationController
2+
before_action :set_record, only: %i[ show update destroy ]
3+
4+
# GET /records
5+
def index
6+
@records = Record.all
7+
8+
render json: @records
9+
end
10+
11+
# GET /records/1
12+
def show
13+
render json: @record
14+
end
15+
16+
# POST /records
17+
def create
18+
@record = Record.new(record_params)
19+
20+
if @record.save
21+
render json: @record, status: :created, location: @record
22+
else
23+
render json: @record.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /records/1
28+
def update
29+
if @record.update(record_params)
30+
render json: @record
31+
else
32+
render json: @record.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /records/1
37+
def destroy
38+
@record.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_record
44+
@record = Record.find(params[:id])
45+
end
46+
47+
# Only allow a list of trusted parameters through.
48+
def record_params
49+
params.require(:record).permit(:patient_id, :description)
50+
end
51+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class SchedulesController < ApplicationController
2+
before_action :set_schedule, only: %i[ show update destroy ]
3+
4+
# GET /schedules
5+
def index
6+
@schedules = Schedule.all
7+
8+
render json: @schedules
9+
end
10+
11+
# GET /schedules/1
12+
def show
13+
render json: @schedule
14+
end
15+
16+
# POST /schedules
17+
def create
18+
@schedule = Schedule.new(schedule_params)
19+
20+
if @schedule.save
21+
render json: @schedule, status: :created, location: @schedule
22+
else
23+
render json: @schedule.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /schedules/1
28+
def update
29+
if @schedule.update(schedule_params)
30+
render json: @schedule
31+
else
32+
render json: @schedule.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /schedules/1
37+
def destroy
38+
@schedule.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_schedule
44+
@schedule = Schedule.find(params[:id])
45+
end
46+
47+
# Only allow a list of trusted parameters through.
48+
def schedule_params
49+
params.require(:schedule).permit(:medic_id, :date)
50+
end
51+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
class SpecialtiesController < ApplicationController
2+
before_action :set_specialty, only: %i[ show update destroy ]
3+
4+
# GET /specialties
5+
def index
6+
@specialties = Specialty.all
7+
8+
render json: @specialties
9+
end
10+
11+
# GET /specialties/1
12+
def show
13+
render json: @specialty
14+
end
15+
16+
# POST /specialties
17+
def create
18+
@specialty = Specialty.new(specialty_params)
19+
20+
if @specialty.save
21+
render json: @specialty, status: :created, location: @specialty
22+
else
23+
render json: @specialty.errors, status: :unprocessable_entity
24+
end
25+
end
26+
27+
# PATCH/PUT /specialties/1
28+
def update
29+
if @specialty.update(specialty_params)
30+
render json: @specialty
31+
else
32+
render json: @specialty.errors, status: :unprocessable_entity
33+
end
34+
end
35+
36+
# DELETE /specialties/1
37+
def destroy
38+
@specialty.destroy
39+
end
40+
41+
private
42+
# Use callbacks to share common setup or constraints between actions.
43+
def set_specialty
44+
@specialty = Specialty.find(params[:id])
45+
end
46+
47+
# Only allow a list of trusted parameters through.
48+
def specialty_params
49+
params.require(:specialty).permit(:name)
50+
end
51+
end

app/controllers/users_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ class UsersController < ApplicationController
55
def index
66
@users = User.all
77

8-
render json: @users
8+
render json: @users, include: [:patient, :medic]
99
end
1010

1111
# GET /users/1
1212
def show
13-
render json: @user
13+
render json: @user, include: [:patient => {:include => :record}]
1414
end
1515

1616
# POST /users
@@ -46,6 +46,6 @@ def set_user
4646

4747
# Only allow a list of trusted parameters through.
4848
def user_params
49-
params.require(:user).permit(:name, :email, :password)
49+
params.require(:user).permit(:name, :email, :password_digest)
5050
end
5151
end

app/models/appointment.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Appointment < ApplicationRecord
2+
belongs_to :medic
3+
belongs_to :patient
4+
end

0 commit comments

Comments
 (0)