backend: license delete and update endpoints
This commit is contained in:
parent
2a36ad52ec
commit
c52d1290c7
2 changed files with 38 additions and 1 deletions
|
@ -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<AppState>,
|
||||
license: web::Json<entity::license::Model>,
|
||||
path: Path<Uuid>,
|
||||
_executor: AuthedUser,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
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<AppState>,
|
||||
path: Path<Uuid>,
|
||||
_executor: AuthedUser,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let db = &state.db;
|
||||
entity::license::Entity::delete_by_id(path.into_inner())
|
||||
.exec(db)
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?;
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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))),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue