Skip to content

Instantly share code, notes, and snippets.

@keepcosmos
Last active August 29, 2015 13:57
Show Gist options
  • Save keepcosmos/9913702 to your computer and use it in GitHub Desktop.
Save keepcosmos/9913702 to your computer and use it in GitHub Desktop.
Mongodb Calendar Sample Code
class Calendar::GuideCalendar
include Mongoid::Document
field :user_id, :type => Integer
has_many :event_date, :class => Calendar::EventDate
# event date 기간 삽입
def insert_duration(start_date, end_date)
self.insert_events(*(start_date..end_date).to_a)
end
# event date 주기 반복 삽입
def insert_repeat_weekday(weekday, start_date, end_date)
weekday.downcase!
dates = (start_date..end_date).to_a.select{ |date| date.strftime("%A").downcase == weekday }
self.insert_events(dates)
end
def insert_events(*dates)
calendar_dates = Array.new
dates.each do |date|
calendar_date = self.event_dates.new
# linked list 만드는 로직
end
# collection insert
# array insert
# http://docs.mongodb.org/manual/reference/method/db.collection.insert/#id4
end
def remove_events(*dates)
end
def remove_events_from(dates)
# 저장된 event date list부터 노드를 따라가며 삭제
end
def get_events(date)
end
def occupied?(date)
end
end
class Calendar::EventDate
include Mongoid::Document
field :title, :type => String #title 이 그룹 date linked list를 대표하기 key 가 되거나, list의 유일키가 필요할 수도 있을 듯
field :evnet_type, :type => String #'occupied', 'hold', 'reserved_group'
field :reservation_id, :type => Integer
field :date, :type => Date
field :prev_event_date, :type => Moped::BSON::ObjectId
field :next_event_date, :type => Moped::BSON::ObjectId
belongs_to :guide_calendar, :class => Calendar::GuideCalendar
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment