feat: add endpoints to retrieve all projects and a specific project
Some checks failed
ci/woodpecker/push/check_fmt Pipeline failed
Some checks failed
ci/woodpecker/push/check_fmt Pipeline failed
get specific project is not working yet
This commit is contained in:
parent
e2de7467ed
commit
c1e5f60fac
7 changed files with 82 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Create Project
|
||||
type: http
|
||||
seq: 1
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
meta {
|
||||
name: Delete Project
|
||||
type: http
|
||||
seq: 2
|
||||
seq: 4
|
||||
}
|
||||
|
||||
delete {
|
||||
|
|
11
bruno/project/Get Projects.bru
Normal file
11
bruno/project/Get Projects.bru
Normal file
|
@ -0,0 +1,11 @@
|
|||
meta {
|
||||
name: Get Projects
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{api_base}}/project
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
15
bruno/project/Get specific Project.bru
Normal file
15
bruno/project/Get specific Project.bru
Normal file
|
@ -0,0 +1,15 @@
|
|||
meta {
|
||||
name: Get specific Project
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{api_base}}/project/:id
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:path {
|
||||
id: 1c2bc42d-20d7-4cec-953f-acf691bad55a
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use actix_web::{Responder, Result, delete, get, post, web};
|
||||
use log::info;
|
||||
use log::debug;
|
||||
use sea_orm::prelude::Uuid;
|
||||
use serde::Deserialize;
|
||||
|
||||
|
@ -17,6 +17,30 @@ pub fn setup(cfg: &mut actix_web::web::ServiceConfig) {
|
|||
.service(get_projects);
|
||||
}
|
||||
|
||||
#[get("")]
|
||||
async fn get_projects(
|
||||
db: web::Data<Database>,
|
||||
) -> Result<web::Json<Vec<entity::project::Model>>, ApiError> {
|
||||
debug!("Fetching all projects");
|
||||
|
||||
let projects = db.get_projects().await?;
|
||||
|
||||
Ok(web::Json(projects))
|
||||
}
|
||||
|
||||
#[get("/{id}")]
|
||||
async fn get_project(
|
||||
db: web::Data<Database>,
|
||||
path: web::Path<Uuid>,
|
||||
) -> Result<web::Json<entity::project::Model>, ApiError> {
|
||||
debug!("Fetching project with id: {}", path);
|
||||
let id = path.into_inner();
|
||||
|
||||
let project = db.get_project(&id).await?;
|
||||
|
||||
Ok(web::Json(project.unwrap()))
|
||||
}
|
||||
|
||||
#[post("")]
|
||||
async fn create_project(
|
||||
db: web::Data<Database>,
|
||||
|
@ -40,8 +64,3 @@ async fn delete_project(
|
|||
result.rows_affected, id
|
||||
)))
|
||||
}
|
||||
|
||||
#[get("")]
|
||||
async fn get_projects() -> impl Responder {
|
||||
""
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::Database;
|
||||
use crate::error::ApiError;
|
||||
use log::info;
|
||||
use log::debug;
|
||||
|
||||
use entity::project;
|
||||
use sea_orm::ActiveValue::{NotSet, Set};
|
||||
|
@ -8,7 +8,30 @@ use sea_orm::prelude::Uuid;
|
|||
use sea_orm::{ActiveModelTrait, DeleteResult, EntityTrait};
|
||||
|
||||
impl Database {
|
||||
pub async fn get_projects(&self) -> Result<Vec<project::Model>, ApiError> {
|
||||
debug!("Fetching all projects");
|
||||
|
||||
let projects = project::Entity::find().all(&self.conn).await?;
|
||||
Ok(projects)
|
||||
}
|
||||
|
||||
// TODO: This is not working yet
|
||||
pub async fn get_project(&self, id: &Uuid) -> Result<Option<project::Model>, ApiError> {
|
||||
debug!("Fetching project with id: {}", id);
|
||||
|
||||
let project = project::Entity::find_by_id(id.to_owned())
|
||||
.one(&self.conn)
|
||||
.await?;
|
||||
|
||||
if project.is_none() {
|
||||
return Err(ApiError::NotFound);
|
||||
}
|
||||
Ok(project)
|
||||
}
|
||||
|
||||
pub async fn create_project(&self, name: &str) -> Result<project::Model, ApiError> {
|
||||
debug!("Creating project with name: {}", name);
|
||||
|
||||
let project = project::ActiveModel {
|
||||
id: NotSet,
|
||||
name: Set(name.to_owned()),
|
||||
|
@ -19,7 +42,7 @@ impl Database {
|
|||
}
|
||||
|
||||
pub async fn delete_project(&self, id: &Uuid) -> Result<DeleteResult, ApiError> {
|
||||
info!("Deleting project with id: {}", id);
|
||||
debug!("Deleting project with id: {}", id);
|
||||
|
||||
let project = project::Entity::delete_by_id(id.to_owned())
|
||||
.exec(&self.conn)
|
||||
|
|
|
@ -2,4 +2,8 @@ use super::Database;
|
|||
|
||||
impl Database {
|
||||
async fn create_user() {}
|
||||
|
||||
async fn verify_user() {}
|
||||
|
||||
async fn change_user_password() {}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue