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

막차 시간 계산 로직 변경 #4

Merged
merged 5 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion data/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id("kotlin-android")
id("com.google.dagger.hilt.android")
id("com.google.devtools.ksp")
id("kotlin-kapt")
}

val properties = Properties()
Expand Down Expand Up @@ -88,7 +89,7 @@ dependencies {
implementation("com.tickaroo.tikxml:annotation:0.8.13")
implementation("com.tickaroo.tikxml:core:0.8.13")
implementation("com.tickaroo.tikxml:retrofit-converter:0.8.13")
ksp("com.tickaroo.tikxml:processor:0.8.13")
kapt("com.tickaroo.tikxml:processor:0.8.13")

// Room
implementation("androidx.room:room-runtime:2.6.1")
Expand Down
20 changes: 20 additions & 0 deletions data/src/main/java/com/stop/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import okhttp3.Protocol
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
Expand Down Expand Up @@ -164,6 +167,19 @@ internal object NetworkModule {
val url = chain.request().url.toUri().toString()

val (name: String, key: String) = when {
// url.contains("transit/routes") -> {
// val response = readJson("response.json")
// return chain.proceed(chain.request())
// .newBuilder()
// .code(200)
// .protocol(Protocol.HTTP_2)
// .message("success")
// .body(
// response.toByteArray()
// .toResponseBody("application/json".toMediaTypeOrNull())
// ).addHeader("content-type", "application/json")
// .build()
// }
url.contains(BuildConfig.OPEN_API_SEOUL_URL) -> Pair(
OPEN_API_SEOUL_KEY_NAME,
BuildConfig.BUS_KEY
Expand All @@ -190,5 +206,9 @@ internal object NetworkModule {
proceed(newRequest)
}
}
private fun readJson(fileName: String): String {
return Thread.currentThread().contextClassLoader?.getResource(fileName)
?.readText() ?: ""
}
}
}
31 changes: 31 additions & 0 deletions data/src/main/java/com/stop/data/model/route/BusRouteListItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.stop.data.model.route

import com.stop.domain.model.route.seoul.bus.BusRouteInfo

data class BusRouteListItem(
val busRouteAbrv: String,
val busRouteId: String,
val busRouteNm: String,
val corpNm: String,
val edStationNm: String,
val firstBusTm: String,
val firstLowTm: String,
val lastBusTm: String,
val lastBusYn: String,
val lastLowTm: String,
val length: String,
val routeType: String,
val stStationNm: String,
val term: String
) {
fun toDomain(): BusRouteInfo {
return BusRouteInfo(
busRouteName = busRouteNm,
busRouteAbbreviation = busRouteAbrv,
busRouteId = busRouteId,
term = term.toInt(),
corpName = corpNm,
lastBusTime = lastBusTm,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.stop.data.model.route

import com.squareup.moshi.Json

data class BusRouteListMsgBody(
@Json(name="itemList")
val busRouteListItemList: List<BusRouteListItem>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stop.data.model.route

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class BusRouteListResponse(
@Json(name = "msgBody")
val msgBody: BusRouteListMsgBody
)
37 changes: 37 additions & 0 deletions data/src/main/java/com/stop/data/model/route/BusStationsItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.stop.data.model.route

import com.stop.domain.model.route.seoul.bus.BusStationInfo

data class BusStationsItem(
val arsId: String,
val beginTm: String,
val busRouteAbrv: String,
val busRouteId: String,
val busRouteNm: String,
val direction: String,
val fullSectDist: String?,
val gpsX: String,
val gpsY: String,
val lastTm: String,
val posX: String,
val posY: String,
val routeType: String,
val sectSpd: String,
val section: String,
val seq: String,
val station: String,
val stationNm: String,
val stationNo: String,
val transYn: String,
val trnstnid: String
) {
fun toDomain(): BusStationInfo {
return BusStationInfo(
startTime = beginTm,
lastTime = lastTm,
stationName = stationNm,
stationId = station,
stationNumber = stationNo
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.stop.data.model.route

import com.squareup.moshi.Json

data class BusStationsMsgBody(
@Json(name="itemList")
val busStationsItemList: List<BusStationsItem>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stop.data.model.route

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class BusStationsResponse(
@Json(name = "msgBody")
val msgBody: BusStationsMsgBody
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "msgBody")
internal data class GyeonggiBusLastTimeMsgBody(
@Element(name = "busRouteInfoItem")
val lastTimes: List<GyeonggiBusLastTime>
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Path
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "response")
internal data class GyeonggiBusLastTimeResponse(
@Path("msgBody")
@Element(name = "busRouteInfoItem")
val lastTimes: List<GyeonggiBusLastTime>
@Element(name = "msgBody")
val msgBody: GyeonggiBusLastTimeMsgBody
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "response")
internal data class GyeonggiBusRouteIdMsgBody(
@Element(name = "busRouteList")
val routes: List<GyeonggiBusRoute>
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Path
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "response")
internal data class GyeonggiBusRouteIdResponse(
@Path("msgBody")
@Element(name = "busRouteList")
val routes: List<GyeonggiBusRoute>
@Element(name = "msgBody")
val msgBody: GyeonggiBusRouteIdMsgBody
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "msgBody")
internal data class GyeonggiBusRouteStationsMsgBody(
@Element(name = "busRouteStationList")
val stations: List<GyeonggiBusStation>
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Path
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "response")
internal data class GyeonggiBusRouteStationsResponse(
@Path("msgBody")
@Element(name = "busRouteStationList")
val stations: List<GyeonggiBusStation>
@Element(name = "msgBody")
val msgBody: GyeonggiBusRouteStationsMsgBody
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Path
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "response")
internal data class GyeonggiBusStationIdResponse(
@Path("msgBody")
@Element(name = "busStationList")
val busStations: List<GyeonggiBusStation>
@Element(name = "msgBody")
val msgBody: GyeonggiBusStationMsgBody
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stop.data.remote.model.route.gyeonggi

import com.tickaroo.tikxml.annotation.Element
import com.tickaroo.tikxml.annotation.Xml

@Xml(name = "msgBody")
internal data class GyeonggiBusStationMsgBody(
@Element(name = "busStationList")
val busStations: List<GyeonggiBusStation>
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ internal interface OpenApiSeoulService {
@Path("END_INDEX") endIndex: Int = 5,
): NetworkResult<SubwayStationResponse>

@GET("{KEY}/{TYPE}/{SERVICE}/{START_INDEX}/{END_INDEX}/%20/%20/{LINE_NAME}")
@GET("{KEY}/{TYPE}/{SERVICE}/{START_INDEX}/{END_INDEX}/%20/%20/%20/{LINE_NUM}")
suspend fun getSubwayStations(
@Path("KEY") key: String = BuildConfig.SUBWAY_KEY,
@Path("TYPE") type: String = "json",
@Path("SERVICE") serviceName: String,
@Path("LINE_NAME") lineName: String,
@Path("LINE_NUM") lineName: String,
@Path("START_INDEX") startIndex: Int = 1,
@Path("END_INDEX") endIndex: Int = 200,
): NetworkResult<SubwayStationsResponse>
Expand Down
16 changes: 16 additions & 0 deletions data/src/main/java/com/stop/data/remote/network/WsBusApiService.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.stop.data.remote.network

import com.stop.data.model.route.BusRouteListResponse
import com.stop.data.model.route.BusStationsResponse
import com.stop.data.remote.model.NetworkResult
import com.stop.data.remote.model.nowlocation.bus.BusNowLocationResponse
import com.stop.domain.model.route.seoul.bus.BusLastTimeResponse
Expand Down Expand Up @@ -35,11 +37,25 @@ internal interface WsBusApiService {
@Query("resultType") resultType: String = "json",
): NetworkResult<BusLastTimeResponse>

@GET(GET_BUS_ROUTE_LIST_URL)
suspend fun getBusRouteList(
@Query("strSrch") routeName: String,
@Query("resultType") resultType: String = JSON,
): NetworkResult<BusRouteListResponse>

@GET(GET_BUS_STATIONS_URL)
suspend fun getBusStations(
@Query("busRouteId") routeId: String,
@Query("resultType") resultType: String = JSON,
): NetworkResult<BusStationsResponse>

companion object {
private const val GET_BUS_ARS_URL = "stationinfo/getStationByName"
private const val GET_BUS_NOW_LOCATION_URL = "buspos/getBusPosByRtid"
private const val JSON = "json"
private const val GET_BUS_LINE_URL = "stationinfo/getRouteByStation"
private const val GET_BUS_LAST_TIME_URL = "stationinfo/getBustimeByStation"
private const val GET_BUS_ROUTE_LIST_URL = "busRouteInfo/getBusRouteList"
private const val GET_BUS_STATIONS_URL = "busRouteInfo/getStaionByRoute"
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.stop.data.remote.source.route

import com.stop.domain.model.route.seoul.subway.StationType
import com.stop.domain.model.geoLocation.AddressType
import com.stop.domain.model.route.gyeonggi.*
import com.stop.domain.model.route.seoul.bus.BusRouteInfo
import com.stop.domain.model.route.seoul.bus.BusStationInfo
import com.stop.domain.model.route.seoul.bus.SeoulBusRouteInfo
import com.stop.domain.model.route.seoul.bus.SeoulBusStationInfo
import com.stop.domain.model.route.seoul.bus.LastTimeInfo
import com.stop.domain.model.route.seoul.subway.Station
import com.stop.domain.model.route.seoul.subway.StationLastTime
Expand All @@ -19,20 +22,22 @@ internal interface RouteRemoteDataSource {
suspend fun getRoute(routeRequest: RouteRequest): List<Itinerary>
suspend fun reverseGeocoding(coordinate: Coordinate, addressType: AddressType): ReverseGeocodingResponse

suspend fun getSubwayStationCd(stationId: String, stationName: String): String
suspend fun getSubwayStationCd(stationType: StationType, stationName: String): String
suspend fun getSubwayStations(lineName: String): List<Station>
suspend fun getSubwayStationLastTime(
stationId: String,
transportDirectionType: TransportDirectionType,
weekType: WeekType,
): List<StationLastTime>

suspend fun getSeoulBusStationArsId(stationName: String): List<BusStationInfo>
suspend fun getSeoulBusRoute(stationId: String): List<BusRouteInfo>
suspend fun getSeoulBusStationArsId(stationName: String): List<SeoulBusStationInfo>
suspend fun getSeoulBusRoute(stationId: String): List<SeoulBusRouteInfo>
suspend fun getSeoulBusLastTime(stationId: String, lineId: String): List<LastTimeInfo>

suspend fun getGyeonggiBusStationId(stationName: String): List<GyeonggiBusStation>
suspend fun getGyeonggiBusRoute(stationId: String): List<GyeonggiBusRoute>
suspend fun getGyeonggiBusLastTime(lineId: String): List<GyeonggiBusLastTime>
suspend fun getGyeonggiBusRouteStations(lineId: String): List<GyeonggiBusStation>
suspend fun getBusRouteList(routeName: String): List<BusRouteInfo>
suspend fun getBusStations(routeId: String): List<BusStationInfo>
}
Loading