refactor: reorganize project structure and add new endpoints for group and user management
Some checks failed
ci/woodpecker/push/check_fmt Pipeline failed
Some checks failed
ci/woodpecker/push/check_fmt Pipeline failed
This commit is contained in:
parent
693ce67806
commit
e2de7467ed
20 changed files with 107 additions and 17 deletions
3
bruno/group/folder.bru
Normal file
3
bruno/group/folder.bru
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
meta {
|
||||||
|
name: group
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
meta {
|
|
||||||
name: groups
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ meta {
|
||||||
}
|
}
|
||||||
|
|
||||||
post {
|
post {
|
||||||
url: {{api_base}}/projects
|
url: {{api_base}}/project
|
||||||
body: json
|
body: json
|
||||||
auth: inherit
|
auth: inherit
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,4 @@ body:json {
|
||||||
|
|
||||||
vars:pre-request {
|
vars:pre-request {
|
||||||
name: FillThisOutButDontCommitIt!
|
name: FillThisOutButDontCommitIt!
|
||||||
}
|
}
|
15
bruno/project/Delete Project.bru
Normal file
15
bruno/project/Delete Project.bru
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
meta {
|
||||||
|
name: Delete Project
|
||||||
|
type: http
|
||||||
|
seq: 2
|
||||||
|
}
|
||||||
|
|
||||||
|
delete {
|
||||||
|
url: {{api_base}}/project/:id
|
||||||
|
body: none
|
||||||
|
auth: inherit
|
||||||
|
}
|
||||||
|
|
||||||
|
params:path {
|
||||||
|
id: MyAwesomeUUIDHere!
|
||||||
|
}
|
3
bruno/project/folder.bru
Normal file
3
bruno/project/folder.bru
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
meta {
|
||||||
|
name: project
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
meta {
|
|
||||||
name: projects
|
|
||||||
}
|
|
3
bruno/user/folder.bru
Normal file
3
bruno/user/folder.bru
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
meta {
|
||||||
|
name: user
|
||||||
|
}
|
|
@ -1,3 +0,0 @@
|
||||||
meta {
|
|
||||||
name: users
|
|
||||||
}
|
|
|
@ -17,6 +17,7 @@ argon2 = "0.5.3"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
|
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
|
log = "0.4"
|
||||||
|
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
sea-orm = { version = "1.1", features = [
|
sea-orm = { version = "1.1", features = [
|
||||||
|
|
|
@ -7,5 +7,9 @@ mod template;
|
||||||
mod user;
|
mod user;
|
||||||
|
|
||||||
pub fn register_controllers(cfg: &mut ServiceConfig) {
|
pub fn register_controllers(cfg: &mut ServiceConfig) {
|
||||||
cfg.service(web::scope("/projects").configure(project::setup));
|
cfg.service(web::scope("/project").configure(project::setup))
|
||||||
|
.service(web::scope("/group").configure(group::setup))
|
||||||
|
.service(web::scope("/user").configure(user::setup))
|
||||||
|
.service(web::scope("/class").configure(class::setup))
|
||||||
|
.service(web::scope("/template").configure(template::setup));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post};
|
||||||
|
|
||||||
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
cfg.service(get_classes)
|
||||||
|
.service(get_class)
|
||||||
|
.service(create_class)
|
||||||
|
.service(delete_class);
|
||||||
|
}
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
async fn get_classes() -> impl Responder {
|
async fn get_classes() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post};
|
||||||
|
|
||||||
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
cfg.service(get_groups)
|
||||||
|
.service(get_groups_for_project)
|
||||||
|
.service(create_group)
|
||||||
|
.service(delete_group);
|
||||||
|
}
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
async fn get_groups() -> impl Responder {
|
async fn get_groups() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
use actix_web::{Responder, Result, delete, get, post, web};
|
use actix_web::{Responder, Result, delete, get, post, web};
|
||||||
|
use log::info;
|
||||||
|
use sea_orm::prelude::Uuid;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::db::Database;
|
use crate::db::Database;
|
||||||
|
@ -10,7 +12,9 @@ struct CreateProject {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(create_project);
|
cfg.service(create_project)
|
||||||
|
.service(delete_project)
|
||||||
|
.service(get_projects);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("")]
|
#[post("")]
|
||||||
|
@ -24,8 +28,17 @@ async fn create_project(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/{id}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_project() -> impl Responder {
|
async fn delete_project(
|
||||||
""
|
db: web::Data<Database>,
|
||||||
|
path: web::Path<Uuid>,
|
||||||
|
) -> Result<web::Json<String>, ApiError> {
|
||||||
|
let id = path.into_inner();
|
||||||
|
let result = db.delete_project(&id).await?;
|
||||||
|
|
||||||
|
Ok(web::Json(format!(
|
||||||
|
"Successfully deleted {} project/s with the id: {}",
|
||||||
|
result.rows_affected, id
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post};
|
||||||
|
|
||||||
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
cfg.service(get_templates)
|
||||||
|
.service(get_template)
|
||||||
|
.service(create_template)
|
||||||
|
.service(delete_template);
|
||||||
|
}
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
async fn get_templates() -> impl Responder {
|
async fn get_templates() -> impl Responder {
|
||||||
""
|
""
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
use actix_web::{Responder, delete, get, post};
|
use actix_web::{Responder, delete, get, post};
|
||||||
|
|
||||||
|
pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
cfg.service(get_users)
|
||||||
|
.service(get_user)
|
||||||
|
.service(create_user)
|
||||||
|
.service(delete_user);
|
||||||
|
}
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
async fn get_users() -> impl Responder {
|
async fn get_users() -> impl Responder {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/{id}")]
|
#[get("/{id}")]
|
||||||
async fn get_class() -> impl Responder {
|
async fn get_user() -> impl Responder {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use sea_orm::{ConnectOptions, DatabaseConnection};
|
use sea_orm::{ConnectOptions, DatabaseConnection};
|
||||||
|
|
||||||
|
mod group;
|
||||||
mod project;
|
mod project;
|
||||||
|
mod user;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Database {
|
pub struct Database {
|
||||||
|
|
3
crates/backend/src/db/group.rs
Normal file
3
crates/backend/src/db/group.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
fn add_user_to_group() {}
|
||||||
|
|
||||||
|
fn create_group() {}
|
|
@ -1,9 +1,11 @@
|
||||||
use super::Database;
|
use super::Database;
|
||||||
use crate::error::ApiError;
|
use crate::error::ApiError;
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use entity::project;
|
use entity::project;
|
||||||
use sea_orm::ActiveModelTrait;
|
|
||||||
use sea_orm::ActiveValue::{NotSet, Set};
|
use sea_orm::ActiveValue::{NotSet, Set};
|
||||||
|
use sea_orm::prelude::Uuid;
|
||||||
|
use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait};
|
||||||
|
|
||||||
impl Database {
|
impl Database {
|
||||||
pub async fn create_project(&self, name: &str) -> Result<project::Model, ApiError> {
|
pub async fn create_project(&self, name: &str) -> Result<project::Model, ApiError> {
|
||||||
|
@ -15,4 +17,18 @@ impl Database {
|
||||||
let project = project.insert(&self.conn).await?;
|
let project = project.insert(&self.conn).await?;
|
||||||
Ok(project)
|
Ok(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_project(&self, id: &Uuid) -> Result<DeleteResult, ApiError> {
|
||||||
|
info!("Deleting project with id: {}", id);
|
||||||
|
|
||||||
|
let project = project::Entity::delete_by_id(id.to_owned())
|
||||||
|
.exec(&self.conn)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
if project.rows_affected == 0 {
|
||||||
|
return Err(ApiError::NotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(project)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
5
crates/backend/src/db/user.rs
Normal file
5
crates/backend/src/db/user.rs
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
use super::Database;
|
||||||
|
|
||||||
|
impl Database {
|
||||||
|
async fn create_user() {}
|
||||||
|
}
|
|
@ -5,12 +5,15 @@ use thiserror::Error;
|
||||||
pub enum ApiError {
|
pub enum ApiError {
|
||||||
#[error("Database Error: {0}")]
|
#[error("Database Error: {0}")]
|
||||||
Database(#[from] sea_orm::DbErr),
|
Database(#[from] sea_orm::DbErr),
|
||||||
|
#[error("Not Found")]
|
||||||
|
NotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ResponseError for ApiError {
|
impl ResponseError for ApiError {
|
||||||
fn status_code(&self) -> StatusCode {
|
fn status_code(&self) -> StatusCode {
|
||||||
match self {
|
match self {
|
||||||
ApiError::Database(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
ApiError::Database(..) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
ApiError::NotFound => StatusCode::NOT_FOUND,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue