Skip to content

Commit

Permalink
refactor: ReservationTicketUiModel 사용하지 않도록 리팩터링
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyCh0 committed Sep 1, 2023
1 parent 683f361 commit 548b064
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.ConcatAdapter
import com.festago.festago.R
import com.festago.festago.databinding.ActivityTicketReserveBinding
import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservedTicket
import com.festago.festago.presentation.model.ReservationTicketUiModel
import com.festago.festago.presentation.ui.FestagoViewModelFactory
import com.festago.festago.presentation.ui.customview.OkDialogFragment
import com.festago.festago.presentation.ui.reservationcomplete.ReservationCompleteActivity
Expand Down Expand Up @@ -63,7 +63,7 @@ class TicketReserveActivity : AppCompatActivity() {
private fun handleEvent(event: TicketReserveEvent) = when (event) {
is ShowTicketTypes -> handleShowTicketTypes(
stageStartTime = event.stageStartTime,
tickets = event.tickets,
reservationTickets = event.tickets,
)

is ReserveTicketSuccess -> handleReserveTicketSuccess(event.reservedTicket)
Expand All @@ -73,7 +73,7 @@ class TicketReserveActivity : AppCompatActivity() {

private fun handleShowTicketTypes(
stageStartTime: LocalDateTime,
tickets: List<ReservationTicketUiModel>,
reservationTickets: List<ReservationTicket>,
) {
TicketReserveBottomSheetFragment.newInstance(
stageStartTime.format(
Expand All @@ -82,7 +82,14 @@ class TicketReserveActivity : AppCompatActivity() {
Locale.KOREA,
),
),
tickets,
reservationTickets.map {
ReservationTicketArg(
id = it.id,
remainAmount = it.remainAmount,
ticketType = it.ticketType,
totalAmount = it.totalAmount
)
},
).show(supportFragmentManager, TicketReserveBottomSheetFragment::class.java.name)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.festago.festago.presentation.ui.ticketreserve

import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservedTicket
import com.festago.festago.presentation.model.ReservationTicketUiModel
import java.time.LocalDateTime

sealed interface TicketReserveEvent {
class ShowTicketTypes(
val stageStartTime: LocalDateTime,
val tickets: List<ReservationTicketUiModel>,
val tickets: List<ReservationTicket>,
) : TicketReserveEvent

class ReserveTicketSuccess(val reservedTicket: ReservedTicket) : TicketReserveEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.festago.festago.presentation.ui.ticketreserve

import android.os.Parcelable
import com.festago.festago.presentation.model.ReservationTicketUiModel
import kotlinx.parcelize.Parcelize
import com.festago.festago.model.ReservationTicket
import java.time.LocalDateTime

@Parcelize
data class TicketReserveItemUiState(
val id: Int,
val lineUp: String,
val startTime: LocalDateTime,
val ticketOpenTime: LocalDateTime,
val reservationTickets: List<ReservationTicketUiModel>,
val reservationTickets: List<ReservationTicket>,
val canReserve: Boolean,
val isSigned: Boolean,
val onShowStageTickets: (stageId: Int, stageStartTime: LocalDateTime) -> Unit,
) : Parcelable
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.lifecycle.viewModelScope
import com.festago.festago.analytics.AnalyticsHelper
import com.festago.festago.analytics.logNetworkFailure
import com.festago.festago.model.ReservationStage
import com.festago.festago.presentation.mapper.toPresentation
import com.festago.festago.presentation.util.MutableSingleLiveData
import com.festago.festago.presentation.util.SingleLiveData
import com.festago.festago.repository.AuthRepository
Expand Down Expand Up @@ -65,7 +64,7 @@ class TicketReserveViewModel(
_event.setValue(
TicketReserveEvent.ShowTicketTypes(
stageStartTime,
tickets.map { it.toPresentation() },
tickets,
),
)
}.onFailure {
Expand Down Expand Up @@ -93,7 +92,7 @@ class TicketReserveViewModel(
lineUp = lineUp,
startTime = startTime,
ticketOpenTime = ticketOpenTime,
reservationTickets = reservationTickets.map { it.toPresentation() },
reservationTickets = reservationTickets,
canReserve = LocalDateTime.now().isAfter(ticketOpenTime),
isSigned = authRepository.isSigned,
onShowStageTickets = ::showTicketTypes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.festago.festago.presentation.ui.ticketreserve.bottomsheet

import com.festago.festago.presentation.model.ReservationTicketUiModel
import com.festago.festago.presentation.ui.ticketreserve.ReservationTicketArg

data class TicketReserveBottomItem(
val ticket: ReservationTicketUiModel,
val ticket: ReservationTicketArg,
val isSelected: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.ViewModelProvider
import com.festago.festago.databinding.FragmentTicketReserveBottomSheetBinding
import com.festago.festago.presentation.model.ReservationTicketUiModel
import com.festago.festago.presentation.ui.ticketreserve.ReservationTicketArg
import com.festago.festago.presentation.ui.ticketreserve.TicketReserveViewModel
import com.festago.festago.presentation.util.getParcelableArrayListCompat
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
Expand Down Expand Up @@ -44,7 +44,7 @@ class TicketReserveBottomSheetFragment : BottomSheetDialogFragment() {
getString(KEY_STAGE_START_TIME)?.let { startTime ->
binding.stageStartTime = startTime
}
getParcelableArrayListCompat<ReservationTicketUiModel>(KEY_ITEMS)?.let {
getParcelableArrayListCompat<ReservationTicketArg>(KEY_ITEMS)?.let {
ticketTypeAdapter.submitList(it.map(::TicketReserveBottomItem))
}
}
Expand All @@ -69,7 +69,7 @@ class TicketReserveBottomSheetFragment : BottomSheetDialogFragment() {

fun newInstance(
stageStartTime: String,
items: List<ReservationTicketUiModel>,
items: List<ReservationTicketArg>,
) = TicketReserveBottomSheetFragment().apply {
arguments = Bundle().apply {
putString(KEY_STAGE_START_TIME, stageStartTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.festago.festago.model.Reservation
import com.festago.festago.model.ReservationStage
import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservedTicket
import com.festago.festago.presentation.mapper.toPresentation
import com.festago.festago.repository.AuthRepository
import com.festago.festago.repository.FestivalRepository
import com.festago.festago.repository.ReservationTicketRepository
Expand Down Expand Up @@ -166,7 +165,7 @@ class TicketReserveViewModelTest {

// and
val event = vm.event.getValue() as TicketReserveEvent.ShowTicketTypes
assertThat(event.tickets).isEqualTo(fakeReservationTickets.map { it.toPresentation() })
assertThat(event.tickets).isEqualTo(fakeReservationTickets)
}

@Test
Expand Down

0 comments on commit 548b064

Please sign in to comment.