Skip to content

Commit

Permalink
feat: 무료 티켓 예매 중 품절 케이스 대응
Browse files Browse the repository at this point in the history
  • Loading branch information
mangbaam committed May 7, 2024
1 parent f452ee6 commit d2fbf7a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.nexters.boolti.data.network.request.ReservationInviteTicketRequest
import com.nexters.boolti.data.network.request.ReservationSalesTicketRequest
import com.nexters.boolti.data.network.response.ApprovePaymentResponse
import com.nexters.boolti.data.network.response.CheckInviteCodeResponse
import com.nexters.boolti.data.network.response.ReservationDto
import com.nexters.boolti.domain.model.TicketWithQuantity
import com.nexters.boolti.domain.model.TicketingInfo
import com.nexters.boolti.domain.request.CheckInviteCodeRequest
Expand Down Expand Up @@ -33,12 +34,12 @@ internal class TicketingDataSource @Inject constructor(
).toDomain()
}

suspend fun requestReservationSalesTicket(request: ReservationSalesTicketRequest): String {
return ticketingService.requestReservationSalesTicket(request).reservationId
suspend fun requestReservationSalesTicket(request: ReservationSalesTicketRequest): Response<ReservationDto> {
return ticketingService.requestReservationSalesTicket(request)
}

suspend fun requestReservationInviteTicket(request: ReservationInviteTicketRequest): String {
return ticketingService.requestReservationInviteTicket(request).reservationId
suspend fun requestReservationInviteTicket(request: ReservationInviteTicketRequest): Response<ReservationDto> {
return ticketingService.requestReservationInviteTicket(request)
}

suspend fun checkInviteCode(request: CheckInviteCodeRequest): Response<CheckInviteCodeResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import com.nexters.boolti.data.network.response.OrderIdDto
import com.nexters.boolti.data.network.response.ReservationDto
import com.nexters.boolti.data.network.response.SalesTicketTypeDto
import com.nexters.boolti.data.network.response.TicketingInfoDto
import com.nexters.boolti.domain.request.PaymentCancelRequest
import com.nexters.boolti.domain.request.OrderIdRequest
import com.nexters.boolti.domain.request.PaymentApproveRequest
import com.nexters.boolti.domain.request.PaymentCancelRequest
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
Expand All @@ -34,12 +34,12 @@ internal interface TicketingService {
@POST("/app/api/v1/reservation/sales-ticket")
suspend fun requestReservationSalesTicket(
@Body request: ReservationSalesTicketRequest,
): ReservationDto
): Response<ReservationDto>

@POST("/app/api/v1/reservation/invite-ticket")
suspend fun requestReservationInviteTicket(
@Body request: ReservationInviteTicketRequest,
): ReservationDto
): Response<ReservationDto>

@GET("/app/api/v1/check/invite-code")
suspend fun checkInviteCode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ internal class TicketingRepositoryImpl @Inject constructor(
is TicketingRequest.Invite -> dataSource.requestReservationInviteTicket(request.toData())
is TicketingRequest.Free -> dataSource.requestReservationSalesTicket(request.toData())
}
emit(response)
if (response.isSuccessful) {
response.body()?.reservationId?.let { emit(it) }
} else {
val errMsg = response.errorBody()?.string()
throw TicketingException(TicketingErrorType.fromString(errMsg?.errorType))
}
}

override fun checkInviteCode(request: CheckInviteCodeRequest): Flow<InviteCodeStatus> = flow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.nexters.boolti.presentation.screen.ticketing
sealed interface TicketingEvent {
data class TicketingSuccess(val reservationId: String, val showId: String) : TicketingEvent
data class ProgressPayment(val userId: String, val orderId: String) : TicketingEvent
data object NoRemainingQuantity : TicketingEvent
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ fun TicketingScreen(
)
showConfirmDialog = false
}

is TicketingEvent.NoRemainingQuantity -> {
showConfirmDialog = false
showTicketSoldOutDialog = true
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.nexters.boolti.presentation.screen.ticketing

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.nexters.boolti.domain.exception.TicketingErrorType
import com.nexters.boolti.domain.exception.TicketingException
import com.nexters.boolti.domain.model.InviteCodeStatus
import com.nexters.boolti.domain.repository.TicketingRepository
import com.nexters.boolti.domain.request.CheckInviteCodeRequest
Expand Down Expand Up @@ -103,7 +105,20 @@ class TicketingViewModel @Inject constructor(
reservationName = uiState.value.reservationName,
reservationPhoneNumber = uiState.value.reservationContact,
)
repository.requestReservation(request).singleOrNull()?.let { reservationId ->
repository.requestReservation(request)
.catch { e ->
if (e !is TicketingException) throw e
if (
e.errorType in listOf(
TicketingErrorType.NoRemainingQuantity,
TicketingErrorType.ApprovePaymentFailed,
TicketingErrorType.Unknown,
)
) {
event(TicketingEvent.NoRemainingQuantity)
}
}
.singleOrNull()?.let { reservationId ->
event(TicketingEvent.TicketingSuccess(reservationId, showId))
}
}
Expand Down

0 comments on commit d2fbf7a

Please sign in to comment.