accounting kernel5 - locking

This commit is contained in:
Priec
2026-07-20 18:13:49 +02:00
parent 8b14e4d6d6
commit 8598af05e7
5 changed files with 101 additions and 2 deletions

View File

@@ -8,6 +8,10 @@ service Accounting {
// all supplied lines atomically when journal_id identifies an existing one.
rpc PostJournal(PostJournalRequest) returns (Journal);
// Permanently lock a balanced journal. This is an explicit action; becoming
// balanced never locks a journal automatically.
rpc LockJournal(LockJournalRequest) returns (Journal);
// Return journal lines and credits-minus-debits informational balance.
rpc GetJournal(GetJournalRequest) returns (Journal);
@@ -58,6 +62,11 @@ message JournalLineInput {
string description = 4;
}
message LockJournalRequest {
string profile_name = 1;
int64 journal_id = 2;
}
message GetJournalRequest {
string profile_name = 1;
int64 journal_id = 2;
@@ -149,4 +158,7 @@ message Journal {
string total_credit = 8;
// Informational difference calculated as credits minus debits.
string balance = 9;
bool locked = 10;
string locked_at = 11;
string locked_by_user_id = 12;
}

Binary file not shown.

View File

@@ -31,6 +31,13 @@ pub struct JournalLineInput {
pub description: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LockJournalRequest {
#[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String,
#[prost(int64, tag = "2")]
pub journal_id: i64,
}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetJournalRequest {
#[prost(string, tag = "1")]
pub profile_name: ::prost::alloc::string::String,
@@ -167,6 +174,12 @@ pub struct Journal {
/// Informational difference calculated as credits minus debits.
#[prost(string, tag = "9")]
pub balance: ::prost::alloc::string::String,
#[prost(bool, tag = "10")]
pub locked: bool,
#[prost(string, tag = "11")]
pub locked_at: ::prost::alloc::string::String,
#[prost(string, tag = "12")]
pub locked_by_user_id: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
@@ -313,6 +326,29 @@ pub mod accounting_client {
.insert(GrpcMethod::new("komp_ac.accounting.Accounting", "PostJournal"));
self.inner.unary(req, path, codec).await
}
/// Permanently lock a balanced journal. This is an explicit action; becoming
/// balanced never locks a journal automatically.
pub async fn lock_journal(
&mut self,
request: impl tonic::IntoRequest<super::LockJournalRequest>,
) -> std::result::Result<tonic::Response<super::Journal>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.accounting.Accounting/LockJournal",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("komp_ac.accounting.Accounting", "LockJournal"));
self.inner.unary(req, path, codec).await
}
/// Return journal lines and credits-minus-debits informational balance.
pub async fn get_journal(
&mut self,
@@ -443,6 +479,12 @@ pub mod accounting_server {
&self,
request: tonic::Request<super::PostJournalRequest>,
) -> std::result::Result<tonic::Response<super::Journal>, tonic::Status>;
/// Permanently lock a balanced journal. This is an explicit action; becoming
/// balanced never locks a journal automatically.
async fn lock_journal(
&self,
request: tonic::Request<super::LockJournalRequest>,
) -> std::result::Result<tonic::Response<super::Journal>, tonic::Status>;
/// Return journal lines and credits-minus-debits informational balance.
async fn get_journal(
&self,
@@ -593,6 +635,51 @@ pub mod accounting_server {
};
Box::pin(fut)
}
"/komp_ac.accounting.Accounting/LockJournal" => {
#[allow(non_camel_case_types)]
struct LockJournalSvc<T: Accounting>(pub Arc<T>);
impl<
T: Accounting,
> tonic::server::UnaryService<super::LockJournalRequest>
for LockJournalSvc<T> {
type Response = super::Journal;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::LockJournalRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as Accounting>::lock_journal(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = LockJournalSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/komp_ac.accounting.Accounting/GetJournal" => {
#[allow(non_camel_case_types)]
struct GetJournalSvc<T: Accounting>(pub Arc<T>);

2
server

Submodule server updated: 3d145bfc4b...58f10e086a