SHARE
TWEET

Untitled

a guest Jun 18th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class IsSeatBookedUseCase(
  2.   private val ticketService: TicketService
  3. ) {
  4.  
  5.   fun execute(request: Request): Observable<Result<Boolean>> {
  6.     return ticketService.isSeatAlloted(request.seatNumber)
  7.       .concatMap { it.toDataObservable() }
  8.       .concatMap {
  9.         when (it) {
  10.           false -> it.toResult().toObservable()
  11.           true -> SEAT_ALREADY_BOOKED_ERROR.toResult<Boolean>().toObservable()
  12.         }
  13.       }
  14.       .onErrorReturn { it.toErrorResult() }
  15.   }
  16.  
  17.   class Request(
  18.     val seatNumber: String
  19.   )
  20.  
  21.   companion object {
  22.     val SEAT_ALREADY_BOOKED_ERROR = Error(103, "This seat is already booked")
  23.   }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top