Требуется аннотация HTTP метода Retrofit2 - PullRequest
0 голосов
/ 19 октября 2019

У меня есть абстракция использования шаблона репозитория, и я не могу выполнить вызов дооснащения.

Я перейду со службы Retrofit к своему варианту использования.

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/"
    }
}

Тогда у меня есть AuthenticationRetrofitApi, который реализует AuthenticationApi

class AuthenticationRetrofitApi(private val service: AuthenticationRetrofitService) : AuthenticationApi {

    override suspend fun doLogin(basicAuth: String) = service.doLogin(basicAuth)

    override suspend fun doLogout() = service.doLogout()

}

Тогда это AuthenticationApi

interface AuthenticationApi {

    suspend fun doLogin(basicAuth: String) : Either<Throwable, Monitor>
    suspend fun doLogout() : Either<Throwable, Unit>
}

Тогда у меня естьAuthenticationRepository

interface AuthenticationRepository {

    suspend fun doLogin(basicAuth: String): Either<Throwable, Monitor>
    suspend fun doLogout(): Either<Throwable, Unit>
}

И 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)})

}

И из моего варианта использования я называю AuthenticationRepository, моя проблема в том, что я не знаю, как их связать, потому чтоесли я запускаю приложение, я получаю эту ошибку.

java.lang.IllegalArgumentException: требуется аннотация HTTP-метода (например, @GET, @POST и т. д.).

Тогда я использую Kodein для внедрения зависимостей, но я не знаю, что для bind или что для provide, возможно, это ошибка? Потому что:

AuthenticationRetrofitApi не используется AuthenticationRepositoryImpl не используется

Чего мне не хватает?

РЕДАКТИРОВАТЬ

Вот как я используюKodein для моего модифицированного модуля

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)
    }
}
...