feat(data): add Retrofit API, DTOs and mappers
This commit is contained in:
32
app/src/main/java/com/radiola/data/remote/ApiMapper.kt
Normal file
32
app/src/main/java/com/radiola/data/remote/ApiMapper.kt
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.radiola.data.remote
|
||||
|
||||
import com.radiola.data.remote.dto.NowPlayingItemDto
|
||||
import com.radiola.data.remote.dto.StationDto
|
||||
import com.radiola.domain.model.Station
|
||||
import com.radiola.domain.model.Track
|
||||
|
||||
object ApiMapper {
|
||||
|
||||
fun StationDto.toDomain(): Station {
|
||||
val cover = iconPng ?: iconSvg ?: ""
|
||||
return Station(
|
||||
id = id,
|
||||
name = name,
|
||||
prefix = prefix,
|
||||
streamUrl = "https://air.radiorecord.ru:805/${prefix}_128",
|
||||
coverUrl = cover,
|
||||
genre = genre ?: "",
|
||||
tags = emptyList(),
|
||||
sortOrder = id
|
||||
)
|
||||
}
|
||||
|
||||
fun NowPlayingItemDto.toDomain(): Track {
|
||||
return Track(
|
||||
artist = artist,
|
||||
song = song,
|
||||
coverUrl = image600 ?: image100,
|
||||
stationName = prefix
|
||||
)
|
||||
}
|
||||
}
|
||||
14
app/src/main/java/com/radiola/data/remote/RecordApi.kt
Normal file
14
app/src/main/java/com/radiola/data/remote/RecordApi.kt
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.radiola.data.remote
|
||||
|
||||
import com.radiola.data.remote.dto.NowPlayingResponse
|
||||
import com.radiola.data.remote.dto.StationsResponse
|
||||
import retrofit2.http.GET
|
||||
|
||||
interface RecordApi {
|
||||
|
||||
@GET("api/stations/")
|
||||
suspend fun getStations(): StationsResponse
|
||||
|
||||
@GET("api/stations/now/")
|
||||
suspend fun getNowPlaying(): NowPlayingResponse
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.radiola.data.remote.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class NowPlayingItemDto(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("prefix") val prefix: String,
|
||||
@SerialName("artist") val artist: String,
|
||||
@SerialName("song") val song: String,
|
||||
@SerialName("image600") val image600: String? = null,
|
||||
@SerialName("image100") val image100: String? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class NowPlayingResponse(
|
||||
@SerialName("result") val result: List<NowPlayingItemDto>
|
||||
)
|
||||
19
app/src/main/java/com/radiola/data/remote/dto/StationDto.kt
Normal file
19
app/src/main/java/com/radiola/data/remote/dto/StationDto.kt
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.radiola.data.remote.dto
|
||||
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class StationDto(
|
||||
@SerialName("id") val id: Int,
|
||||
@SerialName("title") val name: String,
|
||||
@SerialName("prefix") val prefix: String,
|
||||
@SerialName("genre") val genre: String? = null,
|
||||
@SerialName("icon_png") val iconPng: String? = null,
|
||||
@SerialName("icon_svg") val iconSvg: String? = null
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class StationsResponse(
|
||||
@SerialName("result") val result: List<StationDto>
|
||||
)
|
||||
Reference in New Issue
Block a user