-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from FSW-AND-BINAR-BATCH-6/develop
[Soft Fix] fix bugs
- Loading branch information
Showing
50 changed files
with
1,565 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/kom/skyfly/data/datasource/tickets/TicketsDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
126
app/src/main/java/com/kom/skyfly/data/mapper/TicketsMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
app/src/main/java/com/kom/skyfly/data/model/tickets/AuthModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
app/src/main/java/com/kom/skyfly/data/model/tickets/FlightModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/kom/skyfly/data/model/tickets/ItemsTicketsModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
app/src/main/java/com/kom/skyfly/data/model/tickets/SeatModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/kom/skyfly/data/model/tickets/TicketTransactionModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/kom/skyfly/data/model/tickets/TicketsModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/kom/skyfly/data/model/tickets/TransactionDetailModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
app/src/main/java/com/kom/skyfly/data/model/tickets/UserModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/kom/skyfly/data/repository/tickets/TicketsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() } | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/kom/skyfly/data/source/network/model/tickets/Auth.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?, | ||
) |
Oops, something went wrong.