Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Commit c11cef9

Browse files
committed
ticket has_many attendees
1 parent 9f8ee9f commit c11cef9

File tree

7 files changed

+74
-30
lines changed

7 files changed

+74
-30
lines changed

README.md

+13-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
# README
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
5-
6-
Things you may want to cover:
7-
8-
* Ruby version
9-
10-
* System dependencies
11-
12-
* Configuration
13-
14-
* Database creation
15-
16-
* Database initialization
17-
18-
* How to run the test suite
19-
20-
* Services (job queues, cache servers, search engines, etc.)
21-
22-
* Deployment instructions
23-
24-
* ...
3+
## Todos
4+
5+
- be: attendee ログイン
6+
- be: attendee 設定
7+
- be: 複数トラックの設定
8+
- be: タイムテーブル
9+
- fe: IVS embed
10+
- fe: チャット
11+
- be: チャットログ回収
12+
- 字幕考える
13+
- MediaLive スケジューリング
14+
- IVSメタデータ発出
15+
- トランジションのモーションどうするか

app/controllers/tito_webhook_controller.rb

+13-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ class TitoWebhookController < ApplicationController
33
skip_before_action :verify_authenticity_token
44

55
def create
6-
return render(status: 400, json: {status: :unknown_type}) unless request.headers['x-webhook-name']&.start_with?('ticket.')
6+
event_name = request.headers['x-webhook-name']
7+
return render(status: 400, json: {status: :unknown_type}) unless event_name&.start_with?('ticket.')
78

89
updated_at = params[:updated_at]&.yield_self { |_| Time.parse(_) }
9-
return render(status: 400, json: {status: :missing_updated_at}) unless request.headers['x-webhook-name']&.start_with?('ticket.')
10+
return render(status: 400, json: {status: :missing_updated_at}) unless updated_at
1011

1112
ticket = Ticket.find_or_initialize_by(tito_id: params[:id]&.to_i)
1213
return render(status: 200, json: {status: :skipped}) if ticket.updated_at && ticket.updated_at >= updated_at
@@ -26,10 +27,16 @@ def create
2627
tito_updated_at: updated_at,
2728
)
2829

29-
if ticket.save
30-
render(status: 200, json: {status: :ok})
31-
else
32-
render(status: 400, json: {status: :invalid_record}) # TODO: Raven
30+
ApplicationRecord.transaction do
31+
if ticket.save
32+
if %w(ticket.reassigned ticket.voided).include?(event_name) || ticket.state == 'void'
33+
ticket.attendees.each(&:void!)
34+
end
35+
36+
render(status: 200, json: {status: :ok})
37+
else
38+
render(status: 400, json: {status: :invalid_record}) # TODO: Raven
39+
end
3340
end
3441
end
3542

app/models/attendee.rb

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Attendee < ApplicationRecord
2+
belongs_to :ticket
3+
4+
scope :active, -> { where.not(voided_at: nil) }
5+
6+
def void!
7+
self.voided_at = Time.zone.now
8+
self.save!
9+
end
10+
end

app/models/ticket.rb

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
class Ticket < ApplicationRecord
2+
has_many :attendees, dependent: :destroy # includes voided attendee
3+
4+
def active_attendee
5+
attendees.active.first
6+
end
27
end

config/database.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ default: &default
2525
development:
2626
<<: *default
2727
database: takeout_app_development
28-
<% docker_port = ENV['DATABASE_URL'].nil? ? IO.popen([*%w(docker-compose port db 5432), err: File::NULL], 'r', &:read).chomp.split(?:)&.last : nil %>
28+
<% docker_port = (ENV['DATABASE_URL'].nil? ? IO.popen([*%w(docker-compose port db 5432), err: File::NULL], 'r', &:read).chomp.split(?:)&.last : nil) || '' %>
2929
<% unless docker_port.empty? %>
3030
host: 127.0.0.1
3131
port: <%= docker_port %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class CreateAttendees < ActiveRecord::Migration[6.1]
2+
def change
3+
create_table :attendees do |t|
4+
t.references :ticket, null: false, foreign_key: true
5+
t.string :name
6+
t.string :gravatar_hash
7+
t.boolean :is_staff
8+
t.boolean :is_speaker
9+
t.boolean :is_committer
10+
t.boolean :is_sponsor
11+
t.datetime :voided_at
12+
13+
t.timestamps
14+
end
15+
end
16+
end

db/schema.rb

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)