avoid &str in place where ProjectId could be used

This commit is contained in:
Sebastian Thiel 2024-04-15 16:20:36 +02:00
parent e2ef2dc721
commit 62b1c49372
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
2 changed files with 6 additions and 27 deletions

View File

@ -2,7 +2,6 @@ pub mod commands {
use anyhow::Context;
use std::path;
use gitbutler_core::error;
use gitbutler_core::error::Code;
use gitbutler_core::projects::{self, controller::Controller, ProjectId};
use tauri::Manager;
@ -40,12 +39,8 @@ pub mod commands {
#[instrument(skip(handle), err(Debug))]
pub async fn get_project(
handle: tauri::AppHandle,
id: &str,
id: ProjectId,
) -> Result<projects::Project, Error> {
let id = id.parse().context(error::Context::new_static(
Code::Validation,
"Malformed project id",
))?;
handle
.state::<Controller>()
.get(&id)
@ -63,11 +58,7 @@ pub mod commands {
/// We use it to start watching for filesystem events.
#[tauri::command(async)]
#[instrument(skip(handle), err(Debug))]
pub async fn set_project_active(handle: tauri::AppHandle, id: &str) -> Result<(), Error> {
let id: ProjectId = id.parse().context(error::Context::new_static(
Code::Validation,
"Malformed project id",
))?;
pub async fn set_project_active(handle: tauri::AppHandle, id: ProjectId) -> Result<(), Error> {
let project = handle
.state::<Controller>()
.get(&id)
@ -77,11 +68,7 @@ pub mod commands {
#[tauri::command(async)]
#[instrument(skip(handle), err(Debug))]
pub async fn delete_project(handle: tauri::AppHandle, id: &str) -> Result<(), Error> {
let id = id.parse().context(error::Context::new_static(
Code::Validation,
"Malformed project id",
))?;
pub async fn delete_project(handle: tauri::AppHandle, id: ProjectId) -> Result<(), Error> {
handle
.state::<Controller>()
.delete(&id)
@ -93,13 +80,9 @@ pub mod commands {
#[instrument(skip(handle), err(Debug))]
pub async fn git_get_local_config(
handle: tauri::AppHandle,
id: &str,
id: ProjectId,
key: &str,
) -> Result<Option<String>, Error> {
let id = id.parse().context(error::Context::new_static(
Code::Validation,
"Malformed project id",
))?;
Ok(handle
.state::<Controller>()
.get_local_config(&id, key)
@ -110,14 +93,10 @@ pub mod commands {
#[instrument(skip(handle), err(Debug))]
pub async fn git_set_local_config(
handle: tauri::AppHandle,
id: &str,
id: ProjectId,
key: &str,
value: &str,
) -> Result<(), Error> {
let id = id.parse().context(error::Context::new_static(
Code::Validation,
"Malformed project id",
))?;
Ok(handle
.state::<Controller>()
.set_local_config(&id, key, value)

View File

@ -22,7 +22,7 @@ impl super::Handler {
.context("failed to insert deltas into database")
}
pub fn reindex(&self, project_id: ProjectId) -> Result<()> {
pub(in crate::watcher) fn reindex(&self, project_id: ProjectId) -> Result<()> {
let user = self.users.get_user()?;
let project = self.projects.get(&project_id)?;
let project_repository =