This commit is contained in:
che
2026-07-25 13:18:07 +05:00
parent 0544d41b54
commit 249a4b455e
10 changed files with 824 additions and 212 deletions
+13 -1
View File
@@ -1,6 +1,6 @@
use che_tauri::{Filter, FilterSet};
use super::models::{Employee, Message, Task};
use super::models::{Employee, Message, Task, TaskTransfer};
static EMPLOYEE_FILTERS: &[Filter] = &[
Filter::exact("id"),
@@ -24,6 +24,14 @@ static MESSAGE_FILTERS: &[Filter] = &[
Filter::exact("employee_id"),
];
static TASK_TRANSFER_FILTERS: &[Filter] = &[
Filter::exact("id"),
Filter::exact("employee_from_id"),
Filter::exact("employee_to_id"),
Filter::exact("status"),
Filter::exact("typ"),
];
pub fn employee_filterset() -> FilterSet<Employee> {
FilterSet::new(EMPLOYEE_FILTERS)
}
@@ -35,3 +43,7 @@ pub fn task_filterset() -> FilterSet<Task> {
pub fn message_filterset() -> FilterSet<Message> {
FilterSet::new(MESSAGE_FILTERS)
}
pub fn task_transfer_filterset() -> FilterSet<TaskTransfer> {
FilterSet::new(TASK_TRANSFER_FILTERS)
}
+8 -1
View File
@@ -21,11 +21,18 @@ impl AppModule for TaskModule {
serializers::employee_serializer(),
filters::employee_filterset(),
);
ctx.resource::<models::Task>(
ctx.remote_resource::<models::Task>(
"task",
"/api/persone/task",
serializers::task_serializer(),
filters::task_filterset(),
);
ctx.remote_resource::<models::TaskTransfer>(
"task_transfer",
"/api/persone/task_transfer",
serializers::task_transfer_serializer(),
filters::task_transfer_filterset(),
);
ctx.resource::<models::Message>(
"message",
serializers::message_serializer(),
@@ -42,3 +42,22 @@ pub struct Message {
pub text: String,
}
#[derive(Debug, Clone, Model)]
#[model(table = "task_transfer")]
pub struct TaskTransfer {
#[field(primary_key)]
pub id: i64,
#[field(foreign_key = Employee)]
pub employee_from_id: Option<i64>,
#[field(foreign_key = Employee)]
pub employee_to_id: Option<i64>,
pub date_create: String,
pub status: String,
pub typ: String,
}
@@ -1,6 +1,6 @@
use che_tauri::{Field, ModelSerializer};
use super::models::{Employee, Message, Task};
use super::models::{Employee, Message, Task, TaskTransfer};
static EMPLOYEE_FIELDS: &[Field] = &[
Field::new("id").read_only(),
@@ -23,6 +23,15 @@ static MESSAGE_FIELDS: &[Field] = &[
Field::new("text"),
];
static TASK_TRANSFER_FIELDS: &[Field] = &[
Field::new("id").read_only(),
Field::new("employee_from_id").required(false).nullable(),
Field::new("employee_to_id").required(false).nullable(),
Field::new("date_create").read_only(),
Field::new("status"),
Field::new("typ"),
];
pub fn employee_serializer() -> ModelSerializer<Employee> {
ModelSerializer::new(EMPLOYEE_FIELDS)
}
@@ -34,3 +43,7 @@ pub fn task_serializer() -> ModelSerializer<Task> {
pub fn message_serializer() -> ModelSerializer<Message> {
ModelSerializer::new(MESSAGE_FIELDS)
}
pub fn task_transfer_serializer() -> ModelSerializer<TaskTransfer> {
ModelSerializer::new(TASK_TRANSFER_FIELDS)
}
+48
View File
@@ -6,6 +6,14 @@ use tauri::Manager;
use crate::sync::SyncContractsResult;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct CurrentEmployee {
id: i64,
name: String,
short_name: String,
avatar: Option<String>,
}
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
@@ -43,6 +51,45 @@ fn auth_status(api: tauri::State<'_, TauriApi>) -> bool {
api.is_authenticated()
}
#[tauri::command]
async fn current_employee(api: tauri::State<'_, TauriApi>) -> Result<CurrentEmployee, ApiError> {
let remote = api
.state()
.config
.remote
.as_ref()
.ok_or_else(|| ApiError::bad_request("current_employee requires [remote].base_url config"))?;
let token = api
.state()
.auth_token()
.ok_or_else(|| ApiError::new("not_authenticated", "authentication token is missing"))?;
let response = reqwest::Client::new()
.get(format!(
"{}/api/persone/employee/who_im/",
remote.base_url.trim_end_matches('/')
))
.header(reqwest::header::AUTHORIZATION, format!("Token {token}"))
.send()
.await
.map_err(|error| ApiError::new("remote_error", error.to_string()))?;
if !response.status().is_success() {
let status = response.status();
let detail = response.text().await.unwrap_or_default();
return Err(ApiError::new(
"remote_error",
format!("who_im request failed with {status}: {detail}"),
));
}
response
.json::<CurrentEmployee>()
.await
.map_err(|error| ApiError::new("remote_error", error.to_string()))
}
#[tauri::command]
async fn sync_contracts(
app: tauri::AppHandle,
@@ -116,6 +163,7 @@ pub fn run() {
auth_set_token,
auth_logout,
auth_status,
current_employee,
sync_contracts,
load_application_file
])