Skip to content

Commit

Permalink
feat(Backend): ✨ return vector of lanuages instead of stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason0729 committed Feb 6, 2024
1 parent 63bb90a commit a7d0070
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 9 additions & 9 deletions backend/src/endpoint/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,16 @@ impl SubmitSet for Arc<Server> {
Ok(Response::new(()))
}

#[doc = " Server streaming response type for the ListLangs method."]
type ListLangsStream = TonicStream<Language>;

#[instrument(skip_all, level = "debug")]
async fn list_langs(&self, _: Request<()>) -> Result<Response<Self::ListLangsStream>, Status> {
let langs = self.judger.list_lang().into_iter().map(|x| Ok(x.into()));

Ok(Response::new(
Box::pin(tokio_stream::iter(langs)) as TonicStream<_>
))
async fn list_langs(&self, _: Request<()>) -> Result<Response<Languages>, Status> {
let list: Vec<_> = self
.judger
.list_lang()
.into_iter()
.map(|x| x.into())
.collect();

Ok(Response::new(Languages { list }))
}
}

Expand Down
5 changes: 4 additions & 1 deletion proto/backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ message Language {
required string info = 3;
required string lang_ext = 4;
}
message Languages{
repeated Language list=1;
}

enum SubmitSortBy {
SUBMIT_SORT_BY_UPDATE_DATE = 0;
Expand Down Expand Up @@ -168,7 +171,7 @@ service SubmitSet {
rpc Follow(SubmitId) returns (stream SubmitStatus);
rpc Rejudge(RejudgeRequest) returns (google.protobuf.Empty);

rpc ListLangs(google.protobuf.Empty) returns (stream Language);
rpc ListLangs(google.protobuf.Empty) returns (Languages);
}

// Announcements
Expand Down

0 comments on commit a7d0070

Please sign in to comment.