Skip to content

Commit d10ff13

Browse files
authored
fix(events): fixed api to be public and have blank strings be null (#552)
* fix(events): fixed api to be public and have blank strings be null * made is so category is null on empty string
1 parent ecd1fb4 commit d10ff13

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

app/controllers/events_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class EventsController < ApplicationController
2+
respond_to :json
3+
4+
def show
5+
render json: Event.all
6+
end
7+
end

app/models/event.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,25 @@ def finish_before_start
99
errors.add(:finish, 'time must be after start time')
1010
end
1111
end
12+
13+
def description=(value)
14+
if value.blank?
15+
value = nil
16+
end
17+
super value
18+
end
19+
20+
def location=(value)
21+
if value.blank?
22+
value = nil
23+
end
24+
super value
25+
end
26+
27+
def category=(value)
28+
if value.blank?
29+
value = nil
30+
end
31+
super value
32+
end
1233
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
patch :boarded_bus, on: :collection
4141
end
4242

43+
resource :events, only: :show, constraints: ->(req) { req.format == :json }
44+
4345
namespace :manage do
4446
authenticate :user, ->(u) { u.director? } do
4547
root to: "dashboard#index"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class EventsControllerTest < ActionDispatch::IntegrationTest
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end

0 commit comments

Comments
 (0)