actions

package
v0.0.0-...-2cdd79a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 6, 2025 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TimeSpecFmt = "2006-01-02T15:04"

Variables

View Source
var (
	ErrScheduleDisabled    = errors.New("排程已停用")
	ErrTooManyAppointments = errors.New("您已經有一個未完成的預約")
)
View Source
var AvaialbeAppointmentStatus = map[string]AppointmentStatus{
	"pending":    Pending,
	"contacting": Contacting,
	"confirmed":  Confirmed,
	"notMatched": NotMatched,
	"cancelled":  Cancelled,
	"completed":  Completed,
	"missed":     Missed,
}
View Source
var ErrDelNotPending = errors.New("無法取消並非等待中的預約")
View Source
var ErrIncompatibleStatus = errors.New("狀態不相容")
View Source
var ErrIncorrectAppointmentStatus = errors.New("incorrect appointment status")
View Source
var ErrNotMyAppointment = errors.New("這不是您的預約")

Functions

func AddOrg

func AddOrg(tx *gorm.DB, org Org, manager string) error

func LogByUID

func LogByUID(tx *gorm.DB, uid int64, action Action, desc string) error

func LogByUserName

func LogByUserName(tx *gorm.DB, uname string, action Action, desc string) error

func MgrDisableSchedule

func MgrDisableSchedule(tx *gorm.DB, mgr *User, id int64) error

func MgrPairAppointment

func MgrPairAppointment(tx *gorm.DB, mgr *User, aid int64, sid int64) error

func MgrSetAppointmentStatus

func MgrSetAppointmentStatus(tx *gorm.DB, mgr *User, aid int64, status AppointmentStatus) error

func Migrate

func Migrate(db *gorm.DB) error

func OrgGrantRole

func OrgGrantRole(tx *gorm.DB, mgr *User, uname string, role Role) error

func OrgRevokeRole

func OrgRevokeRole(tx *gorm.DB, mgr *User, uname string) error

func SaveTOTP

func SaveTOTP(tx *gorm.DB, u *User, secret string) error

func UpdateMemberNote

func UpdateMemberNote(tx *gorm.DB, u, victim *User, note string) error

func UpdateMemberOTP

func UpdateMemberOTP(tx *gorm.DB, u, victim *User, secret string) error

func UpdateMemberSecret

func UpdateMemberSecret(tx *gorm.DB, u, victim *User, secretNote string) error

func UserDeleteAppointment

func UserDeleteAppointment(tx *gorm.DB, aid int64, user *User) (err error)

func VolDeleteAppointment

func VolDeleteAppointment(tx *gorm.DB, aid int64, vol *User) (err error)

func VolDisableSchedule

func VolDisableSchedule(tx *gorm.DB, vol *User, id int64) error

func VolEditAppointmentPublicNote

func VolEditAppointmentPublicNote(tx *gorm.DB, vol *User, aid int64, note string) error

func VolEditAppointmentSecretNote

func VolEditAppointmentSecretNote(tx *gorm.DB, vol *User, aid int64, note string) error

func VolSetAppointmentStatus

func VolSetAppointmentStatus(tx *gorm.DB, vol *User, aid int64, status AppointmentStatus, checks ...AppointmentStatus) error

func VolSignReceipt

func VolSignReceipt(tx *gorm.DB, vol *User, id int64, note string, receives map[string]int) 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 MgrGetAppointment(tx *gorm.DB, mgr *User, aid int64) (ret *Appointment, err error)

func UsrGetAppointment

func UsrGetAppointment(tx *gorm.DB, user *User, aid int64) (ret *Appointment, err error)

func VolGetAppointment

func VolGetAppointment(tx *gorm.DB, vol *User, aid int64) (ret *Appointment, err error)

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 是民眾提供 聯絡方式及指示

func FakeContactMethod

func FakeContactMethod() *ContactMethod

for template validation

type Log

type Log struct {
	ID          int64
	Action      Action
	UserID      int64
	Description string
	CreatedAt   time.Time

	User *User `gorm:"foreignKey:UserID"`
}

Log 是操作記錄

