Skip to content

Commit

Permalink
Merge pull request #62 from FSW-AND-BINAR-BATCH-6/develop
Browse files Browse the repository at this point in the history
[Soft Fix] fix bugs
  • Loading branch information
YudaSaputraa authored Jul 1, 2024
2 parents 1adbb7a + b9b1d90 commit 847d763
Show file tree
Hide file tree
Showing 50 changed files with 1,565 additions and 257 deletions.
192 changes: 96 additions & 96 deletions README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name=".App"
android:allowBackup="true"
Expand All @@ -17,6 +18,9 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.ticket.TicketsActivity"
android:exported="false" />
<activity
android:name=".presentation.notificationdetail.NotificationDetailActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.kom.skyfly.data.datasource.tickets

import com.kom.skyfly.data.source.network.model.tickets.TicketsResponse
import com.kom.skyfly.data.source.network.services.SkyFlyApiService

/**
Written by Komang Yuda Saputra
Github : https://github.com/YudaSaputraa
**/
interface TicketsDataSource {
suspend fun getTicketById(id: String): TicketsResponse
}

class TicketsDataSourceImpl(private val service: SkyFlyApiService) :
TicketsDataSource {
override suspend fun getTicketById(id: String): TicketsResponse {
return service.getTicketsById(id)
}
}
126 changes: 126 additions & 0 deletions app/src/main/java/com/kom/skyfly/data/mapper/TicketsMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package com.kom.skyfly.data.mapper

import com.kom.skyfly.data.model.tickets.*
import com.kom.skyfly.data.source.network.model.tickets.*

/**
Written by Komang Yuda Saputra
Github : https://github.com/YudaSaputraa
**/
fun TicketsResponse?.toTicketsModel(): TicketsModel =
this?.let {
TicketsModel(
data = it.data.toItemsTicketsModelList(),
message = it.message.orEmpty(),
status = it.status ?: false,
)
} ?: TicketsModel(emptyList(), "", false)

fun List<ItemsTicketsResponse?>?.toItemsTicketsModelList(): List<ItemsTicketsModel> =
this?.mapNotNull { it.toItemsTicketsModel() } ?: emptyList()

fun ItemsTicketsResponse?.toItemsTicketsModel(): ItemsTicketsModel? =
this?.let {
ItemsTicketsModel(
code = it.code.orEmpty(),
flight = it.flight.toFlightModel(),
flightId = it.flightId.orEmpty(),
id = it.id.orEmpty(),
seatId = it.seatId.orEmpty(),
ticketTransaction = it.ticketTransaction.toTicketTransactionModel(),
ticketTransactionId = it.ticketTransactionId.orEmpty(),
user = it.user.toUserModel(),
userId = it.userId.orEmpty(),
)
}

fun Flight?.toFlightModel(): FlightModel? =
this?.let {
FlightModel(
arrivalDate = it.arrivalDate.orEmpty(),
capacity = it.capacity ?: 0,
code = it.code.orEmpty(),
departureAirportId = it.departureAirportId.orEmpty(),
departureDate = it.departureDate.orEmpty(),
destinationAirportId = it.destinationAirportId.orEmpty(),
discount = it.discount.orEmpty(),
facilities = it.facilities.orEmpty(),
id = it.id.orEmpty(),
planeId = it.planeId.orEmpty(),
price = it.price ?: 0,
transitAirportId = it.transitAirportId.orEmpty(),
transitArrivalDate = it.transitArrivalDate.orEmpty(),
transitDepartureDate = it.transitDepartureDate.orEmpty(),
)
}

fun Seat?.toSeatModel(): SeatModel? =
this?.let {
SeatModel(
flightId = it.flightId.orEmpty(),
id = it.id.orEmpty(),
price = it.price ?: 0,
seatNumber = it.seatNumber.orEmpty(),
status = it.status.orEmpty(),
type = it.type.orEmpty(),
)
}

fun TicketTransaction?.toTicketTransactionModel(): TicketTransactionModel? =
this?.let {
TicketTransactionModel(
bookingCode = it.bookingCode.orEmpty(),
bookingDate = it.bookingDate.orEmpty(),
id = it.id.orEmpty(),
orderId = it.orderId.orEmpty(),
status = it.status.orEmpty(),
tax = it.tax ?: 0,
totalPrice = it.totalPrice ?: 0,
transactionDetail = it.transactionDetail.toTransactionDetailModelList(),
userId = it.userId.orEmpty(),
)
}

fun List<TransactionDetail?>?.toTransactionDetailModelList(): List<TransactionDetailModel> =
this?.mapNotNull { it.toTransactionDetailModel() } ?: emptyList()

fun TransactionDetail?.toTransactionDetailModel(): TransactionDetailModel? =
this?.let {
TransactionDetailModel(
citizenship = it.citizenship.orEmpty(),
dob = it.dob.orEmpty(),
familyName = it.familyName.orEmpty(),
flightId = it.flightId.orEmpty(),
id = it.id.orEmpty(),
issuingCountry = it.issuingCountry.orEmpty(),
name = it.name.orEmpty(),
passport = it.passport.orEmpty(),
price = it.price ?: 0,
seatId = it.seatId.orEmpty(),
transactionId = it.transactionId.orEmpty(),
type = it.type.orEmpty(),
validityPeriod = it.validityPeriod.orEmpty(),
seat = it.seat.toSeatModel(),
)
}

fun Auth?.toAuthModel(): AuthModel? =
this?.let {
AuthModel(
email = it.email.orEmpty(),
id = it.id.orEmpty(),
isVerified = it.isVerified ?: false,
)
}

