parent
a2c1a1d27b
commit
c1fcdd8344
@ -0,0 +1,3 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class Owner(val id: Int, val login: String)
|
@ -1,3 +1,3 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class Repository(val name: String, val stars: Int)
|
||||
data class Repository(val owner: Owner, val name: String, val stars: Int = 0)
|
||||
|
@ -0,0 +1,6 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
interface RepositoryIdentifiable {
|
||||
|
||||
val identifier: RepositoryIdentifier
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class RepositoryIdentifier(val owner: String, val name: String) : RepositoryIdentifiable {
|
||||
|
||||
override val identifier: RepositoryIdentifier
|
||||
get() = this
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.model
|
||||
|
||||
data class VersionedFile(val fileName: String)
|
||||
data class VersionedFile(val name: String)
|
||||
|
@ -0,0 +1,48 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.network
|
||||
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifiable
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
import okhttp3.OkHttpClient
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface GiteaApiService {
|
||||
|
||||
@GET("users/{username}/repos")
|
||||
suspend fun listActiveRepositories(@Path("username") username: String, @Query("page") page: Int): List<Repository>
|
||||
|
||||
@GET("repos/{owner}/{repo}/contents/{filePath}")
|
||||
suspend fun listFileContents(@Path("owner") owner: String, @Path("repo") repo: String, @Path("filePath") filePath: String): List<VersionedFile>
|
||||
}
|
||||
|
||||
class GiteaService(private val handle: GiteaApiService) : RepositoryService {
|
||||
|
||||
constructor() : this(createRetrofit().create(GiteaApiService::class.java))
|
||||
|
||||
override suspend fun listActiveRepositories(username: String, page: Int): List<Repository> =
|
||||
handle.listActiveRepositories(username, page)
|
||||
|
||||
override suspend fun listFileContents(repository: RepositoryIdentifiable, filePath: String): List<VersionedFile> =
|
||||
handle.listFileContents(repository.identifier.owner, repository.identifier.name, filePath)
|
||||
}
|
||||
|
||||
private const val CODEFIRST_API_BASE = "https://codefirst.iut.uca.fr/git/api/v1/"
|
||||
|
||||
private val httpClient = OkHttpClient()
|
||||
|
||||
private fun createRetrofit(): Retrofit =
|
||||
Retrofit.Builder()
|
||||
.baseUrl(CODEFIRST_API_BASE)
|
||||
.addConverterFactory(MoshiConverterFactory.create(
|
||||
Moshi.Builder()
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.build()))
|
||||
.client(httpClient)
|
||||
.build()
|
@ -0,0 +1,12 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.network
|
||||
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifiable
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
|
||||
interface RepositoryService {
|
||||
|
||||
suspend fun listActiveRepositories(username: String, page: Int): List<Repository>
|
||||
|
||||
suspend fun listFileContents(repository: RepositoryIdentifiable, filePath: String): List<VersionedFile>
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package fr.uca.iut.clfreville2.teaiswarm.network
|
||||
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Owner
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.Repository
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.RepositoryIdentifiable
|
||||
import fr.uca.iut.clfreville2.teaiswarm.model.VersionedFile
|
||||
|
||||
class StubRepositoryService : RepositoryService {
|
||||
|
||||
override suspend fun listActiveRepositories(username: String, page: Int): List<Repository> =
|
||||
when (page) {
|
||||
1 -> listOf(
|
||||
"oki",
|
||||
"moshell",
|
||||
"scrabble-with-numbers",
|
||||
"vdn-tools",
|
||||
"codefirst-test",
|
||||
"iut-config",
|
||||
"Ebullition"
|
||||
)
|
||||
2 -> listOf(
|
||||
"api-ef",
|
||||
"codefirst-docdeployer",
|
||||
"TeaIsWarm",
|
||||
"Application",
|
||||
"silex"
|
||||
)
|
||||
else -> listOf()
|
||||
}.map { Repository(Owner(-1, ""), it) }
|
||||
|
||||
override suspend fun listFileContents(repository: RepositoryIdentifiable, filePath: String) =
|
||||
listOf(
|
||||
"cli",
|
||||
"doc",
|
||||
"sql",
|
||||
"test",
|
||||
"web",
|
||||
".drone.yml",
|
||||
".gitignore",
|
||||
"CONVENTIONS.md",
|
||||
"README.md"
|
||||
).map { VersionedFile(it) }
|
||||
}
|
Loading…
Reference in new issue