* DRAFT chore(backend): upgrade sqlx to ^0.7 related to: * https://github.com/windmill-labs/windmill/pull/1858 * https://github.com/launchbadge/sqlx/issues/1163#issuecomment-1627685514 * (vol. 2) in 0.7, `Transaction` can no longer implement `Executor` directly ref:afb6b1066e/examples/postgres/transaction/src/main.rs (L14-L17)notice that I'm temporarly using my custom patch16e4c9a8f3it's related to https://github.com/launchbadge/sqlx/issues/2611 * post git rebase chores * use upstream fix from 0.7.1 * fix compile --------- Co-authored-by: Ruben Fiszel <ruben@windmill.dev> Co-authored-by: Ruben Fiszel <ruben@rubenfiszel.com>
78 lines
1.9 KiB
Rust
78 lines
1.9 KiB
Rust
/*
|
|
* Author: Ruben Fiszel
|
|
* Copyright: Windmill Labs, Inc 2022
|
|
* This file and its contents are licensed under the AGPLv3 License.
|
|
* Please see the included NOTICE for copyright information and
|
|
* LICENSE-AGPL for a copy of the license.
|
|
*/
|
|
|
|
use crate::{db::DB, users::Authed};
|
|
use axum::{
|
|
extract::{Extension, Path},
|
|
routing::post,
|
|
Json, Router,
|
|
};
|
|
use windmill_common::error::Result;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
pub fn workspaced_service() -> Router {
|
|
Router::new()
|
|
.route("/star", post(star))
|
|
.route("/unstar", post(unstar))
|
|
}
|
|
|
|
#[derive(sqlx::Type, Serialize, Deserialize, Debug, PartialEq, Clone)]
|
|
#[sqlx(type_name = "FAVORITE_KIND", rename_all = "lowercase")]
|
|
#[serde(rename_all(serialize = "lowercase", deserialize = "lowercase"))]
|
|
pub enum FavoriteKind {
|
|
Script,
|
|
Flow,
|
|
App,
|
|
#[allow(non_camel_case_types)]
|
|
Raw_App,
|
|
}
|
|
#[derive(Deserialize)]
|
|
pub struct Favorite {
|
|
pub favorite_kind: FavoriteKind,
|
|
pub path: String,
|
|
}
|
|
|
|
async fn star(
|
|
authed: Authed,
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
Json(Favorite { favorite_kind, path }): Json<Favorite>,
|
|
) -> Result<String> {
|
|
sqlx::query!(
|
|
"INSERT INTO favorite (workspace_id, usr, path, favorite_kind) VALUES ($1, $2, $3, $4) ON CONFLICT DO NOTHING",
|
|
&w_id,
|
|
authed.username,
|
|
path,
|
|
favorite_kind as FavoriteKind,
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
|
|
Ok(format!("Starred {}", path))
|
|
}
|
|
|
|
async fn unstar(
|
|
authed: Authed,
|
|
Extension(db): Extension<DB>,
|
|
Path(w_id): Path<String>,
|
|
Json(Favorite { favorite_kind, path }): Json<Favorite>,
|
|
) -> Result<String> {
|
|
sqlx::query!(
|
|
"DELETE FROM favorite WHERE workspace_id = $1 AND usr = $2 AND path = $3 AND favorite_kind = $4",
|
|
&w_id,
|
|
authed.username,
|
|
path,
|
|
favorite_kind as FavoriteKind,
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
|
|
Ok(format!("Unstarred {}", path))
|
|
}
|