fun User?.toUserModel(): UserModel? =
this?.let {
UserModel(
auth = it.auth.toAuthModel(),
familyName = it.familyName.orEmpty(),
id = it.id.orEmpty(),
name = it.name.orEmpty(),
phoneNumber = it.phoneNumber.orEmpty(),
role = it.role.orEmpty(),
)
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/kom/skyfly/data/model/tickets/AuthModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class AuthModel(
val email: String?,
val id: String?,
val isVerified: Boolean?,
)
21 changes: 21 additions & 0 deletions app/src/main/java/com/kom/skyfly/data/model/tickets/FlightModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class FlightModel(
val arrivalDate: String?,
val capacity: Int?,
val code: String?,
val departureAirportId: String?,
val departureDate: String?,
val destinationAirportId: String?,
val discount: String?,
val facilities: String?,
val id: String?,
val planeId: String?,
val price: Int?,
val transitAirportId: String?,
val transitArrivalDate: String?,
val transitDepartureDate: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class ItemsTicketsModel(
val code: String?,
val flight: FlightModel?,
val flightId: String?,
val id: String?,
val seatId: String?,
val ticketTransaction: TicketTransactionModel?,
val ticketTransactionId: String?,
val user: UserModel?,
val userId: String?,
)
13 changes: 13 additions & 0 deletions app/src/main/java/com/kom/skyfly/data/model/tickets/SeatModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class SeatModel(
val flightId: String?,
val id: String?,
val price: Int?,
val seatNumber: String?,
val status: String?,
val type: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class TicketTransactionModel(
val bookingCode: String?,
val bookingDate: String?,
val id: String?,
val orderId: String?,
val status: String?,
val tax: Int?,
val totalPrice: Int?,
val transactionDetail: List<TransactionDetailModel?>?,
val userId: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class TicketsModel(
val data: List<ItemsTicketsModel?>,
val message: String?,
val status: Boolean?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class TransactionDetailModel(
val citizenship: String?,
val dob: String?,
val familyName: String?,
val flightId: String?,
val id: String?,
val issuingCountry: String?,
val name: String?,
val passport: String?,
val price: Int?,
val seatId: String?,
val transactionId: String?,
val type: String?,
val seat: SeatModel?,
val validityPeriod: String?,
)
13 changes: 13 additions & 0 deletions app/src/main/java/com/kom/skyfly/data/model/tickets/UserModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kom.skyfly.data.model.tickets

import androidx.annotation.Keep

@Keep
data class UserModel(
val auth: AuthModel?,
val familyName: String?,
val id: String?,
val name: String?,
val phoneNumber: String?,
val role: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.kom.skyfly.utils.ResultWrapper
import com.kom.skyfly.utils.proceedFlow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart
Expand All @@ -24,20 +25,31 @@ class AirportRepositoryImpl(
return flow {
emit(ResultWrapper.Loading())
val result = dataSource.getAllAirports(city = city).data.toAirports()
// delay(500)
emit(ResultWrapper.Success(result))
}
}

override fun createSearchDestinationHistory(searchDestinationHistory: String): Flow<ResultWrapper<Boolean>> {
return proceedFlow {
val affectedRows =
searchHistoryDataSource.insertSearchDestinationHistory(
SearchDestinationHistoryEntity(
searchDestinationHistory = searchDestinationHistory,
),
)
affectedRows > 0
// Fetch all existing search history entries
val existingHistory =
searchHistoryDataSource.getAllSearchDestinationHistory()
.first() // Get the first emission from the Flow

// Check if an entry with the same name already exists
val entryExists = existingHistory.any { it.searchDestinationHistory == searchDestinationHistory }

if (!entryExists) {
val affectedRows =
searchHistoryDataSource.insertSearchDestinationHistory(
SearchDestinationHistoryEntity(
searchDestinationHistory = searchDestinationHistory,
),
)
affectedRows > 0
} else {
false // No new entry created
}
}
}

Expand All @@ -52,14 +64,16 @@ class AirportRepositoryImpl(
override fun getUserSearchDestinationHistory(): Flow<ResultWrapper<List<SearchDestinationHistory>>> {
return searchHistoryDataSource.getAllSearchDestinationHistory()
.map { searchHistoryEntities ->
val searchHistoryList = searchHistoryEntities.toSearchDestinationHistoryList() // Handle nullable case
val searchHistoryList = searchHistoryEntities.toSearchDestinationHistoryList()
if (searchHistoryList != null) {
ResultWrapper.Success(searchHistoryList)
} else {
ResultWrapper.Empty()
}
}.onStart {
emit(ResultWrapper.Loading())
}.catch { e ->
emit(ResultWrapper.Error(Exception(e)))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.kom.skyfly.data.repository.tickets

import com.kom.skyfly.data.datasource.tickets.TicketsDataSource
import com.kom.skyfly.data.mapper.toTicketsModel
import com.kom.skyfly.data.model.tickets.TicketsModel
import com.kom.skyfly.utils.ResultWrapper
import com.kom.skyfly.utils.proceedFlow
import kotlinx.coroutines.flow.Flow

/**
Written by Komang Yuda Saputra
Github : https://github.com/YudaSaputraa
**/
interface TicketsRepository {
fun getTicketsById(id: String): Flow<ResultWrapper<TicketsModel>>
}

class TicketsRepositoryImpl(private val dataSource: TicketsDataSource) : TicketsRepository {
override fun getTicketsById(id: String): Flow<ResultWrapper<TicketsModel>> {
return proceedFlow { dataSource.getTicketById(id).toTicketsModel() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.kom.skyfly.data.source.network.model.tickets

import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName

@Keep
data class Auth(
@SerializedName("email")
val email: String?,
@SerializedName("id")
val id: String?,
@SerializedName("isVerified")
val isVerified: Boolean?,
)
Loading

0 comments on commit 847d763

Please sign in to comment.