Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
updated the BackendClient to the newest version of the proto definition
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Sep 19, 2023
1 parent 387078c commit 321c32d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)) },
Expand All @@ -50,7 +50,7 @@ class BackendClient private constructor() {
* On error, errorCallback is called with an error message.
*/
fun getNewsSources(callback: (List<NewsSources>) -> 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)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,7 +29,7 @@ data class NewsSources(
get() = setOf(7, 8, 9, 13).contains(id)

companion object {
fun fromProto(it: NewsSourceReply): List<NewsSources> {
fun fromProto(it: GetNewsSourcesReply): List<NewsSources> {
return it.sourcesList.map {
NewsSources(
id = it.source.toInt(),
Expand Down
32 changes: 12 additions & 20 deletions app/src/main/proto/backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 321c32d

Please sign in to comment.