Skip to main content

ReservationRepo

This interface defines the contract for managing reservation data. It provides methods for retrieving, creating, updating, and deleting reservation records based on various criteria.

Methods


Get()

@classmethod
def Get(
ctx: context.Context,
key: string
) - > *models.Reservation, error

Fetches a reservation by its unique key. Callers use this to retrieve specific reservation details.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the request, used for cancellation and deadlines.
keystringThe unique identifier for the reservation to retrieve.

Returns

TypeDescription
*models.Reservation, errorThe reservation object if found, otherwise an error.

Create()

@classmethod
def Create(
ctx: context.Context,
reservation: *models.Reservation
) - > error

Creates a new reservation in the repository. Callers use this to persist new reservation data.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the request, used for cancellation and deadlines.
reservation*models.ReservationThe reservation object to be created.

Returns

TypeDescription
errorAn error if the reservation could not be created, otherwise nil.

UpdateIfExpiredOrOwned()

@classmethod
def UpdateIfExpiredOrOwned(
ctx: context.Context,
reservation: *models.Reservation,
now: time.Time
) - > error

Updates an existing reservation only if it is expired or currently owned by the provided reservation's owner. Callers use this to modify reservations under specific conditions.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the request, used for cancellation and deadlines.
reservation*models.ReservationThe reservation object containing the updated data and owner information.
nowtime.TimeThe current time, used to check if the reservation has expired.

Returns

TypeDescription
errorAn error if the update conditions are not met or the update fails, otherwise nil.

DeleteByKeyAndOwner()

@classmethod
def DeleteByKeyAndOwner(
ctx: context.Context,
key: string,
ownerID: string
) - > error

Deletes a reservation identified by its key, but only if it is owned by the specified owner. Callers use this to remove reservations securely.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the request, used for cancellation and deadlines.
keystringThe unique identifier of the reservation to delete.
ownerIDstringThe ID of the owner who must own the reservation for it to be deleted.

Returns

TypeDescription
errorAn error if the reservation cannot be deleted (e.g., not found, owner mismatch), otherwise nil.