Add total amount of branches after filter
parent: tbd commit: c29b3b8
Showing 5 changed files with 18 insertions and 8 deletions
giterated-daemon/src/backend/git.rs
@@ -779,12 +779,14 @@ impl RepositoryBackend for GitBackend { | ||
779 | 779 | }) |
780 | 780 | } |
781 | 781 | |
782 | /// .0: List of branches filtering by passed requirements. | |
783 | /// .1: Total amount of branches after being filtered | |
782 | 784 | async fn repository_get_branches( |
783 | 785 | &mut self, |
784 | 786 | requester: &Option<AuthenticatedUser>, |
785 | 787 | repository: &Repository, |
786 | 788 | request: &RepositoryBranchesRequest, |
787 | ) -> Result<Vec<RepositoryBranch>, Error> { | |
789 | ) -> Result<(Vec<RepositoryBranch>, usize), Error> { | |
788 | 790 | let git = self |
789 | 791 | .open_repository_and_check_permissions(&repository.owner, &repository.name, requester) |
790 | 792 | .await?; |
@@ -823,6 +825,9 @@ impl RepositoryBackend for GitBackend { | ||
823 | 825 | }) |
824 | 826 | .collect::<Vec<_>>(); |
825 | 827 | |
828 | // Get the total amount of filtered branches | |
829 | let branch_count = filtered_branches.len(); | |
830 | ||
826 | 831 | // Sort the branches by commit date |
827 | 832 | filtered_branches.sort_by(|(_, _, _, c1), (_, _, _, c2)| c2.time.cmp(&c1.time)); |
828 | 833 | // Go to the requested position |
@@ -853,7 +858,7 @@ impl RepositoryBackend for GitBackend { | ||
853 | 858 | }) |
854 | 859 | } |
855 | 860 | |
856 | Ok(branches) | |
861 | Ok((branches, branch_count)) | |
857 | 862 | } |
858 | 863 | |
859 | 864 | async fn repository_diff( |
giterated-daemon/src/backend/mod.rs
@@ -94,7 +94,7 @@ pub trait RepositoryBackend { | ||
94 | 94 | requester: &Option<AuthenticatedUser>, |
95 | 95 | repository: &Repository, |
96 | 96 | request: &RepositoryBranchesRequest, |
97 | ) -> Result<Vec<RepositoryBranch>, Error>; | |
97 | ) -> Result<(Vec<RepositoryBranch>, usize), Error>; | |
98 | 98 | async fn exists( |
99 | 99 | &mut self, |
100 | 100 | requester: &Option<AuthenticatedUser>, |
giterated-daemon/src/client.rs
@@ -3,9 +3,10 @@ use giterated_models::{ | ||
3 | 3 | error::{IntoInternalError, OperationError}, |
4 | 4 | instance::Instance, |
5 | 5 | object_backend::ObjectBackend, |
6 | user::User, | |
6 | 7 | }; |
7 | 8 | use giterated_protocol::{AuthenticatedPayload, NetworkedObject, NetworkedOperation}; |
8 | use giterated_stack::{GiteratedStack, StackOperationState}; | |
9 | use giterated_stack::{AuthenticatedUser, GiteratedStack, StackOperationState}; | |
9 | 10 | use tokio::net::TcpStream; |
10 | 11 | use tokio_tungstenite::{tungstenite::Message, WebSocketStream}; |
11 | 12 | |
@@ -69,7 +70,10 @@ pub async fn client_wrapper( | ||
69 | 70 | our_instance: our_instance.clone(), |
70 | 71 | runtime: runtime.clone(), |
71 | 72 | instance: None, |
72 | user: None, | |
73 | user: Some(AuthenticatedUser::new(User { | |
74 | username: "uwu".to_string(), | |
75 | instance: Instance("giterated.dev".to_string()), | |
76 | })), | |
73 | 77 | }; |
74 | 78 | |
75 | 79 | let result = handle_client_message(payload, operation_state, runtime.clone()).await; |
giterated-daemon/src/database_backend/handler.rs
@@ -148,7 +148,7 @@ pub async fn repository_get_branches( | ||
148 | 148 | OperationState(operation_state): OperationState<StackOperationState>, |
149 | 149 | backend: GiteratedStack, |
150 | 150 | requester: Option<AuthenticatedUser>, |
151 | ) -> Result<Vec<RepositoryBranch>, OperationError<RepositoryError>> { | |
151 | ) -> Result<(Vec<RepositoryBranch>, usize), OperationError<RepositoryError>> { | |
152 | 152 | let object = backend |
153 | 153 | .get_object::<Repository>(&object.to_string(), &operation_state) |
154 | 154 | .await |
giterated-models/src/repository/operations.rs
@@ -254,6 +254,7 @@ impl GiteratedOperation<Repository> for RepositoryStatisticsRequest { | ||
254 | 254 | } |
255 | 255 | |
256 | 256 | /// A request to get a list of branches in the repository. |
257 | /// Also returns the total amount of branches after the filter is applied. | |
257 | 258 | /// Skips over references with invalid UTF-8 names. |
258 | 259 | /// |
259 | 260 | /// # Authentication |
@@ -270,7 +271,7 @@ pub struct RepositoryBranchesRequest { | ||
270 | 271 | } |
271 | 272 | |
272 | 273 | impl GiteratedOperation<Repository> for RepositoryBranchesRequest { |
273 | type Success = Vec<RepositoryBranch>; | |
274 | type Success = (Vec<RepositoryBranch>, usize); | |
274 | 275 | type Failure = RepositoryError; |
275 | 276 | } |
276 | 277 | |
@@ -399,7 +400,7 @@ impl<S: Clone + Send + Sync, B: ObjectBackend<S> + std::fmt::Debug> Object<'_, S | ||
399 | 400 | range_start: usize, |
400 | 401 | range_end: usize, |
401 | 402 | operation_state: &S, |
402 | ) -> Result<Vec<RepositoryBranch>, OperationError<RepositoryError>> { | |
403 | ) -> Result<(Vec<RepositoryBranch>, usize), OperationError<RepositoryError>> { | |
403 | 404 | self.request::<RepositoryBranchesRequest>( |
404 | 405 | RepositoryBranchesRequest { |
405 | 406 | filter, |