Private
Public Access
1
0

Adds backend module, tests for /version and /conversations (not real tests yet)

This commit is contained in:
2023-08-06 12:27:58 -07:00
parent 16148949c8
commit 2e9b62b654
17 changed files with 218 additions and 4 deletions

1
.idea/gradle.xml generated
View File

@@ -12,6 +12,7 @@
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" /> <option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/backend" />
</set> </set>
</option> </option>
</GradleProjectSettings> </GradleProjectSettings>

2
.idea/kotlinc.xml generated
View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.8.0" /> <option name="version" value="1.9.0" />
</component> </component>
</project> </project>

1
.idea/misc.xml generated
View File

@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">

View File

@@ -48,6 +48,10 @@ android {
dependencies { dependencies {
implementation 'androidx.compose.material3:material3:1.1.1' implementation 'androidx.compose.material3:material3:1.1.1'
implementation 'androidx.core:core-ktx:+'
// Kordophone lib
implementation project(':backend')
// Navigation // Navigation
def nav_version = "2.5.3" def nav_version = "2.5.3"
@@ -76,7 +80,7 @@ dependencies {
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.1.1' implementation 'androidx.compose.material:material:1.1.1'
implementation 'androidx.compose.foundation:foundation:$compose_ui_version' implementation "androidx.compose.foundation:foundation:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version" debugImplementation "androidx.compose.ui:ui-tooling:$compose_ui_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version" debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_ui_version"

1
backend/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

52
backend/build.gradle Normal file
View File

@@ -0,0 +1,52 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
namespace 'net.buzzert.kordophone.backend'
compileSdk 33
defaultConfig {
minSdk 31
targetSdk 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.core:core-ktx:+'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// Third-party
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.9.0'
// https://mvnrepository.com/artifact/org.jetbrains.kotlinx/kotlinx-coroutines-core
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.7.3', ext: 'pom'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.1'
}

View File

21
backend/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,24 @@
package net.buzzert.kordophone.backend
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("net.buzzert.kordophone.backend.test", appContext.packageName)
}
}

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View File

@@ -0,0 +1,16 @@
package net.buzzert.kordophone.backend
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.net.URL
class APIClient(baseURL: URL) {
private val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(baseURL)
.addConverterFactory(GsonConverterFactory.create())
.build()
fun getClient(): Retrofit {
return retrofit
}
}

View File

@@ -0,0 +1,15 @@
package net.buzzert.kordophone.backend
import net.buzzert.kordophone.backend.model.Conversation
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.GET
interface APIInterface {
@GET("/version")
suspend fun getVersion(): ResponseBody
@GET("/conversations")
suspend fun getConversations(): Response<List<Conversation>>
}

View File

@@ -0,0 +1,19 @@
package net.buzzert.kordophone.backend
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import net.buzzert.kordophone.backend.model.Conversation
import java.net.URL
class ChatRepository(baseURL: URL) {
private val client: APIClient = APIClient(baseURL)
private val apiInterface: APIInterface = client.getClient().create(APIInterface::class.java)
suspend fun getVersion(): String {
return apiInterface.getVersion().string()
}
suspend fun fetchConversations(): List<Conversation> {
return apiInterface.getConversations().body()!!
}
}

View File

@@ -0,0 +1,24 @@
package net.buzzert.kordophone.backend.model
import com.google.gson.annotations.SerializedName
import java.util.Date
data class Conversation(
@SerializedName("date")
val date: Date,
@SerializedName("participantDisplayNames")
val participants: List<String>?,
@SerializedName("displayName")
val displayName: String?,
@SerializedName("unreadCount")
val unreadCount: Int,
@SerializedName("lastMessagePreview")
val lastMessagePreview: String,
@SerializedName("guid")
val guid: String,
)

View File

@@ -0,0 +1,33 @@
package net.buzzert.kordophone.backend
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.Assert.*
import java.net.URL
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
val repository = ChatRepository(URL("http://localhost:5738"))
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
@Test
fun testGetVersion() = runBlocking {
val version = repository.getVersion()
println("Version: $version")
}
@Test
fun testFetchConversations() = runBlocking {
val conversations = repository.fetchConversations()
println("Conversations: $conversations")
}
}

View File

@@ -8,5 +8,5 @@ buildscript {
plugins { plugins {
id 'com.android.application' version '7.4.2' apply false id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false id 'com.android.library' version '7.4.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.0' apply false id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
} }

View File

@@ -14,3 +14,4 @@ dependencyResolutionManagement {
} }
rootProject.name = "KordophoneDroid" rootProject.name = "KordophoneDroid"
include ':app' include ':app'
include ':backend'