add get for nodes and add bruno files

This commit is contained in:
Mika 2024-10-08 16:00:41 +02:00
parent bbcb70d27e
commit c7f3b71fc3
8 changed files with 77 additions and 24 deletions

13
ApfelBruno/bruno.json Normal file
View file

@ -0,0 +1,13 @@
{
"version": "1",
"name": "ApfelBruno",
"type": "collection",
"ignore": [
"node_modules",
".git"
],
"presets": {
"requestType": "http",
"requestUrl": "http://localhost:8080/api/v1/"
}
}

View file

@ -0,0 +1,11 @@
meta {
name: get all nodes
type: http
seq: 3
}
get {
url: http://localhost:8080/api/v1/nodes
body: none
auth: none
}

View file

@ -0,0 +1,11 @@
meta {
name: get all users
type: http
seq: 2
}
get {
url: http://localhost:8080/api/v1/
body: none
auth: none
}

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
entity = { path = "../entity" }
argon2 = { version = "0.5" }
actix-web = "4"
actix-cors = "0.7"
@ -17,4 +18,3 @@ sea-orm = { version = "1", features = [
dotenvy = "*"
jsonwebtoken = "*"
futures = "*"
entity = { path = "../entity" }

View file

@ -1 +1,3 @@
pub mod user;
pub mod node;

View file

@ -0,0 +1,28 @@
use actix_web::{error::ErrorInternalServerError, web, Responder};
use entity::node_group;
use sea_orm::EntityTrait;
use serde::{Deserialize, Serialize};
use crate::AppState;
#[derive(Serialize)]
struct GroupWithNode {
#[serde(flatten)]
group: entity::node_group::Model,
node: Vec<entity::node::Model>,
}
pub async fn get_nodes(state: web::Data<AppState>) -> actix_web::Result<impl Responder> {
let db = &state.db;
let result = node_group::Entity::find()
.find_with_related(entity::prelude::Node)
.all(db)
.await
.map_err(ErrorInternalServerError)?
.into_iter()
.map(|(group, node)| GroupWithNode { group, node })
.collect::<Vec<_>>();
Ok(web::Json(result))
}

View file

@ -4,9 +4,7 @@ use argon2::{
Argon2,
};
use entity::user;
use sea_orm::{
entity::prelude::DateTime, prelude::Uuid, ActiveModelTrait, ActiveValue, EntityTrait,
};
use sea_orm::{prelude::Uuid, ActiveModelTrait, ActiveValue, EntityTrait};
use serde::{Deserialize, Serialize};
use crate::AppState;
@ -94,6 +92,8 @@ pub async fn delete_user(
Ok(HttpResponse::Ok().finish())
}
// Doesnt work yet since I the function still doesnt process the password
// that means it doesnt rehashes it or store the hash
pub async fn update_user(
state: web::Data<AppState>,
path: web::Path<Uuid>,

View file

@ -1,31 +1,19 @@
use crate::controller::{node, user};
use actix_web::web;
pub fn config(cfg: &mut web::ServiceConfig) {
/*cfg.service(
cfg.service(
web::scope("/api/v1")
.service(
web::resource("/users")
.get(UserController::list_users)
.post(UserController::create_user),
.get(user::get_users)
.post(user::create_user),
)
.route("/users/me", web::get().to(UserController::get_current_user))
.service(
web::resource("/users/{id}")
.delete(UserController::delete_user)
.put(UserController::update_user),
.delete(user::delete_user)
.put(user::update_user),
)
.service(
web::resource("/licenses")
.get(LicenseController::list_groups)
.post(LicenseController::create_license),
)
.service(
web::resource("/licenses/{license_id}")
.delete(LicenseController::delete_license)
.put(LicenseController::update_license),
)
.route("/groups", web::post().to(LicenseController::create_group))
.service(web::resource("/groups/{group_id}").delete(LicenseController::delete_group))
.service(web::scope("/auth").route("/login", web::post().to(AuthController::login))),
);*/
.service(web::resource("/nodes").get(node::get_nodes)),
);
}