Compare commits

..

12 commits

Author SHA1 Message Date
Schnitzel
8fb3736188 add loginView 2025-04-09 10:34:33 +02:00
Schnitzel
726c4844fc add LoginView 2025-04-09 10:29:52 +02:00
9daaa94660 Merge pull request 'push-cargo-lock' (#61) from push-cargo-lock into main
Reviewed-on: #61
2025-04-09 10:00:00 +02:00
9a693821ce push cargo-lock
Some checks failed
ci/woodpecker/pr/cargo_check Pipeline was successful
ci/woodpecker/pr/cargo_clippy Pipeline was successful
ci/woodpecker/pr/cargo_test Pipeline was successful
ci/woodpecker/pr/check_fmt Pipeline failed
2025-04-09 09:59:45 +02:00
f81590ff24 feat: automatically run migration on startup 2025-04-09 09:59:45 +02:00
9bad76dcd6 Merge pull request 'chaged the header and styling' (#60) from frontend/changing-more-things-on-header into main
Reviewed-on: #60
Reviewed-by: DulliGulli <jan.hoegerle@gmail.com>
2025-04-09 09:45:15 +02:00
6b4dd96d83 chaged the header and styling
Some checks failed
ci/woodpecker/pr/cargo_check Pipeline was successful
ci/woodpecker/pr/cargo_clippy Pipeline was successful
ci/woodpecker/pr/cargo_test Pipeline was successful
ci/woodpecker/pr/check_fmt Pipeline failed
2025-04-09 09:38:53 +02:00
ca04737c49 Merge pull request 'build rudimentary header, no sticky header yet and tailwind missing' (#58) from frontend/building-header-component into main
Reviewed-on: #58
Reviewed-by: Fargan von Pfargan Pfadfinder Tampon Tamplate <123@123.de>
2025-04-08 12:33:04 +02:00
e6fea1aab3 build rudimentary header, no sticky header yet and tailwind missing
Some checks failed
ci/woodpecker/pr/cargo_check Pipeline was successful
ci/woodpecker/pr/cargo_clippy Pipeline was successful
ci/woodpecker/pr/cargo_test Pipeline failed
ci/woodpecker/pr/check_fmt Pipeline failed
2025-04-08 11:30:34 +02:00
a2fefb459d Implement user retrieval and deletion endpoint (#56)
Reviewed-on: #56
Reviewed-by: Fargan von Pfargan Pfadfinder Tampon Tamplate <123@123.de>
Co-authored-by: Mika Bomm <mika.bomm@outlook.com>
Co-committed-by: Mika Bomm <mika.bomm@outlook.com>
2025-04-07 14:23:54 +02:00
dddad6f0cc Merge pull request 'Refactor database URL tests to use temp_env with multiple variables and improve clarity' (#55) from api-backend into main
Reviewed-on: #55
2025-04-07 13:08:05 +02:00
cee89e31aa Refactor database URL tests to use temp_env with multiple variables and improve clarity
Some checks failed
ci/woodpecker/pr/check_fmt Pipeline failed
ci/woodpecker/pr/cargo_clippy Pipeline was successful
ci/woodpecker/pr/cargo_check Pipeline was successful
ci/woodpecker/pr/cargo_test Pipeline was successful
2025-04-07 13:06:34 +02:00
13 changed files with 4525 additions and 136 deletions

2
.gitignore vendored
View file

@ -6,7 +6,7 @@ target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk

4314
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

15
bruno/user/Get user.bru Normal file
View file

@ -0,0 +1,15 @@
meta {
name: Get user
type: http
seq: 2
}
get {
url: {{api_base}}/user/:id
body: none
auth: inherit
}
params:path {
id: 293ef329-91b2-4912-ad5d-0277490c7b55
}

11
bruno/user/Get users.bru Normal file
View file

@ -0,0 +1,11 @@
meta {
name: Get users
type: http
seq: 1
}
get {
url: {{api_base}}/user
body: none
auth: inherit
}

View file

@ -1,5 +1,5 @@
use crate::{entity, error::ApiError, Database};
use actix_web::{delete, get, post, put, web, Responder};
use crate::{Database, entity, error::ApiError};
use actix_web::{Responder, delete, get, post, put, web};
use serde::Deserialize;
use validator::Validate;
@ -20,13 +20,21 @@ struct CreateUser {
}
#[get("")]
async fn get_users() -> impl Responder {
""
async fn get_users(
db: web::Data<Database>,
) -> Result<web::Json<Vec<entity::user::Model>>, ApiError> {
let users = db.get_users().await?;
Ok(web::Json(users))
}
#[get("/{id}")]
async fn get_user() -> impl Responder {
""
async fn get_user(
db: web::Data<Database>,
id: web::Path<uuid::Uuid>,
) -> Result<web::Json<entity::user::Model>, ApiError> {
let user = db.get_user(id.into_inner()).await?;
Ok(web::Json(user.unwrap()))
}
#[post("")]
@ -48,6 +56,11 @@ async fn update_user() -> impl Responder {
}
#[delete("/{id}")]
async fn delete_user() -> impl Responder {
""
async fn delete_user(
db: web::Data<Database>,
id: web::Path<uuid::Uuid>,
) -> Result<web::Json<String>, ApiError> {
let id = id.into_inner();
db.delete_user(id).await?;
Ok(web::Json(format!("User {} deleted", id)))
}

View file

@ -16,4 +16,8 @@ impl Database {
conn: sea_orm::Database::connect(options).await?,
})
}
pub fn connection(&self) -> &DatabaseConnection {
&self.conn
}
}

View file

@ -1,18 +1,37 @@
use crate::error::ApiError;
use argon2::{
password_hash::{rand_core::OsRng, PasswordHasher, SaltString},
Argon2, PasswordHash, PasswordVerifier,
password_hash::{PasswordHasher, SaltString, rand_core::OsRng},
};
use sea_orm::{
ActiveModelTrait,
ActiveValue::{NotSet, Set},
ColumnTrait, DbErr, EntityTrait, ModelTrait, QueryFilter, TransactionTrait,
ColumnTrait, DbErr, DeleteResult, EntityTrait, ModelTrait, QueryFilter, TransactionTrait,
};
use uuid::Uuid;
use crate::{entity, Database};
use crate::{Database, entity};
impl Database {
pub async fn get_users(&self) -> Result<Vec<entity::user::Model>, ApiError> {
let users = entity::user::Entity::find().all(&self.conn).await?;
Ok(users)
}
pub async fn get_user(&self, id: Uuid) -> Result<Option<entity::user::Model>, ApiError> {
let user = entity::user::Entity::find()
.filter(entity::user::Column::Id.eq(id))
.one(&self.conn)
.await?;
if user.is_none() {
return Err(ApiError::NotFound);
}
Ok(user)
}
pub async fn create_user(
&self,
name: String,
@ -82,6 +101,18 @@ impl Database {
Ok(user.id)
}
pub async fn delete_user(&self, id: Uuid) -> Result<DeleteResult, ApiError> {
let user = entity::user::Entity::delete_by_id(id)
.exec(&self.conn)
.await?;
if user.rows_affected == 0 {
return Err(ApiError::NotFound);
}
Ok(user)
}
pub async fn verify_ldap_user() {}
pub async fn change_user_password() {}

View file

@ -9,6 +9,9 @@ mod error;
pub use db::Database;
pub use db::entity;
use log::info;
use migration::Migrator;
use migration::MigratorTrait;
#[derive(Clone)]
struct AppConfig {
@ -24,6 +27,10 @@ async fn main() -> std::io::Result<()> {
let database = Database::new(database_url.into()).await.unwrap();
info!("Running migrations");
Migrator::up(database.connection(), None).await.unwrap();
info!("Migrations completed");
let redis_conn = connect_to_redis_database().await;
let app_config = AppConfig { ldap_auth: false };
@ -92,31 +99,31 @@ fn build_database_url() -> String {
#[cfg(test)]
mod tests {
use super::*;
use temp_env::with_vars;
use temp_env::{with_vars, with_vars_unset};
#[test]
fn build_database_url_with_defaults() {
temp_env::with_vars([("DB_HOST", None::<&str>)], || {
// Was sieht die direkte Umgebung? (Sollte Err sein)
println!(
"Inside temp_env (unset): std::env::var(\"DB_HOST\") is {:?}",
std::env::var("DB_HOST")
temp_env::with_vars(
[
("DB_USER", None::<&str>),
("DB_NAME", None::<&str>),
("DB_PASSWORD", None::<&str>),
("DB_HOST", Some("localhost")),
("DB_PORT", None::<&str>),
],
|| {
let expected_url = "postgresql://pgg:pgg@localhost:5432/pgg";
let actual_url = build_database_url();
assert_eq!(
actual_url, expected_url,
"Database URL should use default values for unset env vars."
);
// Was sieht dotenvy? (Ist wahrscheinlich Ok(...) wegen .env)
println!(
"Inside temp_env (unset): dotenvy::var(\"DB_HOST\") is {:?}",
dotenvy::var("DB_HOST")
},
);
// Jetzt der Aufruf, der panicen sollte
build_database_url();
});
}
#[test]
fn build_database_url_with_all_vars() {
dotenvy::dotenv().ok();
with_vars(
[
("DB_USER", Some("testuser")),
@ -139,7 +146,8 @@ mod tests {
#[test]
#[should_panic(expected = "DB_HOST must be set in .env")]
fn build_database_url_missing_host_panics() {
dotenvy::dotenv().ok();
with_vars_unset(["DB_HOST"], || {
build_database_url();
});
}
}

View file

@ -1,17 +1,23 @@
<script setup lang="ts">
import MenuBar from './components/MenuBar.vue';
import { RouterLink, RouterView } from 'vue-router';
import HeaderNav from './components/HeaderNav.vue';
import { BoltIcon } from 'lucide-vue-next';
const isTeacher = true;
const isLoggedIn = true;
</script>
<template>
<header>
<img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />
<header class="sticky top-0 z-50 bg-black w-full">
<HeaderNav :isLoggedIn="isLoggedIn" :isTeacher="isTeacher">
<template #left-icon>
<BoltIcon class="icon" />
</template>
</HeaderNav>
</header>
<MenuBar/>
<div id="app" class="flex flex-col min-h-screen overflow-x-hidden">
<main class="flex-grow p-4">
<RouterView />
</main>
</div>
</template>
<style scoped>
</style>

View file

@ -20,16 +20,3 @@ a,
background-color: hsla(160, 100%, 37%, 0.2);
}
}
@media (min-width: 1024px) {
body {
display: flex;
place-items: start;
}
#app {
display: grid;
grid-template-columns: 1fr 1fr;
padding: 0 2rem;
}
}

View file

@ -0,0 +1,78 @@
<template>
<nav class="header-container">
<div class="left-icon">
<slot name="left-icon"></slot>
</div>
<div class="nav-items">
<button
v-if="!isLoggedIn"
class="nav-button"
>
<component :is="LogInIcon" class="icon" />
Login
</button>
<template v-if="isLoggedIn">
<button class="nav-button">
<component :is="LogOutIcon" class="icon" />
Logout
</button>
<button
v-if="isTeacher"
class="nav-button"
>
<component :is="BoltIcon" class="icon" />
Lehrerverwaltung
</button>
</template>
</div>
</nav>
</template>
<script setup lang="ts">
import { LogInIcon, LogOutIcon, BoltIcon } from 'lucide-vue-next';
defineProps<{
isLoggedIn: boolean;
isTeacher: boolean;
}>();
</script>
<style scoped>
.header-container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
width: 100%;
box-sizing: border-box;
}
.left-icon {
display: flex;
align-items: center;
}
.nav-items {
display: flex;
gap: 1rem;
align-items: center;
margin-left: auto;
}
.nav-button {
display: flex;
align-items: center;
gap: 0.5rem;
background: none;
border: none;
cursor: pointer;
font-weight: bold;
color: white;
}
.icon {
width: 1rem;
height: 1rem;
}
</style>

View file

@ -1,80 +0,0 @@
<template>
<div class="card">
<Menubar :model="items">
<template #item="{ item, props, hasSubmenu }">
<router-link v-if="item.route" v-slot="{ href, navigate }" :to="item.route" custom>
<a v-ripple :href="href" v-bind="props.action" @click="navigate">
<span :class="item.icon" />
<span>{{ item.label }}</span>
</a>
</router-link>
<a v-else v-ripple :href="item.url" :target="item.target" v-bind="props.action">
<span :class="item.icon" />
<span> n/A {{ item.label }}</span>
<span v-if="hasSubmenu" class="pi pi-fw pi-angle-down" />
</a>
</template>
</Menubar>
</div>
</template>
<script setup>
import Menubar from 'primevue/menubar';
import { ref } from "vue";
import { useRouter } from 'vue-router';
const items = ref([
{
label: 'Home',
icon: 'pi pi-home',
route: '/'
},
{
label: 'Student',
icon: 'pi pi-graduation-cap',
route: '/Student'
},
{
label: 'Login',
icon: 'pi pi-graduation-cap',
route: '/Login'
},
{
label: 'Projects',
icon: 'pi pi-search',
items: [
{
label: 'Components',
icon: 'pi pi-bolt'
},
{
label: 'Blocks',
icon: 'pi pi-server'
},
{
label: 'UI Kit',
icon: 'pi pi-pencil'
},
{
label: 'Templates',
icon: 'pi pi-palette',
items: [
{
label: 'Apollo',
icon: 'pi pi-palette'
},
{
label: 'Ultima',
icon: 'pi pi-palette'
}
]
}
]
},
{
label: 'Contact',
icon: 'pi pi-envelope'
}
]);
</script>

View file

@ -5,6 +5,7 @@ import { createApp } from 'vue'
import { createPinia } from 'pinia'
import PrimeVue from 'primevue/config'
import Aura from '@primeuix/themes/aura'
import Ripple from 'primevue/ripple'
import App from './App.vue'
import router from './router'
@ -18,5 +19,6 @@ app.use(PrimeVue, {
})
app.use(createPinia())
app.use(router)
app.directive('ripple', Ripple)
app.mount('#app')