feat: add update project functionality and corresponding DTO
This commit is contained in:
parent
fa098217f1
commit
621c41d793
10 changed files with 46 additions and 11 deletions
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Delete Project
|
||||
type: http
|
||||
seq: 4
|
||||
seq: 5
|
||||
}
|
||||
|
||||
delete {
|
||||
|
|
22
bruno/project/Update Project.bru
Normal file
22
bruno/project/Update Project.bru
Normal file
|
@ -0,0 +1,22 @@
|
|||
meta {
|
||||
name: Update Project
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
put {
|
||||
url: {{api_base}}/project
|
||||
body: json
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"id": "{{project_to_change}}",
|
||||
"name": "ThisProjectHasBeenChanged!"
|
||||
}
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
project_to_change: 77d0394b-6d61-44a9-97a8-35caa101dc0e
|
||||
}
|
|
@ -4,6 +4,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
|||
cfg.service(get_classes)
|
||||
.service(get_class)
|
||||
.service(create_class)
|
||||
.service(update_class)
|
||||
.service(delete_class);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
|||
cfg.service(get_groups)
|
||||
.service(get_groups_for_project)
|
||||
.service(create_group)
|
||||
.service(update_group)
|
||||
.service(delete_group);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
use actix_web::{Responder, Result, delete, get, post, put, web};
|
||||
use actix_web::{Result, delete, get, post, put, web};
|
||||
use sea_orm::prelude::Uuid;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::dto::project::UpdateProject;
|
||||
|
||||
use crate::db::Database;
|
||||
use crate::error::ApiError;
|
||||
|
||||
// Maybe move this here into the corresponding DTO file
|
||||
#[derive(Deserialize)]
|
||||
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)
|
||||
.service(create_project)
|
||||
.service(update_project)
|
||||
.service(delete_project);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
|||
cfg.service(get_templates)
|
||||
.service(get_template)
|
||||
.service(create_template)
|
||||
.service(update_template)
|
||||
.service(delete_template);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@ use super::Database;
|
|||
use crate::error::ApiError;
|
||||
use log::debug;
|
||||
|
||||
use crate::dto::project::UpdateProject;
|
||||
|
||||
use entity::project;
|
||||
use sea_orm::ActiveValue::{NotSet, Set};
|
||||
use sea_orm::ActiveValue::{NotSet, Set, Unchanged};
|
||||
use sea_orm::prelude::Uuid;
|
||||
use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait};
|
||||
|
||||
|
@ -44,8 +46,8 @@ impl Database {
|
|||
debug!("Updating project with id: {}", &project.id);
|
||||
|
||||
let active_model = project::ActiveModel {
|
||||
id: NotSet,
|
||||
name: Set(project.name.to_owned()),
|
||||
id: Unchanged(project.id),
|
||||
name: Set(project.name),
|
||||
};
|
||||
|
||||
let project = active_model.update(&self.conn).await?;
|
||||
|
|
1
crates/backend/src/dto.rs
Normal file
1
crates/backend/src/dto.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod project;
|
8
crates/backend/src/dto/project.rs
Normal file
8
crates/backend/src/dto/project.rs
Normal file
|
@ -0,0 +1,8 @@
|
|||
use sea_orm::prelude::Uuid;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct UpdateProject {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
|
@ -7,6 +7,7 @@ use log::debug;
|
|||
|
||||
mod controller;
|
||||
mod db;
|
||||
mod dto;
|
||||
mod error;
|
||||
|
||||
#[actix_web::main]
|
||||
|
|
Loading…
Add table
Reference in a new issue