I have an abstraction of usage of repository pattern and I'm not able to do a retrofit call.
I'll go from Retrofit service to my use case.
I've AuthenticationRetrofitService
interface AuthenticationRetrofitService {
@GET(LOGIN_PATH)
suspend fun doLogin(@Header("Authorization") basicAuth: String) : Either<Throwable, Monitor>
@GET(LOGOUT_PATH)
suspend fun doLogout() : Either<Throwable,Unit>
companion object {
private const val LOGIN_PATH = "login/"
private const val LOGOUT_PATH = "logout/"
}
}
Then I have AuthenticationRetrofitApi
which implements AuthenticationApi
class AuthenticationRetrofitApi(private val service: AuthenticationRetrofitService) : AuthenticationApi {
override suspend fun doLogin(basicAuth: String) = service.doLogin(basicAuth)
override suspend fun doLogout() = service.doLogout()
}
Then this is the AuthenticationApi
interface AuthenticationApi {
suspend fun doLogin(basicAuth: String) : Either<Throwable, Monitor>
suspend fun doLogout() : Either<Throwable, Unit>
}
Then I have the AuthenticationRepository
interface AuthenticationRepository {
suspend fun doLogin(basicAuth: String): Either<Throwable, Monitor>
suspend fun doLogout(): Either<Throwable, Unit>
}
And the AuthenticationRepositoryImpl
class AuthenticationRepositoryImpl (private val api: AuthenticationApi) : AuthenticationRepository {
override suspend fun doLogin(basicAuth: String) =
api.doLogin(basicAuth = basicAuth)
.fold({
Either.Left(Throwable())
},
{
Either.Right(it)
}
)
override suspend fun doLogout() = api.doLogout().fold({Either.Left(Throwable())},{Either.Right(Unit)})
}
And from my usecase I call the AuthenticationRepository
my problem is, I do not know how to link them because if I run the app I get this error.
java.lang.IllegalArgumentException: HTTP method annotation is required (e.g., @GET, @POST, etc.).
Then I'm using Kodein
for dependency injection but I do not know what to bind
or what to provide
perhaps is that the error?
Because :
AuthenticationRetrofitApi
is not used
AuthenticationRepositoryImpl
is not used
What I'm missing?
EDIT
This is how I use Kodein
for my retrofit module
val retrofitModule = Kodein.Module("retrofitModule") {
bind<OkHttpClient>() with singleton {
OkHttpClient().newBuilder().build()
}
bind<Retrofit>() with singleton {
Retrofit.Builder()
.baseUrl("https://127.0.0.1/api/")
.client(instance())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
//I'm not sure if I have to bind this
bind<AuthenticationRepository>() with singleton {
instance<Retrofit>().create(AuthenticationRepository::class.java)
}
}