From 321c32dbaafbd1fe474d347c9c879f8f5be43a42 Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Tue, 19 Sep 2023 22:14:26 +0200 Subject: [PATCH] updated the BackendClient to the newest version of the proto definition --- .../in/tumcampusapp/api/app/BackendClient.kt | 6 ++-- .../component/ui/news/model/NewsSources.kt | 4 +-- app/src/main/proto/backend.proto | 32 +++++++------------ 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/de/tum/in/tumcampusapp/api/app/BackendClient.kt b/app/src/main/java/de/tum/in/tumcampusapp/api/app/BackendClient.kt index 5e719d010..14d195edd 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/api/app/BackendClient.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/api/app/BackendClient.kt @@ -1,7 +1,7 @@ package de.tum.`in`.tumcampusapp.api.app -import com.google.protobuf.Empty import de.tum.`in`.tumcampusapp.BuildConfig import de.tum.`in`.tumcampusapp.api.backend.CampusGrpc +import de.tum.`in`.tumcampusapp.api.backend.GetNewsSourcesRequest import de.tum.`in`.tumcampusapp.api.backend.GetUpdateNoteRequest import de.tum.`in`.tumcampusapp.component.ui.news.model.NewsSources import de.tum.`in`.tumcampusapp.component.ui.updatenote.model.UpdateNote @@ -37,7 +37,7 @@ class BackendClient private constructor() { * On error, errorCallback is called with an error message. */ fun getUpdateNote(callback: (UpdateNote) -> Unit, errorCallback: (message: io.grpc.StatusRuntimeException) -> Unit) { - val request = GetUpdateNoteRequest.newBuilder().setVersion(BuildConfig.VERSION_CODE).build() + val request = GetUpdateNoteRequest.newBuilder().setVersion(BuildConfig.VERSION_CODE.toLong()).build() val response = stub.getUpdateNote(request) response.runCatching { get() }.fold( onSuccess = { callback(UpdateNote.fromProto(it)) }, @@ -50,7 +50,7 @@ class BackendClient private constructor() { * On error, errorCallback is called with an error message. */ fun getNewsSources(callback: (List) -> Unit, errorCallback: (message: io.grpc.StatusRuntimeException) -> Unit) { - val response = stub.getNewsSources(Empty.getDefaultInstance()) + val response = stub.getNewsSources(GetNewsSourcesRequest.getDefaultInstance()) response.runCatching { get() }.fold( onSuccess = { callback(NewsSources.fromProto(it)) }, onFailure = { errorCallback(getStatus(it)) } diff --git a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/model/NewsSources.kt b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/model/NewsSources.kt index bf807b2a6..988153ea6 100644 --- a/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/model/NewsSources.kt +++ b/app/src/main/java/de/tum/in/tumcampusapp/component/ui/news/model/NewsSources.kt @@ -4,7 +4,7 @@ import androidx.room.Entity import androidx.room.PrimaryKey import androidx.room.RoomWarnings import com.google.gson.annotations.SerializedName -import de.tum.`in`.tumcampusapp.api.backend.NewsSourceReply +import de.tum.`in`.tumcampusapp.api.backend.GetNewsSourcesReply /** * This class contains information about the source of a [News] item. @@ -29,7 +29,7 @@ data class NewsSources( get() = setOf(7, 8, 9, 13).contains(id) companion object { - fun fromProto(it: NewsSourceReply): List { + fun fromProto(it: GetNewsSourcesReply): List { return it.sourcesList.map { NewsSources( id = it.source.toInt(), diff --git a/app/src/main/proto/backend.proto b/app/src/main/proto/backend.proto index e7e01d0e4..97978f849 100644 --- a/app/src/main/proto/backend.proto +++ b/app/src/main/proto/backend.proto @@ -7,38 +7,30 @@ option java_outer_classname = "CampusApiProto"; package api; -import "google/protobuf/empty.proto"; import "google/protobuf/timestamp.proto"; service Campus { - rpc GetTopNews (google.protobuf.Empty) returns (GetTopNewsReply) { } - rpc GetNewsSources (google.protobuf.Empty) returns (NewsSourceReply) { } - rpc GetUpdateNote (GetUpdateNoteRequest) returns (GetUpdateNoteReply) { } + rpc GetNewsSources(GetNewsSourcesRequest) returns (GetNewsSourcesReply) {} + rpc GetUpdateNote (GetUpdateNoteRequest) returns (GetUpdateNoteReply) {} } -message NewsSourceReply { - repeated NewsSource sources = 1; -} +message GetNewsSourcesRequest {} -message NewsSource { - string source = 1; - string title = 2; - string icon = 3; +message GetNewsSourcesReply { + repeated NewsSource sources = 1; } -message GetTopNewsReply { - string image_url = 1; - string link = 2; - google.protobuf.Timestamp created = 3; - google.protobuf.Timestamp from = 4; - google.protobuf.Timestamp to = 5; +message NewsSource { + string source = 1; + string title = 2; + string icon = 3; } message GetUpdateNoteRequest{ - int32 version = 1; + int64 version = 1; } message GetUpdateNoteReply{ - string message = 1; - string version_name = 2; + string message = 1; + string version_name = 2; }