Skip to content

Commit 488ea22

Browse files
feat: Add color to medical shifts and recurrences (#335)
1 parent 5072e5c commit 488ea22

14 files changed

+59
-16
lines changed

app/controllers/api/v1/medical_shift_recurrences_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def recurrence_params
6969
:workload,
7070
:start_hour,
7171
:hospital_name,
72-
:amount_cents
72+
:amount_cents,
73+
:color
7374
).to_h
7475
end
7576
end

app/controllers/api/v1/medical_shifts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def medical_shift
8484
end
8585

8686
def medical_shift_params
87-
params.permit(:hospital_name, :workload, :start_date, :start_hour, :amount_cents, :paid).to_h
87+
params.permit(:hospital_name, :workload, :start_date, :start_hour, :amount_cents, :paid, :color).to_h
8888
end
8989

9090
def serialized_medical_shifts(medical_shifts)

app/models/medical_shift.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class MedicalShift < ApplicationRecord
2121
validates :amount_cents, presence: true
2222

2323
validates :amount_cents, numericality: { greater_than_or_equal_to: 0 }
24+
validates :color, format: { with: /\A#[a-fA-F0-9]{6}\z/ }
2425

2526
def shift
2627
daytime_start = Time.new(2000, 0o1, 0o1, 0o7, 0o0, 0o0, 0o0)

app/models/medical_shift_recurrence.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MedicalShiftRecurrence < ApplicationRecord
1919
validates :start_hour, presence: true
2020
validates :hospital_name, presence: true
2121
validates :amount_cents, presence: true, numericality: { greater_than_or_equal_to: 0 }
22+
validates :color, format: { with: /\A#[a-fA-F0-9]{6}\z/ }
2223

2324
validates :day_of_week, presence: true, if: lambda {
2425
frequency.in?(%w[weekly biweekly])

app/serializers/medical_shift_recurrence_serializer.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ class MedicalShiftRecurrenceSerializer < ActiveModel::Serializer
1212
:hospital_name,
1313
:amount_cents,
1414
:last_generated_until,
15-
:user_id
15+
:user_id,
16+
:color
1617

1718
def amount_cents
1819
object.amount.format

app/serializers/medical_shift_serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class MedicalShiftSerializer < ActiveModel::Serializer
44
attributes :id, :hospital_name, :workload, :date, :hour, :amount_cents, :paid, :shift, :title,
5-
:medical_shift_recurrence_id
5+
:medical_shift_recurrence_id, :color
66

77
def date
88
object.start_date.strftime("%d/%m/%Y")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddColorToMedicalShiftsAndRecurrences < ActiveRecord::Migration[7.1]
4+
def change
5+
add_column :medical_shifts, :color, :string, default: "#ffffff", null: false
6+
add_column :medical_shift_recurrences, :color, :string, default: "#ffffff", null: false
7+
end
8+
end

db/schema.rb

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/factories/medical_shift_recurrences.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
start_hour { "19:00:00" }
1212
hospital_name { create(:hospital).name }
1313
amount_cents { 120_000 }
14+
color { "#ffffff" }
1415

1516
trait :weekly do
1617
frequency { "weekly" }

spec/factories/medical_shifts.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
start_hour { "10:51:23" }
1111
amount_cents { 1 }
1212
paid { false }
13+
color { "#ffffff" }
1314

1415
traits_for_enum(:workload, MedicalShifts::Workloads.list)
1516

0 commit comments

Comments
 (0)