func FakeLog

func FakeLog(u *User) *Log

for template validation

func MyLogs

func MyLogs(tx *gorm.DB, u *User) (ret []*Log, err error)

func OrgLogs

func OrgLogs(tx *gorm.DB, o *Org) (ret []*Log, err error)

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: 是否啟用交件功能

func FakeOrg

func FakeOrg() *Org

for template validation

func GetOrg

func GetOrg(tx *gorm.DB, name string) (ret *Org, cnt int64, err error)

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 FakeReceipt

func FakeReceipt(a *Appointment) *Receipt

for template validation

func UsrCreateReceipt

func UsrCreateReceipt(tx *gorm.DB, user *User, aid int64, secret string) (ret *Receipt, err error)

func UsrGetReceipt

func UsrGetReceipt(tx *gorm.DB, user *User, id int64) (ret *Receipt, err error)

func VolCreateReceipt

func VolCreateReceipt(tx *gorm.DB, vol *User, aid int64, secret string) (ret *Receipt, err error)

func VolGetReceipt

func VolGetReceipt(tx *gorm.DB, vol *User, id int64) (ret *Receipt, err error)

func (*Receipt) Receive

func (r *Receipt) Receive(area string, num int) *Receipt

for template validation

type Role

type Role string
const (
	Manager   Role = "manager"   // 罷團幹部
	Volunteer Role = "volunteer" // 罷免志工
	Novice    Role = "novice"    // 新手志工
	Member    Role = "member"    // 一般民眾
)

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 CreateSchedule(tx *gorm.DB, u *User, begin, end time.Time, area string) (ret *Schedule, err error)

func FakeSchedule

func FakeSchedule(u *User) *Schedule

for template validation

func ListAvailableSchedule

func ListAvailableSchedule(tx *gorm.DB, now time.Time, spec TimeSpec) (ret []*Schedule, err error)

func ListOrgSchedule

func ListOrgSchedule(tx *gorm.DB, org *Org, user string, spec TimeSpec) (ret []*Schedule, err error)

func ListUserSchedule

func ListUserSchedule(tx *gorm.DB, u *User, spec TimeSpec) (ret []*Schedule, err error)

func (*Schedule) SetDisabled

func (s *Schedule) SetDisabled(d bool) *Schedule

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

func ParseTimeSpec(bb, ba, eb, ea, inc string) (ret TimeSpec)

func (TimeSpec) ApplyTo

func (ts TimeSpec) ApplyTo(q *gorm.DB) *gorm.DB

func (TimeSpec) NZ

func (ts TimeSpec) NZ() bool

func (TimeSpec) SetBeginAfter

func (ts TimeSpec) SetBeginAfter(t time.Time) TimeSpec

func (TimeSpec) SetBeginBefore

func (ts TimeSpec) SetBeginBefore(t time.Time) TimeSpec

func (TimeSpec) SetEndAfter

func (ts TimeSpec) SetEndAfter(t time.Time) TimeSpec

func (TimeSpec) SetEndBefore

func (ts TimeSpec) SetEndBefore(t time.Time) TimeSpec

func (TimeSpec) SetInclude

func (ts TimeSpec) SetInclude(t time.Time) TimeSpec

func (TimeSpec) ToQuery

func (ts TimeSpec) ToQuery() template.URL

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 FakeUser

func FakeUser() *User

for template validation

func FindUser

func FindUser(tx *gorm.DB, name string) (*User, error)

func FindUserByID

func FindUserByID(tx *gorm.DB, id string) (*User, error)

func ListMembers

func ListMembers(tx *gorm.DB, orgID int64) ([]*User, error)

func Login

func Login(tx *gorm.DB, id string, provider OauthProvider) (ret *User, err error)

Login 透過 OAuth ID 登入,不存在則直接新增

func (*User) SetOrg

func (u *User) SetOrg(o *Org) *User

for template validation

func (*User) SetRole

func (u *User) SetRole(r Role) *User

for template validation

func (*User) SetTOTPSecret

func (u *User) SetTOTPSecret(secret string) *User

for template validation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL