diff --git a/database-model.ts b/database-model.ts index d91c67d..a784a44 100644 --- a/database-model.ts +++ b/database-model.ts @@ -16,30 +16,54 @@ type Maybe = { present: false } | { present: true; value: T } // PostiDM // +type UserID = string +type BookingID = string +type SlotID = string +type SeatID = string +type RoomID = string + type UserPermission = 'basic' | 'helper' | 'moderator' | 'admin' type PostiDM = { users: Map rooms: Map seats: Map + slots: Map + getCurrentWeekSlots(): Slot[] + + bookings: Map } -type UserID = string +// TODO: Tutte le funzioni "getCurrentSomething()" in realtà sono da pensare meglio in modo da poter passare un range temporale o qualcosa del genere + +/** + * Un utente loggato con credenziali di ateneo + */ type User = { id: UserID permissions: Set - bookings: Booking[] + + getBookings(): Booking[] + getCurrentSeat(): Maybe } -type BookingID = string +/** + * Una prenotazione di un utente per un certo slot orario + */ type Booking = { id: BookingID timestamp: Datetime slotID: SlotID + userID: UserID // cioè ok c'è User.bookings però pensando in SQL è sempre meglio avere comunque un id qui (forse) + + getSlot(): Slot // giusto per comodità per parlare direttamente dell'oggetto "Slot" relativo ad un "Booking" + getSeat(): Seat // ".getSlot().getSeat()" } -type SlotID = string +/** + * Slot rappresenta uno slot orario prenotabile per un certo posto + */ type Slot = { id: SlotID seatID: SeatID @@ -47,9 +71,13 @@ type Slot = { from: Datetime to: Datetime } + + getCurrentBooking(): Maybe } -type SeatID = string +/** + * Seat rappresenta un posto in dipartimento in una certa stanza + */ type Seat = { id: SeatID roomID: RoomID @@ -60,11 +88,13 @@ type Seat = { height: Natural } - // non mi piace questo nome - getCurrentOccupant(): Maybe + // TODO: Forse per ora è meglio fare che più utenti possono prenotare lo stesso posto così inizialmente possiamo fare che in ogni stanza c'è solo un posto e la gente può prenotarsi solo "alla stanza" e non al posto specifico, altrimenti facciamo "getCurrentBookedUser(): Maybe" + getCurrentlyBookedUsers(): User[] } -type RoomID = string +/** + * Room rappresenta una stanza in dipartimento e contiene dei posti + */ type Room = { id: RoomID seatIDs: SeatID[] @@ -73,6 +103,6 @@ type Room = { gridCols: Natural } - getTotalSeatCount(): Natural - getOccupiedSeatCount(): Natural + getTotalSeatCount(): Natural // ".seatIDs.length" + getCurrentBookedSeatCount(): Natural } diff --git a/server/db/database.go b/server/db/database.go index 6c427a6..f788762 100644 --- a/server/db/database.go +++ b/server/db/database.go @@ -161,12 +161,12 @@ func NewInMemoryStore() Database { db.users["aziis98"] = &User{ ID: "aziis98", - Permissions: util.NewSet[string](PermissionAdmin), + Permissions: util.NewSet(PermissionAdmin), } db.users["bachoseven"] = &User{ ID: "bachoseven", - Permissions: util.NewSet[string](PermissionAdmin), + Permissions: util.NewSet(PermissionAdmin), } return db diff --git a/server/db/inmemory.go b/server/db/inmemory.go index a38a30b..11ef09f 100644 --- a/server/db/inmemory.go +++ b/server/db/inmemory.go @@ -149,7 +149,7 @@ func (db *memDB) GetRoomFreeSeats(roomID string) ([]string, error) { func (db *memDB) GetUserSeats(userID string) (util.Set[string], error) { for _, seat := range db.seats { if len(seat.OccupiedBy) > 0 && seat.OccupiedBy[0] == userID { - return util.NewSet[string](seat.ID), nil + return util.NewSet(seat.ID), nil } }