Compare commits
No commits in common. "3c11f3018a9292b12a4da0a719d4dea99188ce02" and "b8255a3d969bfac81a61b450230bb68b10f314e6" have entirely different histories.
3c11f3018a
...
b8255a3d96
9 changed files with 106 additions and 189 deletions
|
@ -1,15 +0,0 @@
|
||||||
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
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
meta {
|
|
||||||
name: Get users
|
|
||||||
type: http
|
|
||||||
seq: 1
|
|
||||||
}
|
|
||||||
|
|
||||||
get {
|
|
||||||
url: {{api_base}}/user
|
|
||||||
body: none
|
|
||||||
auth: inherit
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{Database, entity, error::ApiError};
|
use crate::{entity, error::ApiError, Database};
|
||||||
use actix_web::{Responder, delete, get, post, put, web};
|
use actix_web::{delete, get, post, put, web, Responder};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
|
@ -20,21 +20,13 @@ struct CreateUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("")]
|
#[get("")]
|
||||||
async fn get_users(
|
async fn get_users() -> impl Responder {
|
||||||
db: web::Data<Database>,
|
""
|
||||||
) -> Result<web::Json<Vec<entity::user::Model>>, ApiError> {
|
|
||||||
let users = db.get_users().await?;
|
|
||||||
Ok(web::Json(users))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/{id}")]
|
#[get("/{id}")]
|
||||||
async fn get_user(
|
async fn get_user() -> impl Responder {
|
||||||
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("")]
|
#[post("")]
|
||||||
|
@ -56,11 +48,6 @@ async fn update_user() -> impl Responder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/{id}")]
|
#[delete("/{id}")]
|
||||||
async fn delete_user(
|
async fn delete_user() -> impl Responder {
|
||||||
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)))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +1,18 @@
|
||||||
use crate::error::ApiError;
|
use crate::error::ApiError;
|
||||||
use argon2::{
|
use argon2::{
|
||||||
|
password_hash::{rand_core::OsRng, PasswordHasher, SaltString},
|
||||||
Argon2, PasswordHash, PasswordVerifier,
|
Argon2, PasswordHash, PasswordVerifier,
|
||||||
password_hash::{PasswordHasher, SaltString, rand_core::OsRng},
|
|
||||||
};
|
};
|
||||||
use sea_orm::{
|
use sea_orm::{
|
||||||
ActiveModelTrait,
|
ActiveModelTrait,
|
||||||
ActiveValue::{NotSet, Set},
|
ActiveValue::{NotSet, Set},
|
||||||
ColumnTrait, DbErr, DeleteResult, EntityTrait, ModelTrait, QueryFilter, TransactionTrait,
|
ColumnTrait, DbErr, EntityTrait, ModelTrait, QueryFilter, TransactionTrait,
|
||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{Database, entity};
|
use crate::{entity, Database};
|
||||||
|
|
||||||
impl Database {
|
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(
|
pub async fn create_user(
|
||||||
&self,
|
&self,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -101,18 +82,6 @@ impl Database {
|
||||||
Ok(user.id)
|
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 verify_ldap_user() {}
|
||||||
|
|
||||||
pub async fn change_user_password() {}
|
pub async fn change_user_password() {}
|
||||||
|
|
|
@ -92,31 +92,31 @@ fn build_database_url() -> String {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use temp_env::{with_vars, with_vars_unset};
|
use temp_env::with_vars;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_database_url_with_defaults() {
|
fn build_database_url_with_defaults() {
|
||||||
temp_env::with_vars(
|
temp_env::with_vars([("DB_HOST", None::<&str>)], || {
|
||||||
[
|
// Was sieht die direkte Umgebung? (Sollte Err sein)
|
||||||
("DB_USER", None::<&str>),
|
println!(
|
||||||
("DB_NAME", None::<&str>),
|
"Inside temp_env (unset): std::env::var(\"DB_HOST\") is {:?}",
|
||||||
("DB_PASSWORD", None::<&str>),
|
std::env::var("DB_HOST")
|
||||||
("DB_HOST", Some("localhost")),
|
);
|
||||||
("DB_PORT", None::<&str>),
|
|
||||||
],
|
// Was sieht dotenvy? (Ist wahrscheinlich Ok(...) wegen .env)
|
||||||
|| {
|
println!(
|
||||||
let expected_url = "postgresql://pgg:pgg@localhost:5432/pgg";
|
"Inside temp_env (unset): dotenvy::var(\"DB_HOST\") is {:?}",
|
||||||
let actual_url = build_database_url();
|
dotenvy::var("DB_HOST")
|
||||||
assert_eq!(
|
);
|
||||||
actual_url, expected_url,
|
|
||||||
"Database URL should use default values for unset env vars."
|
// Jetzt der Aufruf, der panicen sollte
|
||||||
);
|
build_database_url();
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_database_url_with_all_vars() {
|
fn build_database_url_with_all_vars() {
|
||||||
|
dotenvy::dotenv().ok();
|
||||||
with_vars(
|
with_vars(
|
||||||
[
|
[
|
||||||
("DB_USER", Some("testuser")),
|
("DB_USER", Some("testuser")),
|
||||||
|
@ -139,8 +139,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "DB_HOST must be set in .env")]
|
#[should_panic(expected = "DB_HOST must be set in .env")]
|
||||||
fn build_database_url_missing_host_panics() {
|
fn build_database_url_missing_host_panics() {
|
||||||
with_vars_unset(["DB_HOST"], || {
|
dotenvy::dotenv().ok();
|
||||||
build_database_url();
|
build_database_url();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import HeaderNav from './components/HeaderNav.vue'
|
|
||||||
import SideBar from './components/SideBar.vue'
|
import SideBar from './components/SideBar.vue'
|
||||||
import { RouterLink, RouterView } from 'vue-router'
|
import { RouterLink, RouterView } from 'vue-router'
|
||||||
|
|
||||||
const isTeacher = false
|
|
||||||
const isLoggedIn = true
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="sticky top-0">
|
|
||||||
<header>
|
|
||||||
<HeaderNav :isLoggedIn="isLoggedIn" :isTeacher="isTeacher">
|
|
||||||
<template #left-icon>
|
|
||||||
<BoltIcon class="icon" />
|
|
||||||
<!--Hier dann ein richtiges Logo rein-->
|
|
||||||
</template>
|
|
||||||
</HeaderNav>
|
|
||||||
</header>
|
|
||||||
</div>
|
|
||||||
<SideBar />
|
<SideBar />
|
||||||
<div>
|
<div>
|
||||||
<RouterView />
|
<RouterView />
|
||||||
|
|
|
@ -1,71 +0,0 @@
|
||||||
<template>
|
|
||||||
<nav class="header-container">
|
|
||||||
<div class="left-icon">
|
|
||||||
<!-- Platzhalter für ein 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-else>
|
|
||||||
<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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-items {
|
|
||||||
display: flex;
|
|
||||||
gap: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav-button {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 0.5rem;
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
cursor: pointer;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.icon {
|
|
||||||
width: 1rem;
|
|
||||||
height: 1rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
75
frontend/src/components/MenuBar.vue
Normal file
75
frontend/src/components/MenuBar.vue
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<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: '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>
|
|
@ -5,7 +5,6 @@ import { createApp } from 'vue'
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import PrimeVue from 'primevue/config'
|
import PrimeVue from 'primevue/config'
|
||||||
import Aura from '@primeuix/themes/aura'
|
import Aura from '@primeuix/themes/aura'
|
||||||
import Ripple from 'primevue/ripple'
|
|
||||||
|
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
|
@ -19,6 +18,5 @@ app.use(PrimeVue, {
|
||||||
})
|
})
|
||||||
app.use(createPinia())
|
app.use(createPinia())
|
||||||
app.use(router)
|
app.use(router)
|
||||||
app.directive('ripple', Ripple)
|
|
||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
|
Loading…
Add table
Reference in a new issue