update_project endpoint and DTOs #29
12 changed files with 99 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
meta {
|
meta {
|
||||||
name: Delete Project
|
name: Delete Project
|
||||||
type: http
|
type: http
|
||||||
seq: 4
|
seq: 5
|
||||||
}
|
}
|
||||||
|
|
||||||
delete {
|
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
|
||||||
|
}
|
|
@ -1,9 +1,10 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post, put};
|
||||||
|
|
||||||
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(get_classes)
|
cfg.service(get_classes)
|
||||||
.service(get_class)
|
.service(get_class)
|
||||||
.service(create_class)
|
.service(create_class)
|
||||||
|
.service(update_class)
|
||||||
.service(delete_class);
|
.service(delete_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +23,11 @@ async fn create_class() -> impl Responder {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("")]
|
||||||
|
async fn update_class() -> impl Responder {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
#[delete("/{id}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_class() -> impl Responder {
|
async fn delete_class() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post, put};
|
||||||
|
|
||||||
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(get_groups)
|
cfg.service(get_groups)
|
||||||
.service(get_groups_for_project)
|
.service(get_groups_for_project)
|
||||||
.service(create_group)
|
.service(create_group)
|
||||||
|
.service(update_group)
|
||||||
.service(delete_group);
|
.service(delete_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +23,11 @@ async fn create_group() -> impl Responder {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("")]
|
||||||
|
async fn update_group() -> impl Responder {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
#[delete("/{id}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_group() -> impl Responder {
|
async fn delete_group() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
use actix_web::{Result, delete, get, post, web};
|
use actix_web::{Result, delete, get, post, put, web};
|
||||||
use log::debug;
|
|
||||||
use sea_orm::prelude::Uuid;
|
use sea_orm::prelude::Uuid;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
use crate::dto::project::UpdateProject;
|
||||||
|
|
||||||
use crate::db::Database;
|
use crate::db::Database;
|
||||||
use crate::error::ApiError;
|
use crate::error::ApiError;
|
||||||
|
|
||||||
|
// Maybe move this here into the corresponding DTO file
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
struct CreateProject {
|
struct CreateProject {
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -15,6 +17,7 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(get_project)
|
cfg.service(get_project)
|
||||||
.service(get_projects)
|
.service(get_projects)
|
||||||
.service(create_project)
|
.service(create_project)
|
||||||
|
.service(update_project)
|
||||||
.service(delete_project);
|
.service(delete_project);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +52,18 @@ async fn create_project(
|
||||||
Ok(web::Json(result))
|
Ok(web::Json(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("")]
|
||||||
|
async fn update_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}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_project(
|
async fn delete_project(
|
||||||
db: web::Data<Database>,
|
db: web::Data<Database>,
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post, put};
|
||||||
|
|
||||||
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(get_templates)
|
cfg.service(get_templates)
|
||||||
.service(get_template)
|
.service(get_template)
|
||||||
.service(create_template)
|
.service(create_template)
|
||||||
|
.service(update_template)
|
||||||
.service(delete_template);
|
.service(delete_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +23,11 @@ async fn create_template() -> impl Responder {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("")]
|
||||||
|
async fn update_template() -> impl Responder {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
#[delete("/{id}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_template() -> impl Responder {
|
async fn delete_template() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -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) {
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(get_users)
|
cfg.service(get_users)
|
||||||
|
@ -22,6 +22,11 @@ async fn create_user() -> impl Responder {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[put("")]
|
||||||
|
async fn update_user() -> impl Responder {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
#[delete("/{id}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_user() -> impl Responder {
|
async fn delete_user() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -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) {}
|
||||||
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@ use super::Database;
|
||||||
use crate::error::ApiError;
|
use crate::error::ApiError;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
|
|
||||||
|
use crate::dto::project::UpdateProject;
|
||||||
|
|
||||||
use entity::project;
|
use entity::project;
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
use sea_orm::ActiveValue::{NotSet, Set, Unchanged};
|
||||||
use sea_orm::prelude::Uuid;
|
use sea_orm::prelude::Uuid;
|
||||||
use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait};
|
use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait};
|
||||||
|
|
||||||
|
@ -40,6 +42,19 @@ impl Database {
|
||||||
Ok(project)
|
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: Unchanged(project.id),
|
||||||
|
name: Set(project.name),
|
||||||
|
};
|
||||||
|
|
||||||
|
let project = active_model.update(&self.conn).await?;
|
||||||
|
|
||||||
|
Ok(project)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn delete_project(&self, id: &Uuid) -> Result<DeleteResult, ApiError> {
|
pub async fn delete_project(&self, id: &Uuid) -> Result<DeleteResult, ApiError> {
|
||||||
debug!("Deleting project with id: {}", id);
|
debug!("Deleting project with id: {}", id);
|
||||||
|
|
||||||
|
|
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 controller;
|
||||||
mod db;
|
mod db;
|
||||||
|
mod dto;
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
|
|
Loading…
Add table
Reference in a new issue