Documentation
¶
Overview ¶
Package anny integrates the Anny room-booking system (anny.eu): it fetches the bookings from the Anny API, stores them, and answers queries about them and about the personalization configuration that decides which bookings are "ours". It is deliberately narrow: it depends only on a small DB interface (satisfied by *db.DB), a Reporter for progress output, and a static Config injected by the caller (so viper stays in plexams). The room-capacity views that consume Anny bookings (e.g. booked seats per slot) live in the plexams package; they call this service for the raw bookings and the configuration.
Index ¶
- func CoversSlot(from, until, slotStart time.Time) bool
- func IsApprovedStatus(status string) bool
- func MatchesAnyPersonalization(name string, names []string) bool
- func RoomBookedDuringExamTime(bookings []RoomBooking, slot *model.Slot) bool
- type Config
- type DB
- type Reporter
- type RoomBooking
- type Service
- func (s *Service) AllBookings(ctx context.Context) ([]*model.AnnyBooking, error)
- func (s *Service) Bookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error)
- func (s *Service) Config(ctx context.Context) (*model.AnnyConfig, error)
- func (s *Service) Fetch(ctx context.Context, reporter Reporter) error
- func (s *Service) PersonalizationNames(ctx context.Context) []string
- func (s *Service) RoomNames(ctx context.Context) (map[string]struct{}, error)
- func (s *Service) SetPersonalizationNames(ctx context.Context, names []string) (*model.AnnyConfig, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoversSlot ¶ added in v1.213.3
CoversSlot reports whether a booking spanning [from, until) makes its rooms usable in an exam slot starting at slotStart: the booking must start before the slot and end after the slot's ~90-minute window (slotStart + 89 minutes).
func IsApprovedStatus ¶
IsApprovedStatus reports whether an Anny booking status counts as approved.
func MatchesAnyPersonalization ¶
MatchesAnyPersonalization reports whether name equals (case-insensitively) any of the configured names. An empty list means "keep everything".
func RoomBookedDuringExamTime ¶ added in v1.213.3
func RoomBookedDuringExamTime(bookings []RoomBooking, slot *model.Slot) bool
RoomBookedDuringExamTime reports whether any booking fully covers the exam window of the slot — from the slot start to 90 minutes later, with the boundaries inclusive (a booking starting/ending exactly at an exam boundary counts).
Types ¶
type Config ¶
type Config struct {
// Token is the Anny API bearer token (anny.token).
Token string
// URL is the bookings endpoint (anny.url); a default is used when empty.
URL string
// SeedPersonalizationNames is the config-file fallback used as the personalization
// configuration when the DB holds none yet.
SeedPersonalizationNames []string
}
Config holds the static configuration (from the config file) the service needs.
type DB ¶
type DB interface {
SaveAnnyBookings(ctx context.Context, bookings []*model.AnnyBooking) error
GetAnnyConfig(ctx context.Context) (*model.AnnyConfig, error)
SetAnnyConfig(ctx context.Context, cfg *model.AnnyConfig) error
AnnyBookings(ctx context.Context, room *string) ([]*model.AnnyBooking, error)
AllAnnyBookings(ctx context.Context) ([]*model.AnnyBooking, error)
Rooms(ctx context.Context) ([]*model.Room, error)
AddSyncLogEntry(ctx context.Context, entry *model.SyncLogEntry) error
}
DB is the persistence the anny service needs; *db.DB satisfies it.
type RoomBooking ¶ added in v1.213.3
RoomBooking is one or more rooms booked in Anny for a time window, with the approval status. It is the merged, planning-facing view (see MergeRoomBookings) of the raw Anny bookings; it feeds the EXaHM room availability per slot.
func MergeRoomBookings ¶ added in v1.213.3
func MergeRoomBookings(entries []RoomBooking) []RoomBooking
MergeRoomBookings sorts the bookings by room, approval and time, and merges adjacent or overlapping bookings of the same single room and approval status into one window. Bookings that do not name exactly one room are left untouched.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the Anny integration.
func New ¶
New builds an Anny service. db may be nil when no database is configured; the methods that need it guard against that.
func (*Service) AllBookings ¶
AllBookings returns all stored Anny bookings, each flagged with Mine.
func (*Service) Bookings ¶
Bookings returns the stored Anny bookings for a room (nil = all rooms), each flagged with Mine when its personalization name is one of ours.
func (*Service) Config ¶
Config returns the Anny settings from the DB, seeded from the config file (anny.personalization_name) when nothing is stored yet.
func (*Service) Fetch ¶
Fetch fetches the bookings from the Anny API and stores them in the database. All bookings (all rooms, all people) are kept; "ours" is flagged via the personalization names at query time, not filtered away here.
func (*Service) PersonalizationNames ¶
PersonalizationNames returns the configured personalization names (DB, else config-file seed).
func (*Service) RoomNames ¶
RoomNames returns the normalized names of the rooms marked as Anny rooms in the global rooms master data (RequestWith == ANNY).
func (*Service) SetPersonalizationNames ¶
func (s *Service) SetPersonalizationNames(ctx context.Context, names []string) (*model.AnnyConfig, error)
SetPersonalizationNames stores the personalization names used to flag our bookings.