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

View file

@ -1 +1,3 @@
pub mod user; 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, Argon2,
}; };
use entity::user; use entity::user;
use sea_orm::{ use sea_orm::{prelude::Uuid, ActiveModelTrait, ActiveValue, EntityTrait};
entity::prelude::DateTime, prelude::Uuid, ActiveModelTrait, ActiveValue, EntityTrait,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::AppState; use crate::AppState;
@ -94,6 +92,8 @@ pub async fn delete_user(
Ok(HttpResponse::Ok().finish()) 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( pub async fn update_user(
state: web::Data<AppState>, state: web::Data<AppState>,
path: web::Path<Uuid>, path: web::Path<Uuid>,

View file

@ -1,31 +1,19 @@
use crate::controller::{node, user};
use actix_web::web; use actix_web::web;
pub fn config(cfg: &mut web::ServiceConfig) { pub fn config(cfg: &mut web::ServiceConfig) {
/*cfg.service( cfg.service(
web::scope("/api/v1") web::scope("/api/v1")
.service( .service(
web::resource("/users") web::resource("/users")
.get(UserController::list_users) .get(user::get_users)
.post(UserController::create_user), .post(user::create_user),
) )
.route("/users/me", web::get().to(UserController::get_current_user))
.service( .service(
web::resource("/users/{id}") web::resource("/users/{id}")
.delete(UserController::delete_user) .delete(user::delete_user)
.put(UserController::update_user), .put(user::update_user),
) )
.service( .service(web::resource("/nodes").get(node::get_nodes)),
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))),
);*/
} }