Skip to content

Commit

Permalink
[FEAT]#30: Auth data에 필요한 클래스 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
flash159483 committed Jul 17, 2024
1 parent 77b1be9 commit ac54c9e
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 7 deletions.
7 changes: 0 additions & 7 deletions core/model/src/main/kotlin/com/bff/wespot/model/SchoolItem.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.bff.wespot.network.di

import com.bff.wespot.network.source.auth.AuthDataSource
import com.bff.wespot.network.source.auth.AuthDataSourceImpl
import com.bff.wespot.network.source.message.MessageDataSource
import com.bff.wespot.network.source.message.MessageDataSourceImpl
import dagger.Binds
Expand All @@ -16,4 +18,10 @@ abstract class NetworkModule {
abstract fun bindsMessageDataSource(
messageDataSourceImpl: MessageDataSourceImpl
): MessageDataSource

@Binds
@Singleton
abstract fun bindsAuthDataSource(
authDataSourceImpl: AuthDataSourceImpl
): AuthDataSource
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.bff.wespot.network.model.auth

import com.bff.wespot.model.auth.School
import kotlinx.serialization.Serializable

@Serializable
data class SchoolDto(
val id: Int,
val name: String,
val address: String,
val type: String,
) {
fun toSchool(): School = School(
id = id,
name = name,
address = address,
type = type,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.bff.wespot.network.model.auth

import kotlinx.serialization.Serializable

@Serializable
data class SchoolListDto(
val schools: List<SchoolDto>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bff.wespot.network.source.auth

import com.bff.wespot.network.model.auth.SchoolListDto

interface AuthDataSource {
suspend fun getSchoolList(search: String): Result<SchoolListDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.bff.wespot.network.source.auth

import com.bff.wespot.network.extensions.safeRequest
import com.bff.wespot.network.model.auth.SchoolListDto
import io.ktor.client.HttpClient
import io.ktor.client.request.parameter
import io.ktor.http.HttpMethod
import io.ktor.http.path
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val httpClient: HttpClient
) : AuthDataSource {
override suspend fun getSchoolList(search: String): Result<SchoolListDto> =
httpClient.safeRequest {
url {
method = HttpMethod.Get
path("api/v1/auth/signup/schools/search")
parameter("name", search)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.bff.wespot.data.repository.message

import com.bff.wespot.domain.repository.auth.AuthRepository
import com.bff.wespot.model.auth.School
import com.bff.wespot.network.model.auth.SchoolDto
import com.bff.wespot.network.source.auth.AuthDataSource
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource
) : AuthRepository {
override suspend fun getSchoolList(search: String): Result<List<School>> =
authDataSource
.getSchoolList(search)
.map { it.schools.map(SchoolDto::toSchool) }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.bff.wespot.domain.repository.auth

import com.bff.wespot.model.auth.School

interface AuthRepository {
suspend fun getSchoolList(search: String): Result<List<School>>
}

0 comments on commit ac54c9e

Please sign in to comment.