Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#21] "열차조회 뷰" api 연동 #25

Merged
merged 16 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4cf9259
[feat/#15] 결제하기 화면의 기본 UI를 구성합니다.
SYAAINN Nov 26, 2024
ebf87bb
[chore/#15] 단위 유무에 따라 힌트의 색상을 다르게 조정합니다.
SYAAINN Nov 26, 2024
45c3398
[feat/#15] 할인 세부 UI를 구현합니다.
SYAAINN Nov 26, 2024
780130d
[feat/#15] 결제수단 선택 세부 UI를 구현합니다.
SYAAINN Nov 26, 2024
f32ed45
[feat/#15] 결제하기 서버통신을 위한 Service 인터페이스와 Dto를 정의합니다.
SYAAINN Nov 28, 2024
d91aca0
[feat/#15] Service를 바탕으로 DataSource를 구현합니다.
SYAAINN Nov 28, 2024
e8e5554
[feat/#15] DataSource를 바탕으로 Repository 인터페이스를 정의합니다.
SYAAINN Nov 28, 2024
90965c6
[feat/#15] domain layer과 data layer의 의존성을 보장해줄 model과 mapper를 구현합니다.
SYAAINN Nov 28, 2024
f71d242
[feat/#15] Repository 인터페이스의 구현체를 구현합니다.
SYAAINN Nov 28, 2024
f434c6e
[feat/#15] 의존성 주입에 대한 파일들을 정의합니다.
SYAAINN Nov 28, 2024
ade56e6
[feat/#15] 의존성 주입에 대한 파일들을 정의합니다.
SYAAINN Nov 28, 2024
90de28c
[feat/#15] 서버통신의 상태를 담을 State를 정의합니다.
SYAAINN Nov 28, 2024
97f98bb
Merge remote-tracking branch 'origin/#15/feat-payment-ui' into #21/fe…
gitsuhyun Nov 28, 2024
4762b89
[feat/#21] trainSearch api 연동 로직 추가
gitsuhyun Nov 28, 2024
8b31415
[refactor/#21] timetable domain model 변경
gitsuhyun Nov 29, 2024
9ab62b9
Merge branch 'develop' into #21/feat-search-api
SYAAINN Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
)
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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.sopt.korailtalk.data.mapper.todomain

import com.sopt.korailtalk.data.remote.model.response.TrainSearchResponseDto
import com.sopt.korailtalk.domain.model.TimeTable
import com.sopt.korailtalk.domain.model.TimeTables

fun TrainSearchResponseDto.toDomain(): TimeTables {
return TimeTables(
timetables = this.timetables.map {
TimeTable(
timetableId = it.timetableId,
trainName = it.trainName,
departureTime = it.departureTime,
arrivalTime = it.arrivalTime,
standardPrice = it.standardPrice,
premiumPrice = it.premiumPrice,
isStandardSold = it.isStandardSold,
isPremiumSold = it.isPremiumSold,
travelTime = it.travelTime
)
}.toCollection(ArrayList())
)
}
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>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.sopt.korailtalk.data.remote.datasource

import com.sopt.korailtalk.data.remote.model.base.ApiResponse
import com.sopt.korailtalk.data.remote.model.response.TrainSearchResponseDto

interface TrainSearchRemoteDataSource {
suspend fun getTimeTableData(
userId: Long,
date: String,
departurePlace: String,
arrivalPlace: String
): ApiResponse<TrainSearchResponseDto>
}
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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.sopt.korailtalk.data.remote.datasourceimpl

import com.sopt.korailtalk.data.remote.datasource.TrainSearchRemoteDataSource
import com.sopt.korailtalk.data.remote.service.TrainSearchService
import javax.inject.Inject

class TrainSearchRemoteDataSourceImpl @Inject constructor(
private val trainSearchService: TrainSearchService
) : TrainSearchRemoteDataSource {
override suspend fun getTimeTableData(
userId: Long,
date: String,
departurePlace: String,
arrivalPlace: String
) = trainSearchService.getTimeTableData(
userId = userId,
date = date,
departurePlace = departurePlace,
arrivalPlace = arrivalPlace
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import kotlinx.serialization.Serializable
@Serializable
data class ApiResponse<T>(
val status: Int = 200,
val message: String = "Success",
val message: String= "Success",
val data: T? = null
)
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
)
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
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,27 @@ import kotlinx.serialization.Serializable

@Serializable
data class TrainSearchResponseDto(
@SerialName("timetableId")
val timetableId: Long?,
@SerialName("trainName")
val trainName: String,
@SerialName("departureTime")
val departureTime: String,
@SerialName("arrivalTime")
val arrivalTime: String,
@SerialName("standardPrice")
val standardPrice: Int,
@SerialName("premiumPrice")
val premiumPrice: Int,
@SerialName("isStandardSold")
val isStandardSold: Boolean,
@SerialName("isPremiumSold")
val isPremiumSold: Boolean,
@SerialName("travelTime")
val travelTime: Int,
)
@SerialName("timetables") val timetables: List<TimeTable>
) {
@Serializable
data class TimeTable(
@SerialName("timetableId")
val timetableId: Long,
@SerialName("trainName")
val trainName: String,
@SerialName("departureTime")
val departureTime: String,
@SerialName("arrivalTime")
val arrivalTime: String,
@SerialName("standardPrice")
val standardPrice: Int,
@SerialName("premiumPrice")
val premiumPrice: Int,
@SerialName("isStandardSold")
val isStandardSold: Boolean,
@SerialName("isPremiumSold")
val isPremiumSold: Boolean,
@SerialName("travelTime")
val travelTime: Int,
)
}
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>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sopt.korailtalk.data.remote.service

import com.sopt.korailtalk.data.remote.model.base.ApiResponse
import com.sopt.korailtalk.data.remote.model.response.TrainSearchResponseDto
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

interface TrainSearchService {
@GET("timetables")
suspend fun getTimeTableData(
@Header("userId") userId: Long,
@Query("date") date: String,
@Query("departurePlace") departurePlace: String,
@Query("arrivalPlace") arrivalPlace: String,
): ApiResponse<TrainSearchResponseDto>
}
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())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.sopt.korailtalk.data.repositoryimpl

import com.sopt.korailtalk.data.mapper.todomain.toDomain
import com.sopt.korailtalk.data.remote.datasource.TrainSearchRemoteDataSource
import com.sopt.korailtalk.data.remote.util.handleApiResponse
import com.sopt.korailtalk.domain.model.TimeTables
import com.sopt.korailtalk.domain.repository.TrainSearchRepository
import javax.inject.Inject

class TrainSearchRepositoryImpl @Inject constructor(
private val trainSearchRemoteDataSource: TrainSearchRemoteDataSource
) : TrainSearchRepository {
override suspend fun getTimeTableData(
userId: Long,
date: String,
departurePlace: String,
arrivalPlace: String
): Result<TimeTables> {
return runCatching {
trainSearchRemoteDataSource.getTimeTableData(
userId = userId,
date = date,
departurePlace = departurePlace,
arrivalPlace = arrivalPlace
).handleApiResponse().getOrThrow()
.toDomain()
}
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/sopt/korailtalk/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package com.sopt.korailtalk.di
import com.sopt.korailtalk.data.local.datasource.ExampleLocalDataSource
import com.sopt.korailtalk.data.local.datasourceimpl.ExampleLocalDataSourceImpl
import com.sopt.korailtalk.data.remote.datasource.ExampleRemoteDataSource
import com.sopt.korailtalk.data.remote.datasource.PaymentRemoteDataSource
import com.sopt.korailtalk.data.remote.datasource.TrainSearchRemoteDataSource
import com.sopt.korailtalk.data.remote.datasourceimpl.ExampleRemoteDataSourceImpl
import com.sopt.korailtalk.data.remote.datasourceimpl.PaymentRemoteDataSourceImpl
import com.sopt.korailtalk.data.remote.datasourceimpl.TrainSearchRemoteDataSourceImpl
import com.sopt.korailtalk.data.remote.datasource.SeatsRemoteDataSource
import com.sopt.korailtalk.data.remote.datasource.TicketRemoteDataSource
import com.sopt.korailtalk.data.remote.datasourceimpl.ExampleRemoteDataSourceImpl
Expand All @@ -29,6 +34,18 @@ abstract class DataSourceModule {
exampleRemoteDataSourceImpl: ExampleRemoteDataSourceImpl
): ExampleRemoteDataSource

@Binds
@Singleton
abstract fun bindPaymentRemoteDataSource(
paymentRemoteDataSourceImpl: PaymentRemoteDataSourceImpl
): PaymentRemoteDataSource

@Binds
@Singleton
abstract fun bindTrainSearchRemoteDataSource(
trainSearchRemoteDataSourceImpl: TrainSearchRemoteDataSourceImpl
): TrainSearchRemoteDataSource

@Binds
@Singleton
abstract fun bindSeatsRemoteDataSource(
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/sopt/korailtalk/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.sopt.korailtalk.di

import com.sopt.korailtalk.data.repositoryimpl.ExampleRepositoryImpl
import com.sopt.korailtalk.data.repositoryimpl.PaymentRepositoryImpl
import com.sopt.korailtalk.data.repositoryimpl.TrainSearchRepositoryImpl
import com.sopt.korailtalk.domain.repository.ExampleRepository
import com.sopt.korailtalk.domain.repository.PaymentRepository
import com.sopt.korailtalk.domain.repository.TrainSearchRepository
import com.sopt.korailtalk.data.repositoryimpl.SeatsRepositoryImpl
import com.sopt.korailtalk.data.repositoryimpl.TicketRepositoryImpl
import com.sopt.korailtalk.domain.repository.ExampleRepository
Expand All @@ -21,6 +26,18 @@ abstract class RepositoryModule {
exampleRepositoryImpl: ExampleRepositoryImpl
): ExampleRepository

@Binds
@Singleton
abstract fun bindPaymentRepository(
paymentRepositoryImpl: PaymentRepositoryImpl
): PaymentRepository

@Binds
@Singleton
abstract fun bindTrainSearchRepository(
trainSearchRepositoryImpl: TrainSearchRepositoryImpl
): TrainSearchRepository

@Binds
@Singleton
abstract fun bindSeatsRepository(
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopt/korailtalk/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sopt.korailtalk.di

import com.sopt.korailtalk.data.remote.service.ExampleService
import com.sopt.korailtalk.data.remote.service.PaymentService
import com.sopt.korailtalk.data.remote.service.TrainSearchService
import com.sopt.korailtalk.data.remote.service.SeatsService
import com.sopt.korailtalk.data.remote.service.TicketService
import com.sopt.korailtalk.di.qualifier.KorailTalk
Expand All @@ -19,6 +21,16 @@ object ServiceModule {
fun provideExampleService(@KorailTalk retrofit: Retrofit): ExampleService =
retrofit.create(ExampleService::class.java)

@Provides
@Singleton
fun providePaymentService(@KorailTalk retrofit: Retrofit): PaymentService =
retrofit.create(PaymentService::class.java)

@Provides
@Singleton
fun provideTrainSearchService(@KorailTalk retrofit: Retrofit): TrainSearchService =
retrofit.create(TrainSearchService::class.java)

@Provides
@Singleton
fun provideSeatsService(@KorailTalk retrofit: Retrofit): SeatsService =
Expand Down
Loading