-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…at-search-api
- Loading branch information
Showing
22 changed files
with
915 additions
and
9 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/korailtalk/data/mapper/todata/TicketBuyingMapper.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.sopt.korailtalk.data.mapper.todata | ||
|
||
import com.sopt.korailtalk.data.remote.model.request.TicketBuyingRequestDto | ||
import com.sopt.korailtalk.domain.model.TicketBuying | ||
|
||
fun TicketBuying.toData(): TicketBuyingRequestDto = TicketBuyingRequestDto( | ||
ticketId = this.ticketId, | ||
totalPrice = this.totalPrice, | ||
usedPoint = this.usedPoint | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/sopt/korailtalk/data/mapper/todomain/LPointResponseDtoMapper.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,9 @@ | ||
package com.sopt.korailtalk.data.mapper.todomain | ||
|
||
import com.sopt.korailtalk.data.remote.model.response.LPointResponseDto | ||
import com.sopt.korailtalk.domain.model.LPoint | ||
|
||
fun LPointResponseDto.toDomain(): LPoint = LPoint( | ||
isValid = this.isValid, | ||
point = this.point | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/korailtalk/data/remote/datasource/PaymentRemoteDataSource.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.sopt.korailtalk.data.remote.datasource | ||
|
||
import com.sopt.korailtalk.data.remote.model.base.ApiResponse | ||
import com.sopt.korailtalk.data.remote.model.request.TicketBuyingRequestDto | ||
import com.sopt.korailtalk.data.remote.model.response.LPointResponseDto | ||
|
||
interface PaymentRemoteDataSource { | ||
suspend fun getLpoint(userId: Long, pointPassword: Int): ApiResponse<LPointResponseDto> | ||
suspend fun buyTicket(ticketBuyingRequestDto: TicketBuyingRequestDto): ApiResponse<Unit> | ||
} |
16 changes: 16 additions & 0 deletions
16
...c/main/java/com/sopt/korailtalk/data/remote/datasourceimpl/PaymentRemoteDataSourceImpl.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.sopt.korailtalk.data.remote.datasourceimpl | ||
|
||
import com.sopt.korailtalk.data.remote.datasource.PaymentRemoteDataSource | ||
import com.sopt.korailtalk.data.remote.model.request.TicketBuyingRequestDto | ||
import com.sopt.korailtalk.data.remote.service.PaymentService | ||
import javax.inject.Inject | ||
|
||
class PaymentRemoteDataSourceImpl @Inject constructor( | ||
private val paymentService: PaymentService | ||
) : PaymentRemoteDataSource { | ||
override suspend fun getLpoint(userId: Long, pointPassword: Int) = | ||
paymentService.getLpoint(userId, pointPassword) | ||
|
||
override suspend fun buyTicket(ticketBuyingRequestDto: TicketBuyingRequestDto) = | ||
paymentService.buyTicket(ticketBuyingRequestDto) | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/com/sopt/korailtalk/data/remote/model/request/TicketBuyingRequestDto.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,11 @@ | ||
package com.sopt.korailtalk.data.remote.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class TicketBuyingRequestDto( | ||
@SerialName("ticketId") val ticketId: Long, | ||
@SerialName("totalPrice") val totalPrice: Int, | ||
@SerialName("usedPoint") val usedPoint: Int | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/korailtalk/data/remote/model/response/LPointResponseDto.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.sopt.korailtalk.data.remote.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LPointResponseDto( | ||
@SerialName("isValid") val isValid: Boolean, | ||
@SerialName("point") val point: Int | ||
) |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/sopt/korailtalk/data/remote/service/PaymentService.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,23 @@ | ||
package com.sopt.korailtalk.data.remote.service | ||
|
||
import com.sopt.korailtalk.data.remote.model.base.ApiResponse | ||
import com.sopt.korailtalk.data.remote.model.request.TicketBuyingRequestDto | ||
import com.sopt.korailtalk.data.remote.model.response.LPointResponseDto | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.PATCH | ||
import retrofit2.http.Query | ||
|
||
interface PaymentService { | ||
@GET("/users/points") | ||
suspend fun getLpoint( | ||
@Header("userId") userId: Long, | ||
@Query("pointPassword") pointPassword: Int | ||
): ApiResponse<LPointResponseDto> | ||
|
||
@PATCH("/tickets") | ||
suspend fun buyTicket( | ||
@Body ticketBuyingRequestDto: TicketBuyingRequestDto | ||
): ApiResponse<Unit> | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/sopt/korailtalk/data/repositoryimpl/PaymentRepositoryImpl.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,27 @@ | ||
package com.sopt.korailtalk.data.repositoryimpl | ||
|
||
import com.sopt.korailtalk.data.mapper.todata.toData | ||
import com.sopt.korailtalk.data.mapper.todomain.toDomain | ||
import com.sopt.korailtalk.data.remote.datasource.PaymentRemoteDataSource | ||
import com.sopt.korailtalk.data.remote.util.handleApiResponse | ||
import com.sopt.korailtalk.domain.model.LPoint | ||
import com.sopt.korailtalk.domain.model.TicketBuying | ||
import com.sopt.korailtalk.domain.repository.PaymentRepository | ||
import javax.inject.Inject | ||
|
||
class PaymentRepositoryImpl @Inject constructor( | ||
private val paymentRemoteDataSource: PaymentRemoteDataSource | ||
) : PaymentRepository { | ||
override suspend fun getLpoint(userId: Long, pointPassword: Int): Result<LPoint> { | ||
return runCatching { | ||
paymentRemoteDataSource.getLpoint(userId = userId, pointPassword = pointPassword) | ||
.handleApiResponse().getOrThrow().toDomain() | ||
} | ||
} | ||
|
||
override suspend fun buyTicket(ticketBuying: TicketBuying): Result<Unit> { | ||
return runCatching { | ||
paymentRemoteDataSource.buyTicket(ticketBuyingRequestDto = ticketBuying.toData()) | ||
} | ||
} | ||
} |
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
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
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
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
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
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,6 @@ | ||
package com.sopt.korailtalk.domain.model | ||
|
||
data class LPoint( | ||
val isValid: Boolean, | ||
val point: Int, | ||
) |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopt/korailtalk/domain/model/TicketBuying.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,7 @@ | ||
package com.sopt.korailtalk.domain.model | ||
|
||
data class TicketBuying ( | ||
val ticketId: Long, | ||
val totalPrice: Int, | ||
val usedPoint: Int, | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/sopt/korailtalk/domain/repository/PaymentRepository.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,9 @@ | ||
package com.sopt.korailtalk.domain.repository | ||
|
||
import com.sopt.korailtalk.domain.model.LPoint | ||
import com.sopt.korailtalk.domain.model.TicketBuying | ||
|
||
interface PaymentRepository { | ||
suspend fun getLpoint(userId: Long, pointPassword: Int): Result<LPoint> | ||
suspend fun buyTicket(ticketBuying: TicketBuying): Result<Unit> | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/sopt/korailtalk/presentation/ui/payment/LPointState.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.sopt.korailtalk.presentation.ui.payment | ||
|
||
import com.sopt.korailtalk.domain.model.LPoint | ||
|
||
sealed class LPointState { | ||
data object Idle: LPointState() | ||
data object Loading: LPointState() | ||
data class Success(val data: LPoint): LPointState() | ||
data class Failure(val message: String): LPointState() | ||
} |
Oops, something went wrong.