Skip to content

Commit

Permalink
[AN/USER] feat: 재학생, 방문객 영문 값 한글로 번역(#345) (#521)
Browse files Browse the repository at this point in the history
* feat: ticket type 상수 생성

* feat: TicketType 도메인 객체 생성

* feat: 티켓 타입 전달 객체 생성

* refactor: 티켓 타입이 string 으로 번역되도록 변경

* feat: ReservationTickets 정의

* feat: Response 가 ReservationTickets 를 반환한다

* refactor: 레포지토리에서 ReservationTickets 로 도매인 객체로 반환

* refactor: 티켓 타입이 정렬되게 변경

* fix: Response 타입 맞추기

* feat: 축제 상세 보기 실패 상수 의미 변경

* refactor: 테스트 코드 객체 포장 제거

* refactor: ReservationTickets 캡슐화
  • Loading branch information
SeongHoonC authored Oct 11, 2023
1 parent 251babc commit 73666ec
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festago.data.dto

import com.festago.festago.model.ReservationStage
import com.festago.festago.model.ReservationTickets
import kotlinx.serialization.Serializable
import java.time.LocalDateTime

Expand All @@ -17,6 +18,10 @@ data class ReservationStageResponse(
lineUp = lineUp,
startTime = LocalDateTime.parse(startTime),
ticketOpenTime = LocalDateTime.parse(ticketOpenTime),
reservationTickets = tickets.map { it.toDomain() },
reservationTickets = tickets.toDomain(),
)

private fun List<ReservationTicketResponse>.toDomain() = ReservationTickets(
this.map { it.toDomain() },
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festago.data.dto

import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.TicketType
import kotlinx.serialization.Serializable

@Serializable
Expand All @@ -12,8 +13,16 @@ data class ReservationTicketResponse(
) {
fun toDomain(): ReservationTicket = ReservationTicket(
id = id,
ticketType = ticketType,
ticketType = convertToTicketType(ticketType),
totalAmount = totalAmount,
remainAmount = remainAmount,
)

private fun convertToTicketType(ticketType: String): TicketType {
return when (ticketType) {
"STUDENT" -> TicketType.STUDENT
"VISITOR" -> TicketType.VISITOR
else -> TicketType.OTHER
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.festago.festago.data.dto

import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservationTickets
import kotlinx.serialization.Serializable

@Serializable
data class ReservationTicketsResponse(
val tickets: List<ReservationTicketResponse>,
) {
fun toDomain(): List<ReservationTicket> = tickets.map { it.toDomain() }
fun toDomain(): ReservationTickets = ReservationTickets(
tickets.map { it.toDomain() },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.festago.festago.data.repository
import com.festago.festago.data.service.ReservationTicketRetrofitService
import com.festago.festago.data.util.onSuccessOrCatch
import com.festago.festago.data.util.runCatchingResponse
import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservationTickets
import com.festago.festago.repository.ReservationTicketRepository
import javax.inject.Inject

class ReservationTicketDefaultRepository @Inject constructor(
private val reservationTicketRetrofitService: ReservationTicketRetrofitService,
) : ReservationTicketRepository {

override suspend fun loadTicketTypes(stageId: Int): Result<List<ReservationTicket>> =
override suspend fun loadTicketTypes(stageId: Int): Result<ReservationTickets> =
runCatchingResponse { reservationTicketRetrofitService.getReservationTickets(stageId) }
.onSuccessOrCatch { it.toDomain() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.festago.festago.presentation.ui.ticketreserve.TicketReserveEvent.Show
import com.festago.festago.presentation.ui.ticketreserve.adapter.TicketReserveAdapter
import com.festago.festago.presentation.ui.ticketreserve.adapter.TicketReserveHeaderAdapter
import com.festago.festago.presentation.ui.ticketreserve.bottomsheet.BottomSheetReservationTicketArg
import com.festago.festago.presentation.ui.ticketreserve.bottomsheet.BottomSheetTicketTypeArg
import com.festago.festago.presentation.ui.ticketreserve.bottomsheet.TicketReserveBottomSheetFragment
import com.festago.festago.presentation.util.repeatOnStarted
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -93,7 +94,7 @@ class TicketReserveActivity : AppCompatActivity() {
BottomSheetReservationTicketArg(
id = it.id,
remainAmount = it.remainAmount,
ticketType = it.ticketType,
ticketType = BottomSheetTicketTypeArg.from(it.ticketType),
totalAmount = it.totalAmount,
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class TicketReserveViewModel @Inject constructor(
viewModelScope.launch {
if (authRepository.isSigned) {
reservationTicketRepository.loadTicketTypes(stageId)
.onSuccess { tickets ->
.onSuccess { reservationTickets ->
_event.emit(
TicketReserveEvent.ShowTicketTypes(
stageStartTime,
tickets,
reservationTickets.sortedByTicketTypes(),
),
)
}.onFailure {
Expand Down Expand Up @@ -95,7 +95,7 @@ class TicketReserveViewModel @Inject constructor(
lineUp = lineUp,
startTime = startTime,
ticketOpenTime = ticketOpenTime,
reservationTickets = reservationTickets,
reservationTickets = reservationTickets.sortedByTicketTypes(),
canReserve = LocalDateTime.now().isAfter(ticketOpenTime),
isSigned = authRepository.isSigned,
onShowStageTickets = ::showTicketTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import kotlinx.parcelize.Parcelize
data class BottomSheetReservationTicketArg(
val id: Int,
val remainAmount: Int,
val ticketType: String,
val ticketType: BottomSheetTicketTypeArg,
val totalAmount: Int,
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.festago.festago.presentation.ui.ticketreserve.bottomsheet

import android.os.Parcelable
import com.festago.festago.model.TicketType
import kotlinx.parcelize.Parcelize

@Parcelize
enum class BottomSheetTicketTypeArg : Parcelable {
STUDENT, VISITOR, OTHER
;

companion object {
fun from(ticketType: TicketType): BottomSheetTicketTypeArg = when (ticketType) {
TicketType.STUDENT -> STUDENT
TicketType.VISITOR -> VISITOR
TicketType.OTHER -> OTHER
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.festago.festago.presentation.ui.ticketreserve.bottomsheet
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.festago.festago.R
import com.festago.festago.databinding.ItemTicketReserveBottomSheetBinding

class TicketReserveBottomViewHolder(
Expand All @@ -17,6 +18,16 @@ class TicketReserveBottomViewHolder(
fun bind(item: TicketReserveBottomItem) {
binding.item = item
binding.clLayout.isSelected = item.isSelected
binding.tvTicketType.text = item.ticket.ticketType.getString()
}

private fun BottomSheetTicketTypeArg.getString(): String {
val resId: Int = when (this) {
BottomSheetTicketTypeArg.STUDENT -> R.string.all_ticket_type_student
BottomSheetTicketTypeArg.VISITOR -> R.string.all_ticket_type_visitor
BottomSheetTicketTypeArg.OTHER -> R.string.all_ticket_type_other
}
return binding.root.context.getString(resId)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.festago.festago.R
import com.festago.festago.databinding.ItemTicketReserveBinding
import com.festago.festago.model.TicketType
import com.festago.festago.presentation.ui.ticketreserve.TicketReserveItemUiState
import java.time.format.DateTimeFormatter

Expand Down Expand Up @@ -39,13 +40,22 @@ class TicketReserveViewHolder(
item.reservationTickets.joinToString(binding.root.context.getString(R.string.ticket_reserve_tv_ticket_count_separator)) {
binding.root.context.getString(
R.string.ticket_reserve_tv_ticket_count,
it.ticketType,
it.ticketType.getString(),
it.remainAmount.toString(),
it.totalAmount.toString(),
)
}
}

private fun TicketType.getString(): String {
val resId: Int = when (this) {
TicketType.STUDENT -> R.string.all_ticket_type_student
TicketType.VISITOR -> R.string.all_ticket_type_visitor
TicketType.OTHER -> R.string.all_ticket_type_other
}
return binding.root.context.getString(resId)
}

companion object {
fun from(parent: ViewGroup): TicketReserveViewHolder {
val binding = ItemTicketReserveBinding.inflate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
android:id="@+id/tvTicketType"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@{item.ticket.ticketType}"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
Expand Down
8 changes: 6 additions & 2 deletions android/festago/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<string name="all_ticket_state_after_entry">입장완료</string>
<string name="all_ticket_state_away">외출중</string>

<!--ticket type-->
<string name="all_ticket_type_student">재학생용</string>
<string name="all_ticket_type_visitor">방문객용</string>
<string name="all_ticket_type_other">기타</string>

<!-- Strings related to main -->
<string name="main_btn_ticket_disable_time">HH:mm 티켓 활성화</string>
<string name="main_btn_ticket_enable_time">티켓 제시</string>
Expand Down Expand Up @@ -37,14 +42,13 @@
<string name="ticket_reserve_tv_ticket_count">%1$s(%2$s/%3$s)</string>
<string name="ticket_reserve_tv_ticket_count_separator">", "</string>
<string name="ticket_reserve_tv_auth_guide_student">⚠️ 재학생용 티켓예매를 위해 사전에 학교 인증이 필요합니다.</string>
<string name="ticket_reserve_tv_error_page">예매 가능한 티켓이 없습니다.</string>
<string name="ticket_reserve_tv_error_page">축제 조회에 실패했습니다.</string>
<string name="ticket_reserve_btn_reserve_ticket">티켓 예매</string>
<string name="ticket_reserve_tv_ticket_count_format">(%1$s/%2$s)</string>
<string name="ticket_reserve_tv_btn_reserve_ticket">예매 하기</string>
<string name="ticket_reserve_tv_btn_reserve_ticket_not_open">MM월 dd일 HH:mm 오픈예정</string>
<string name="ticket_reserve_tv_signin">로그인 후 예매</string>


<!-- Strings related to festival list -->
<string name="festival_list_tv_date_format">yyyy.MM.dd</string>
<string name="festival_list_chip_ongoing">진행중</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ class ReservationTicketRetrofitServiceTest {
startTime = "2023-07-09T16:00:00",
ticketOpenTime = "2023-07-08T14:00:00",
lineUp = "르세라핌,아이브,뉴진스",
tickets = listOf(
tickets =
listOf(
ReservationTicketResponse(
id = 1,
ticketType = "STUDENT",
Expand All @@ -211,14 +212,16 @@ class ReservationTicketRetrofitServiceTest {
totalAmount = 300,
remainAmount = 212,
),

),
),
ReservationStageResponse(
id = 2,
startTime = "2023-07-09T16:00:00",
ticketOpenTime = "2023-07-08T14:00:00",
lineUp = "르세라핌,아이브,뉴진스",
tickets = listOf(
tickets =
listOf(
ReservationTicketResponse(
id = 3,
ticketType = "STUDENT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.festago.festago.analytics.AnalyticsHelper
import com.festago.festago.model.Reservation
import com.festago.festago.model.ReservationStage
import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservationTickets
import com.festago.festago.model.ReservedTicket
import com.festago.festago.model.TicketType
import com.festago.festago.repository.AuthRepository
import com.festago.festago.repository.FestivalRepository
import com.festago.festago.repository.ReservationTicketRepository
Expand Down Expand Up @@ -35,9 +37,11 @@ class TicketReserveViewModelTest {
private lateinit var authRepository: AuthRepository
private lateinit var analyticsHelper: AnalyticsHelper

private val fakeReservationTickets = listOf(
ReservationTicket(1, "재학생용", 219, 500),
ReservationTicket(1, "외부인용", 212, 300),
private val fakeReservationTickets = ReservationTickets(
listOf(
ReservationTicket(1, TicketType.STUDENT, 219, 500),
ReservationTicket(1, TicketType.VISITOR, 212, 300),
),
)
private val fakeReservationStage = ReservationStage(
id = 1,
Expand Down Expand Up @@ -94,7 +98,7 @@ class TicketReserveViewModelTest {
coEvery { authRepository.isSigned } answers { isSigned }
}

private fun `특정 공연의 티켓 타입 요청 결과가 다음과 같을 때`(result: Result<List<ReservationTicket>>) {
private fun `특정 공연의 티켓 타입 요청 결과가 다음과 같을 때`(result: Result<ReservationTickets>) {
coEvery { reservationTicketRepository.loadTicketTypes(any()) } returns result
}

Expand Down Expand Up @@ -172,7 +176,7 @@ class TicketReserveViewModelTest {

// and
val actual = (event as? TicketReserveEvent.ShowTicketTypes)?.tickets
assertThat(actual).isEqualTo(fakeReservationTickets)
assertThat(actual).isEqualTo(fakeReservationTickets.sortedByTicketTypes())
}
softly.assertAll()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ data class ReservationStage(
val lineUp: String,
val startTime: LocalDateTime,
val ticketOpenTime: LocalDateTime,
val reservationTickets: List<ReservationTicket>,
val reservationTickets: ReservationTickets,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.festago.festago.model

data class ReservationTicket(
val id: Int,
val ticketType: String,
val ticketType: TicketType,
val remainAmount: Int,
val totalAmount: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.festago.festago.model

class ReservationTickets(private val tickets: List<ReservationTicket>) {

fun sortedByTicketTypes(): List<ReservationTicket> {
val ticketTypes = TicketType.values().toList()
return tickets.sortedBy { ticketTypes.indexOf(it.ticketType) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.festago.festago.model

enum class TicketType {
STUDENT, VISITOR, OTHER
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.festago.festago.repository

import com.festago.festago.model.ReservationTicket
import com.festago.festago.model.ReservationTickets

interface ReservationTicketRepository {
suspend fun loadTicketTypes(stageId: Int): Result<List<ReservationTicket>>
suspend fun loadTicketTypes(stageId: Int): Result<ReservationTickets>
}

0 comments on commit 73666ec

Please sign in to comment.