在Rails中构建约会预订系统 [英] Building an appointment booking system in Rails

查看:119
本文介绍了在Rails中构建约会预订系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求构建具有以下特征的约会预订应用程序: -用户可以是服务提供商或买家 -服务提供商设置其可用性(但最多只能将其可用性设置为最长6个月) -买方可以根据这些可用性来预定约会-每个约会根据服务类型而花费的时间不同 -根据买方选择的约会,将显示一组不同的可用性,具体取决于服务所需的时间

我构建的是以下内容: -一个TimeSlot模型,其中我根据start_timeend_time属性创建了一些通用的30分钟时隙.为了使这些时间间隔延长到未来的6个月,我每天都会运行一个后台作业,该工作会创建所有必要的新时间段

class TimeSlot < ActiveRecord::Base
  has_many :user_time_slots
  # ... more methods below
end

-一个UserTimeSlots模型,该模型基本上表示他们可以设置的服务提供商的可用性.因此,当他们创建一个user_time_slot时,实际上是在说它们当时可用.

class UserTimeSlot < ActiveRecord::Base 
    belongs_to :time_slot
    belongs_to :service_provider, :class_name => "User"
    belongs_to :appointment
end

-一个具有许多user_time_slot的Appointment模型.它有很多原因,因为约会属于需要花费一定时间(服务上的time_required属性)的服务,并且可能跨越多个连续 user_time_slots.

class Appointment < ActiveRecord::Base
  has_many :user_time_slots
  belongs_to :buyer, :class_name => "User"
  belongs_to :service_provider, :class_name => "User"
  belongs_to :service
end

-一个Service模型,具有许多约会,并且属于创建该服务的服务提供商.

class Service < ActiveRecord::Base
  has_many :appointments
  belongs_to :service_provider, :class_name => "User"
end

此域模型有效;但是,由于以下原因,我想知道是否有更好的方法:

  • 对于我来说,每天使用后台作业在后端创建TimeSlot记录对我来说有点笨拙-TimeSlot的唯一目的是确定开始时间和结束时间,然后与之关联.

  • >
    • 一旦用户(买方)选择了他们想要的服务,我不确定如何有效地找到x个连续的user_time_slot,因此可用于预订约会(例如,如果我有30分钟的话)时隙间隔,并且用户选择了一个约需3个小时的约会,因此我必须找到6个连续的时隙).例如,如果用户单击某个服务的实例,我将必须1)获得该服务所需的时间(足够容易做到)和2)我必须找到该用户的所有user_time_slots并收集其关联的time_slots,然后将每个时隙的开始时间和结束时间相互比较,以找到连续的时间.对我来说,这似乎太多了迭代,并且这似乎会使我的应用程序陷入困境!

是否有人有更好的方法或解决方案(特别是围绕查找连续时隙的话题)?

解决方案

看起来像一个有趣的项目. :)

我个人不会为现有时间"建模,即我不会有后台工作来创建空"数据.

我会尝试这样的模型:

用户表在哪里?

对于两种不同的用户类型,我不会使用共享的用户模型.我的直觉是,即使不是现在,它们也需要与时俱进,以至于变得与众不同.我认为,这也使模型更加清晰.如果有登录名或任何身份验证,我将为该特定数据添加一个User表,而让服务提供商消费者与之相关.

服务提供商管理可用性

服务提供商仅需要一个空日历(或类似日历),并根据 Service 仅列出她已经输入的服务可用性.

消费类图书预约

消费者将根据服务

搜索/浏览/导航服务可用性

取决于业务逻辑,即 Consumer 是否总是安排整个定义的时间段?或者,消费者可以预定一个首选时间段.只要预订的时段在给定服务的可用时段内?

计划

因此,我们仅在服务提供者管理其对特定服务的可用性时才放入服务可用性记录.空被认为是不可用的.

基于服务可用性,我们仅在消费者预订服务时放置约会记录./p>

如果消费者可能只预订服务可用性时段的一部分,我建议创建两个(或一个)新的 Service剩余时间的可用性记录.可以通过将服务可用性约会进行比较来检查时间是否可用,但这并不是最佳选择. 最好只查询服务可用性以获取特定的 Service 并获得可用性时间表,其中没有记录就意味着没有可用性.

