diff --git a/crates/backend/src/controller/license.rs b/crates/backend/src/controller/license.rs index db698e5..31b1d33 100644 --- a/crates/backend/src/controller/license.rs +++ b/crates/backend/src/controller/license.rs @@ -1,6 +1,11 @@ -use actix_web::{error::ErrorInternalServerError, web, Responder}; +use actix_web::{ + error::ErrorInternalServerError, + web::{self, Path}, + HttpResponse, Responder, +}; use sea_orm::{ActiveModelTrait, ActiveValue, EntityTrait, IntoActiveModel}; use serde::{Deserialize, Serialize}; +use uuid::Uuid; use crate::{auth::AuthedUser, AppState}; @@ -60,4 +65,31 @@ impl LicenseController { Ok(web::Json(res)) } + + pub async fn update_license( + state: web::Data, + license: web::Json, + path: Path, + _executor: AuthedUser, + ) -> actix_web::Result { + let db = &state.db; + let mut license = license.into_inner().into_active_model(); + let id = path.into_inner(); + license.id = ActiveValue::Set(id); + let res = license.update(db).await.map_err(ErrorInternalServerError)?; + Ok(web::Json(res)) + } + + pub async fn delete_license( + state: web::Data, + path: Path, + _executor: AuthedUser, + ) -> actix_web::Result { + let db = &state.db; + entity::license::Entity::delete_by_id(path.into_inner()) + .exec(db) + .await + .map_err(ErrorInternalServerError)?; + Ok(HttpResponse::Ok().finish()) + } } diff --git a/crates/backend/src/routes.rs b/crates/backend/src/routes.rs index 92bb913..d5a5b4f 100644 --- a/crates/backend/src/routes.rs +++ b/crates/backend/src/routes.rs @@ -15,6 +15,11 @@ pub fn config(cfg: &mut web::ServiceConfig) { .get(LicenseController::list_groups) .post(LicenseController::create_license), ) + .service( + web::resource("/licenses/{license_id}") + .delete(LicenseController::delete_license) + .put(LicenseController::update_license), + ) .route("/groups", web::post().to(LicenseController::create_group)) .service(web::scope("/auth").route("/login", web::post().to(AuthController::login))), );