Documentation
¶
Index ¶
- Constants
- Variables
- func AddOrg(tx *gorm.DB, org Org, manager string) error
- func LogByUID(tx *gorm.DB, uid int64, action Action, desc string) error
- func LogByUserName(tx *gorm.DB, uname string, action Action, desc string) error
- func MgrDisableSchedule(tx *gorm.DB, mgr *User, id int64) error
- func MgrPairAppointment(tx *gorm.DB, mgr *User, aid int64, sid int64) error
- func MgrSetAppointmentStatus(tx *gorm.DB, mgr *User, aid int64, status AppointmentStatus) error
- func Migrate(db *gorm.DB) error
- func OrgGrantRole(tx *gorm.DB, mgr *User, uname string, role Role) error
- func OrgRevokeRole(tx *gorm.DB, mgr *User, uname string) error
- func SaveTOTP(tx *gorm.DB, u *User, secret string) error
- func UpdateMemberNote(tx *gorm.DB, u, victim *User, note string) error
- func UpdateMemberOTP(tx *gorm.DB, u, victim *User, secret string) error
- func UpdateMemberSecret(tx *gorm.DB, u, victim *User, secretNote string) error
- func UserDeleteAppointment(tx *gorm.DB, aid int64, user *User) (err error)
- func VolDeleteAppointment(tx *gorm.DB, aid int64, vol *User) (err error)
- func VolDisableSchedule(tx *gorm.DB, vol *User, id int64) error
- func VolEditAppointmentPublicNote(tx *gorm.DB, vol *User, aid int64, note string) error
- func VolEditAppointmentSecretNote(tx *gorm.DB, vol *User, aid int64, note string) error
- func VolSetAppointmentStatus(tx *gorm.DB, vol *User, aid int64, status AppointmentStatus, ...) error
- func VolSignReceipt(tx *gorm.DB, vol *User, id int64, note string, receives map[string]int) error
- type Action
- type Appointment
- func CreateAppointment(tx *gorm.DB, scheduleID int64, user *User, contact ContactMethod) (ret *Appointment, err error)
- func FakeAppointment(u *User, s *Schedule) *Appointment
- func GetMgrAppointments(tx *gorm.DB, mgr *User) (ret []*Appointment, err error)
- func GetUserAppointments(tx *gorm.DB, u *User) (ret []*Appointment, err error)
- func GetVolAppointments(tx *gorm.DB, vol *User) (ret []*Appointment, err error)
- func MgrGetAppointment(tx *gorm.DB, mgr *User, aid int64) (ret *Appointment, err error)
- func UsrGetAppointment(tx *gorm.DB, user *User, aid int64) (ret *Appointment, err error)
- func VolGetAppointment(tx *gorm.DB, vol *User, aid int64) (ret *Appointment, err error)
- type AppointmentStatus
- type ContactMethod
- type Log
- type OauthProvider
- type Org
- type Receipt
- func FakeReceipt(a *Appointment) *Receipt
- func UsrCreateReceipt(tx *gorm.DB, user *User, aid int64, secret string) (ret *Receipt, err error)
- func UsrGetReceipt(tx *gorm.DB, user *User, id int64) (ret *Receipt, err error)
- func VolCreateReceipt(tx *gorm.DB, vol *User, aid int64, secret string) (ret *Receipt, err error)
- func VolGetReceipt(tx *gorm.DB, vol *User, id int64) (ret *Receipt, err error)
- type Role
- type Schedule
- func CreateSchedule(tx *gorm.DB, u *User, begin, end time.Time, area string) (ret *Schedule, err error)
- func FakeSchedule(u *User) *Schedule
- func ListAvailableSchedule(tx *gorm.DB, now time.Time, spec TimeSpec) (ret []*Schedule, err error)
- func ListOrgSchedule(tx *gorm.DB, org *Org, user string, spec TimeSpec) (ret []*Schedule, err error)
- func ListUserSchedule(tx *gorm.DB, u *User, spec TimeSpec) (ret []*Schedule, err error)
- type TimeSpec
- func (ts TimeSpec) ApplyTo(q *gorm.DB) *gorm.DB
- func (ts TimeSpec) NZ() bool
- func (ts TimeSpec) SetBeginAfter(t time.Time) TimeSpec
- func (ts TimeSpec) SetBeginBefore(t time.Time) TimeSpec
- func (ts TimeSpec) SetEndAfter(t time.Time) TimeSpec
- func (ts TimeSpec) SetEndBefore(t time.Time) TimeSpec
- func (ts TimeSpec) SetInclude(t time.Time) TimeSpec
- func (ts TimeSpec) ToQuery() template.URL
- type User
Constants ¶
const TimeSpecFmt = "2006-01-02T15:04"
Variables ¶
var ( ErrScheduleDisabled = errors.New("排程已停用") ErrTooManyAppointments = errors.New("您已經有一個未完成的預約") )
var AvaialbeAppointmentStatus = map[string]AppointmentStatus{ "pending": Pending, "contacting": Contacting, "confirmed": Confirmed, "notMatched": NotMatched, "cancelled": Cancelled, "completed": Completed, "missed": Missed, }
var ErrDelNotPending = errors.New("無法取消並非等待中的預約")
var ErrIncompatibleStatus = errors.New("狀態不相容")
var ErrIncorrectAppointmentStatus = errors.New("incorrect appointment status")
var ErrNotMyAppointment = errors.New("這不是您的預約")
Functions ¶
func LogByUserName ¶
func MgrPairAppointment ¶
func MgrSetAppointmentStatus ¶
func UpdateMemberSecret ¶
func UserDeleteAppointment ¶
func VolDeleteAppointment ¶
func VolSetAppointmentStatus ¶
func VolSetAppointmentStatus(tx *gorm.DB, vol *User, aid int64, status AppointmentStatus, checks ...AppointmentStatus) error
Types ¶
type Action ¶
type Action string
Action 是操作類型
const ( RegisterAccount Action = "register_account" UserLogin Action = "user_login" GrantRole Action = "grant_role" RevokeRole Action = "revoke_role" Enable2FA Action = "enable_2fa" EditMemberNote Action = "edit_member_note" EditMemberSecret Action = "edit_member_secret" EditMemberOTP Action = "edit_member_otp" NewSchedule Action = "new_schedule" DisableSchedule Action = "disable_schedule" NewAppointment Action = "new_appointment" CancelAppointment Action = "cancel_appointment" EditAppointment Action = "edit_appointment" PairAppointment Action = "pair_appointment" CreateReceipt Action = "create_receipt" SignReceipt Action = "sign_receipt" )
type Appointment ¶
type Appointment struct {
ID int64
UserID int64
ScheduleID int64
RegisterAt time.Time
ContactAt *time.Time
ContactMethod *ContactMethod `gorm:"serializer:json"`
UserNote string
VolunteerNote string
FinishAt *time.Time
Status AppointmentStatus
User *User `gorm:"foreignKey:UserID"`
Schedule *Schedule `gorm:"foreignKey:ScheduleID"`
Receipt *Receipt `gorm:"foreignKey:AppointmentID"`
}
Appointment 是一個掛號/預約,User 是一般民眾
- Name: 如何稱呼 (黃先生) (民眾填寫) - UserNote: 寫給民眾看的備註 - VolunteerNote: 寫給志工或幹部看的備註 - ContactAt: 標記為聯絡中的時間 - FinishAt: 變更為 Completed/Missed/Cancelled 的時間 (之後不能再變更)
func CreateAppointment ¶
func CreateAppointment(tx *gorm.DB, scheduleID int64, user *User, contact ContactMethod) (ret *Appointment, err error)
func FakeAppointment ¶
func FakeAppointment(u *User, s *Schedule) *Appointment
for template validation
func GetMgrAppointments ¶
func GetMgrAppointments(tx *gorm.DB, mgr *User) (ret []*Appointment, err error)
func GetUserAppointments ¶
func GetUserAppointments(tx *gorm.DB, u *User) (ret []*Appointment, err error)
func GetVolAppointments ¶
func GetVolAppointments(tx *gorm.DB, vol *User) (ret []*Appointment, err error)
func MgrGetAppointment ¶
func UsrGetAppointment ¶
func VolGetAppointment ¶
func (*Appointment) SetReceipt ¶
func (s *Appointment) SetReceipt(r *Receipt) *Appointment
for template validation
func (*Appointment) SetStatus ¶
func (s *Appointment) SetStatus(status AppointmentStatus) *Appointment
for template validation
type AppointmentStatus ¶
type AppointmentStatus int
const ( Pending AppointmentStatus = iota // 預設狀態,等待志工確認 Contacting // 聯絡中 Confirmed // 預約成功 NotMatched // 時間無法配合,需幹部介入轉給其他志工 Cancelled // 取消預約 Completed // 已取件 Missed // 連署人未出現 InvalidStatus )
狀態分為已完成和未完成兩類,Cancelled, Completed, Missed 是已完成的狀態
type ContactMethod ¶
type ContactMethod struct {
Name string // 如何稱呼 (黃先生)
Prefer string // 偏好的聯絡方式 (周一至五白天)
Phone string // 電話號碼
}
ContactMethod 是民眾提供 聯絡方式及指示
type Log ¶
type Log struct {
ID int64
Action Action
UserID int64
Description string
CreatedAt time.Time
User *User `gorm:"foreignKey:UserID"`
}
Log 是操作記錄
type OauthProvider ¶
type OauthProvider string
const ( Google OauthProvider = "google" Facebook OauthProvider = "facebook" Instagram OauthProvider = "instagram" Twitter OauthProvider = "twitter" Line OauthProvider = "line" Telegram OauthProvider = "telegram" )
type Org ¶
type Org struct {
ID int64
Name string `gorm:"unique"`
Area []string `gorm:"serializer:json"`
Target string
UseSubmission bool
}
Org 是一個罷免團隊
- Name: 團隊名稱 (斷健行動) - Area: 罷免區域 (中五、北區、北屯區) - Target: 罷免目標 (黃健豪) - UseSubmission: 是否啟用交件功能
type Receipt ¶
type Receipt struct {
ID int64
AppointmentID int64 `gorm:"unique"`
CreatedAt time.Time
CreatedByUserID int64
SignAt *time.Time
Secret string
Note string
Receives map[string]int `gorm:"serializer:json"`
SubmitAt *time.Time
ManagerID int64
Appointment *Appointment `gorm:"foreignKey:AppointmentID"`
CreatedByUser *User `gorm:"foreignKey:CreatedByUserID"`
Manager *User `gorm:"foreignKey:ManagerID"`
}
Receipt 是簽收記錄
- Secret: 民眾填寫的簽收備註 (密語) - Note: 志工填寫的簽收備註 - Receives: 收到的連署書 (區域名稱 -> 數量) - SubmitAt: 交件給罷團的時間 - Manager: 負責收下這次交件的罷團幹部
func UsrCreateReceipt ¶
func UsrGetReceipt ¶
func VolCreateReceipt ¶
type Schedule ¶
type Schedule struct {
ID int64
UserID int64
BeginAt time.Time
EndAt time.Time
Area string
Disabled bool
User *User `gorm:"foreignKey:UserID"`
}
Schedule 是一個可預約的項目,User 是志工
- BeginAt: 開始時間 - EndAt: 結束時間 - Area: 說明此志工有可能前往收件的區域 - Disabled: 是否停用,停用後不會出現在可掛號的清單中
func CreateSchedule ¶
func ListAvailableSchedule ¶
func ListOrgSchedule ¶
func ListUserSchedule ¶
func (*Schedule) SetDisabled ¶
for template validation
type TimeSpec ¶
type TimeSpec struct {
BeginBefore *time.Time
BeginAfter *time.Time
EndBefore *time.Time
EndAfter *time.Time
Include *time.Time
}
func ParseTimeSpec ¶
type User ¶
type User struct {
ID int64
OauthID string `gorm:"uniqueIndex:idx_oauth_provider_oauth_id"`
OauthProvider OauthProvider `gorm:"uniqueIndex:idx_oauth_provider_oauth_id"`
Name string `gorm:"unique"`
Note string // 幹部志工都能看見/僅幹部能修改
Secret string // 僅幹部能看見修改
Role Role
OrgID *int64
TOTPSecret string
Org *Org `gorm:"foreignKey:OrgID"`
}
使用者帳號
- Name: 名稱匿名化成 "隊員#甲乙丙丁" 這種格式,這裡存的是 "甲乙丙丁",隨機產生 - Role: 使用者角色,決定權限
func (*User) SetTOTPSecret ¶
for template validation