In alcuni punti go deduce da solo i tipi e ulteriori aggiunte a database-model.ts

dev
Antonio De Lucreziis 4 years ago
parent 7387307ad9
commit 1682cdca81

@ -16,30 +16,54 @@ type Maybe<T> = { present: false } | { present: true; value: T }
// PostiDM // PostiDM
// //
type UserID = string
type BookingID = string
type SlotID = string
type SeatID = string
type RoomID = string
type UserPermission = 'basic' | 'helper' | 'moderator' | 'admin' type UserPermission = 'basic' | 'helper' | 'moderator' | 'admin'
type PostiDM = { type PostiDM = {
users: Map<UserID, User> users: Map<UserID, User>
rooms: Map<RoomID, Room> rooms: Map<RoomID, Room>
seats: Map<SeatID, Seat> seats: Map<SeatID, Seat>
slots: Map<SlotID, Slot> slots: Map<SlotID, Slot>
getCurrentWeekSlots(): Slot[]
bookings: Map<BookingID, Booking>
} }
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 = { type User = {
id: UserID id: UserID
permissions: Set<UserPermission> permissions: Set<UserPermission>
bookings: Booking[]
getBookings(): Booking[]
getCurrentSeat(): Maybe<Seat>
} }
type BookingID = string /**
* Una prenotazione di un utente per un certo slot orario
*/
type Booking = { type Booking = {
id: BookingID id: BookingID
timestamp: Datetime timestamp: Datetime
slotID: SlotID 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 = { type Slot = {
id: SlotID id: SlotID
seatID: SeatID seatID: SeatID
@ -47,9 +71,13 @@ type Slot = {
from: Datetime from: Datetime
to: Datetime to: Datetime
} }
getCurrentBooking(): Maybe<Booking>
} }
type SeatID = string /**
* Seat rappresenta un posto in dipartimento in una certa stanza
*/
type Seat = { type Seat = {
id: SeatID id: SeatID
roomID: RoomID roomID: RoomID
@ -60,11 +88,13 @@ type Seat = {
height: Natural height: Natural
} }
// non mi piace questo nome // 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<User>"
getCurrentOccupant(): Maybe<UserID> getCurrentlyBookedUsers(): User[]
} }
type RoomID = string /**
* Room rappresenta una stanza in dipartimento e contiene dei posti
*/
type Room = { type Room = {
id: RoomID id: RoomID
seatIDs: SeatID[] seatIDs: SeatID[]
@ -73,6 +103,6 @@ type Room = {
gridCols: Natural gridCols: Natural
} }
getTotalSeatCount(): Natural getTotalSeatCount(): Natural // ".seatIDs.length"
getOccupiedSeatCount(): Natural getCurrentBookedSeatCount(): Natural
} }

@ -161,12 +161,12 @@ func NewInMemoryStore() Database {
db.users["aziis98"] = &User{ db.users["aziis98"] = &User{
ID: "aziis98", ID: "aziis98",
Permissions: util.NewSet[string](PermissionAdmin), Permissions: util.NewSet(PermissionAdmin),
} }
db.users["bachoseven"] = &User{ db.users["bachoseven"] = &User{
ID: "bachoseven", ID: "bachoseven",
Permissions: util.NewSet[string](PermissionAdmin), Permissions: util.NewSet(PermissionAdmin),
} }
return db return db

@ -149,7 +149,7 @@ func (db *memDB) GetRoomFreeSeats(roomID string) ([]string, error) {
func (db *memDB) GetUserSeats(userID string) (util.Set[string], error) { func (db *memDB) GetUserSeats(userID string) (util.Set[string], error) {
for _, seat := range db.seats { for _, seat := range db.seats {
if len(seat.OccupiedBy) > 0 && seat.OccupiedBy[0] == userID { if len(seat.OccupiedBy) > 0 && seat.OccupiedBy[0] == userID {
return util.NewSet[string](seat.ID), nil return util.NewSet(seat.ID), nil
} }
} }

Loading…
Cancel
Save