这里有很多if,具体取决于您的特定需求和要求的业务逻辑.但我希望这会有所启发和启发.

I am looking to build an appointment booking app with the following characteristics: - Users can be service providers or buyers - Service providers set their availabilities (but can only set their availabilities at a maximum of 6 months ahead) - Buyers can then book appointments based on those availabilities - each appointment, based on the type of service, takes a different amount of time - Based on the appointment that a buyer selects, a different set of availabilities is shown depending on how long the service takes

What I've built is the following: - A TimeSlot model where I create a number of generic 30 minute time slots based on a start_time and end_time attribute. In order to make these time slots extend 6 months into the future, I have a background job running each day that creates all the new time slots necessary

class TimeSlot < ActiveRecord::Base
  has_many :user_time_slots
  # ... more methods below
end

- A UserTimeSlots model that basically represents a service provider's availability that they can set. So when they create a user_time_slot, they are essentially saying that they are available at that time.

class UserTimeSlot < ActiveRecord::Base 
    belongs_to :time_slot
    belongs_to :service_provider, :class_name => "User"
    belongs_to :appointment
end

- An Appointment model that has many user_time_slots. It has many because an appointment belongs to a service which takes a certain amount of time (a time_required attribute on services) and it might span a number consecutive user_time_slots.

class Appointment < ActiveRecord::Base
  has_many :user_time_slots
  belongs_to :buyer, :class_name => "User"
  belongs_to :service_provider, :class_name => "User"
  belongs_to :service
end

- A Service model that has many appointments and belongs to a service provider who creates that service.

class Service < ActiveRecord::Base
  has_many :appointments
  belongs_to :service_provider, :class_name => "User"
end

This domain model works; however, I am wondering if there is a better way to do this because of the following:

  • It seems a little clunky to me to be creating TimeSlot records every day on my backend using a background job - the TimeSlots really have the sole purpose of having a start and end time and then being associated to.

    • Once the user (buyer) selects a service they want, I am not sure how I would efficiently find the x number of user_time_slots that are consecutive and, therefore, available for booking the appointment (for example, if I have 30 minute time slot intervals and a user selects an appointment that will take 3 hours, I would have to find 6 consecutive time slots). For example, if a user clicks on an instance of a service I would have to 1) get the time required for that service (easy enough to do) and 2) I'd have to find ALL of the user's user_time_slots and collect their associated time_slots, then compare each time slot's start and end times to one another to find consecutive ones. This just seems like way too much iteration to me and seems like this will bog down my application!

Does anyone have a better way or solution to do this (particularly around the topic of finding consecutive time slots)?

解决方案

Look like a fun project. :)

I would personally not model the "existing time", i.e I would not have a background job create "empty" data.

I would try a model like this:

Where the User table?

I would not use a shared User model for the two different User types. My gut feeling is that they need to be different, if not now, most surly over time. Also it makes the model more clear, in my opinion. If there is a login or any auth, I would add a User table for that specific data and rather have Service Provider and Consumer have some relation to this.

Service Provider manages availability

The Service Provider would only need an empty calendar (or similar), listing only her already entered Service Availability, per Service.

Consumer books appointment

The Consumer would search/browse/navigate Service Availability, per Service

Depending on business logic, i.e. will a Consumer always schedule the whole defined time slot? Or could the Consumer book a preferred time slot. As long as the booked slot is within the given Service's available time slot?

Scheduling

So we only put Service Availability records in when the Service Provider manages her availability for a specific Service. Empty is simply considered not available.

We only put Appointment records in when a Consumer books an Service, based on Service Availability.

If its possible for the Consumer to book only a part of a Service Availability time slot, I would recommend to create two (or one) new Service Availability records for the time left over. Checking if time is available could be done by comparing Service Availability with Appointment, but this would not be optimal. Better would be to just query Service Availability for a specific Service and get a availability schedule, where no record would mean no availability.

There are a lots of ifs here, depending on your specifc needs and requested business logic. But I hope this helps with some inspiration and ideas.

这篇关于在Rails中构建约会预订系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