This commit is contained in:
Mika 2025-04-02 21:22:17 +02:00
parent d6714aa7d9
commit 1ad0e4400a
7 changed files with 62 additions and 8 deletions

View file

@ -1,4 +1,4 @@
use actix_web::{Responder, delete, get, post};
use actix_web::{Responder, delete, get, post, put};
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(get_classes)
@ -22,6 +22,11 @@ async fn create_class() -> impl Responder {
""
}
#[put("")]
async fn change_class() -> impl Responder {
""
}
#[delete("/{id}")]
async fn delete_class() -> impl Responder {
""

View file

@ -1,4 +1,4 @@
use actix_web::{Responder, delete, get, post};
use actix_web::{Responder, delete, get, post, put};
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(get_groups)
@ -22,6 +22,11 @@ async fn create_group() -> impl Responder {
""
}
#[put("")]
async fn change_group() -> impl Responder {
""
}
#[delete("/{id}")]
async fn delete_group() -> impl Responder {
""

View file

@ -1,5 +1,4 @@
use actix_web::{Result, delete, get, post, web};
use log::debug;
use actix_web::{Responder, Result, delete, get, post, put, web};
use sea_orm::prelude::Uuid;
use serde::Deserialize;
@ -11,6 +10,12 @@ struct CreateProject {
name: String,
}
#[derive(Deserialize)]
struct UpdateProject {
id: Uuid,
name: String,
}
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(get_project)
.service(get_projects)
@ -49,6 +54,18 @@ async fn create_project(
Ok(web::Json(result))
}
#[put("")]
async fn change_project(
db: web::Data<Database>,
update_project_struct: web::Json<UpdateProject>,
) -> Result<web::Json<entity::project::Model>, ApiError> {
let updated_project = db
.update_project(update_project_struct.into_inner())
.await?;
Ok(web::Json(updated_project))
}
#[delete("/{id}")]
async fn delete_project(
db: web::Data<Database>,

View file

@ -1,4 +1,4 @@
use actix_web::{Responder, delete, get, post};
use actix_web::{Responder, delete, get, post, put};
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(get_templates)
@ -22,6 +22,11 @@ async fn create_template() -> impl Responder {
""
}
#[put("")]
async fn change_template() -> impl Responder {
""
}
#[delete("/{id}")]
async fn delete_template() -> impl Responder {
""

View file

@ -1,4 +1,4 @@
use actix_web::{Responder, delete, get, post};
use actix_web::{Responder, delete, get, post, put};
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
cfg.service(get_users)
@ -22,6 +22,11 @@ async fn create_user() -> impl Responder {
""
}
#[put("")]
async fn change_user() -> impl Responder {
""
}
#[delete("/{id}")]
async fn delete_user() -> impl Responder {
""

View file

@ -1,3 +1,7 @@
fn add_user_to_group() {}
use super::Database;
fn create_group() {}
impl Database {
async fn add_user_to_group(&self) {}
async fn create_group(&self) {}
}

View file

@ -40,6 +40,19 @@ impl Database {
Ok(project)
}
pub async fn update_project(&self, project: UpdateProject) -> Result<project::Model, ApiError> {
debug!("Updating project with id: {}", &project.id);
let active_model = project::ActiveModel {
id: NotSet,
name: Set(project.name.to_owned()),
};
let project = active_model.update(&self.conn).await?;
Ok(project)
}
pub async fn delete_project(&self, id: &Uuid) -> Result<DeleteResult, ApiError> {
debug!("Deleting project with id: {}", id);