Skip to content

Instantly share code, notes, and snippets.

@NeverHappened
Created December 15, 2017 13:21
Show Gist options
  • Select an option

  • Save NeverHappened/62fe1c404e1d712f3e13b154b94b8a86 to your computer and use it in GitHub Desktop.

Select an option

Save NeverHappened/62fe1c404e1d712f3e13b154b94b8a86 to your computer and use it in GitHub Desktop.
MovieTheater
class User
has_many :tickets
end
class Hall < ActiveRecord
has_many :movie_sessions
end
class Movie < ActiveRecord
validates_presence_of :name
has_many :movie_sessions
end
class MovieSession < ActiveRecord
belongs_to :hall
belongs_to :movie
validates_presence_of :start
end
class Ticket < ActiveRecord
belongs_to :movie_session
belongs_to :user
validates_presence_of :row, :seat_number
end
class Facade
def next_week_movies
week_start = Time.now # TODO
week_end = Time.now # TODO
Movie.joins(:movie_sessions).where(
'movie_sessions.start > :next_week_start AND movie_sessions.start < :next_week_end',
next_week_start: week_start, next_week_end: week_end,
)
end
def buy_ticket(movie_session, user)
tickets = movie_session.tickets.where.not(user_id: nil)
ticket = tickets.first
ticket.update!(user: user)
ticket
end
# ITS unclear here how we should check the ticket - whether we have its ID?? or what
def check_ticket(hall, ticket)
current_session = ticket.movie_session
current_session&.hall && current_session.hall.id == hall.id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment