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
//
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<UserID, User>
rooms: Map<RoomID, Room>
seats: Map<SeatID, Seat>
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 = {
id: UserID
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 = {
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<Booking>
}
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<UserID>
// 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>"
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
}

@ -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

@ -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
}
}

Loading…
Cancel
Save