feat: création de l'API de gestion des projets et liaison dynamique avec le Dashboard
This commit is contained in:
1 parent
fd53c75dee
commit
2c19670177
3 files changed
+99
-22
No files matched your search
+37
-1
@@ -10,6 +10,11 @@ from .models import User
|
|||||||
from .auth import get_password_hash, generate_totp_secret, get_totp_uri, verify_password, verify_totp, create_access_token, verify_token
|
from .auth import get_password_hash, generate_totp_secret, get_totp_uri, verify_password, verify_totp, create_access_token, verify_token
|
||||||
from .schemas import AdminCreate, LoginRequest
|
from .schemas import AdminCreate, LoginRequest
|
||||||
|
|
||||||
|
# MAJ BDD
|
||||||
|
from typing import List
|
||||||
|
from .schemas import AdminCreate, LoginRequest, ProjectCreate, ProjectResponse
|
||||||
|
from .models import User, Project
|
||||||
|
|
||||||
# Création des tables dans la base de données
|
# Création des tables dans la base de données
|
||||||
Base.metadata.create_all(bind=engine)
|
Base.metadata.create_all(bind=engine)
|
||||||
|
|
||||||
@@ -137,4 +142,35 @@ def dashboard(request: Request):
|
|||||||
if not os.path.exists(frontend_path):
|
if not os.path.exists(frontend_path):
|
||||||
raise HTTPException(status_code=404, detail="Interface du tableau de bord introuvable.")
|
raise HTTPException(status_code=404, detail="Interface du tableau de bord introuvable.")
|
||||||
|
|
||||||
return FileResponse(frontend_path)
|
return FileResponse(frontend_path)
|
||||||
|
|
||||||
|
# --- GESTION DES PROJETS ---
|
||||||
|
|
||||||
|
def get_current_user(request: Request, db: Session = Depends(get_db)):
|
||||||
|
"""Extrait l'utilisateur actuel à partir du cookie de session JWT."""
|
||||||
|
token = request.cookies.get("session_token")
|
||||||
|
if not token:
|
||||||
|
raise HTTPException(status_code=401, detail="Non authentifié")
|
||||||
|
|
||||||
|
payload = verify_token(token)
|
||||||
|
if not payload:
|
||||||
|
raise HTTPException(status_code=401, detail="Session expirée")
|
||||||
|
|
||||||
|
user = db.query(User).filter(User.username == payload.get("sub")).first()
|
||||||
|
if not user:
|
||||||
|
raise HTTPException(status_code=401, detail="Utilisateur introuvable")
|
||||||
|
return user
|
||||||
|
|
||||||
|
@app.get("/api/projects", response_model=List[ProjectResponse])
|
||||||
|
def get_projects(db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
|
||||||
|
"""Récupère tous les projets de l'utilisateur connecté."""
|
||||||
|
return db.query(Project).filter(Project.user_id == current_user.id).order_by(Project.created_at.desc()).all()
|
||||||
|
|
||||||
|
@app.post("/api/projects", response_model=ProjectResponse)
|
||||||
|
def create_project(project: ProjectCreate, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
|
||||||
|
"""Crée un nouveau projet pour l'utilisateur connecté."""
|
||||||
|
new_project = Project(title=project.title, user_id=current_user.id)
|
||||||
|
db.add(new_project)
|
||||||
|
db.commit()
|
||||||
|
db.refresh(new_project)
|
||||||
|
return new_project
|
||||||
+18
-2
@@ -1,12 +1,28 @@
|
|||||||
from pydantic import BaseModel, EmailStr
|
from pydantic import BaseModel, EmailStr
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
class AdminCreate(BaseModel):
|
class AdminCreate(BaseModel):
|
||||||
email: EmailStr
|
email: EmailStr
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
# NOUVEAU : Schéma pour la connexion
|
|
||||||
class LoginRequest(BaseModel):
|
class LoginRequest(BaseModel):
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
totp_code: str
|
totp_code: str
|
||||||
|
|
||||||
|
# --- NOUVEAU : Schémas pour les Projets ---
|
||||||
|
class ProjectBase(BaseModel):
|
||||||
|
title: str
|
||||||
|
|
||||||
|
class ProjectCreate(ProjectBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ProjectResponse(ProjectBase):
|
||||||
|
id: int
|
||||||
|
created_at: datetime
|
||||||
|
is_pinned: bool
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
from_attributes = True
|
||||||
+44
-19
@@ -4,7 +4,6 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>AETHAS38 - Dashboard</title>
|
<title>AETHAS38 - Dashboard</title>
|
||||||
<!-- Tailwind CSS -->
|
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<script>
|
<script>
|
||||||
tailwind.config = {
|
tailwind.config = {
|
||||||
@@ -14,14 +13,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<!-- Vue.js 3 -->
|
|
||||||
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||||||
<!-- Icônes Lucide -->
|
|
||||||
<script src="https://unpkg.com/lucide@latest"></script>
|
<script src="https://unpkg.com/lucide@latest"></script>
|
||||||
<style>
|
<style>
|
||||||
body { background-color: #0f172a; color: #f8fafc; font-family: 'Inter', sans-serif; }
|
body { background-color: #0f172a; color: #f8fafc; font-family: 'Inter', sans-serif; }
|
||||||
.neon-text { background: linear-gradient(to right, #06b6d4, #a855f7); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
.neon-text { background: linear-gradient(to right, #06b6d4, #a855f7); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
|
||||||
/* Style de la scrollbar pour le champ de texte */
|
|
||||||
::-webkit-scrollbar { width: 6px; }
|
::-webkit-scrollbar { width: 6px; }
|
||||||
::-webkit-scrollbar-track { background: transparent; }
|
::-webkit-scrollbar-track { background: transparent; }
|
||||||
::-webkit-scrollbar-thumb { background: #334155; border-radius: 10px; }
|
::-webkit-scrollbar-thumb { background: #334155; border-radius: 10px; }
|
||||||
@@ -31,10 +27,8 @@
|
|||||||
|
|
||||||
<div id="app" class="flex w-full h-full relative bg-aethas-dark">
|
<div id="app" class="flex w-full h-full relative bg-aethas-dark">
|
||||||
|
|
||||||
<!-- Overlay assombrissant pour mobile si la sidebar est ouverte -->
|
|
||||||
<div v-if="isSidebarOpen" @click="toggleSidebar" class="md:hidden fixed inset-0 bg-black/60 z-40 transition-opacity"></div>
|
<div v-if="isSidebarOpen" @click="toggleSidebar" class="md:hidden fixed inset-0 bg-black/60 z-40 transition-opacity"></div>
|
||||||
|
|
||||||
<!-- 1. BARRE LATÉRALE (Rétractable) -->
|
|
||||||
<div :class="['transition-all duration-300 flex-shrink-0 relative z-50', isSidebarOpen ? 'w-72' : 'w-0']">
|
<div :class="['transition-all duration-300 flex-shrink-0 relative z-50', isSidebarOpen ? 'w-72' : 'w-0']">
|
||||||
<aside :class="['absolute top-0 left-0 h-full w-72 bg-aethas-panel border-r border-gray-700 flex flex-col transition-transform duration-300', isSidebarOpen ? 'translate-x-0' : '-translate-x-full']">
|
<aside :class="['absolute top-0 left-0 h-full w-72 bg-aethas-panel border-r border-gray-700 flex flex-col transition-transform duration-300', isSidebarOpen ? 'translate-x-0' : '-translate-x-full']">
|
||||||
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
<div class="p-4 border-b border-gray-700 flex items-center justify-between">
|
||||||
@@ -48,23 +42,21 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
<button class="w-full bg-gray-800 hover:bg-gray-700 text-white border border-gray-600 rounded-lg py-2.5 px-4 flex items-center gap-2 transition-colors">
|
<button @click="createNewProject" :disabled="isLoading" class="w-full bg-gray-800 hover:bg-gray-700 text-white border border-gray-600 rounded-lg py-2.5 px-4 flex items-center justify-center gap-2 transition-colors disabled:opacity-50">
|
||||||
<i data-lucide="plus" class="w-5 h-5 text-aethas-cyan"></i>
|
<i data-lucide="plus" class="w-5 h-5 text-aethas-cyan"></i>
|
||||||
Nouveau Projet IA
|
Nouveau Projet IA
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-1 overflow-y-auto p-4 space-y-6">
|
<div class="flex-1 overflow-y-auto p-4 space-y-6">
|
||||||
<div>
|
|
||||||
<h3 class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-3">Épinglés</h3>
|
|
||||||
<ul class="space-y-1">
|
|
||||||
<li class="p-2 hover:bg-gray-800 rounded cursor-pointer text-sm text-gray-300 truncate">Projet Assistant Code</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<h3 class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-3">Récents</h3>
|
<h3 class="text-xs font-semibold text-gray-400 uppercase tracking-wider mb-3">Récents</h3>
|
||||||
<ul class="space-y-1">
|
<ul class="space-y-1">
|
||||||
<li class="p-2 hover:bg-gray-800 rounded cursor-pointer text-sm text-gray-300 truncate">Traduction Document</li>
|
<li v-if="projects.length === 0" class="text-sm text-gray-500 italic p-2">Aucun projet pour le moment.</li>
|
||||||
|
<li v-for="project in projects" :key="project.id" class="p-2 hover:bg-gray-800 rounded cursor-pointer text-sm text-gray-300 truncate transition-colors flex items-center gap-2">
|
||||||
|
<i data-lucide="message-square" class="w-4 h-4 text-gray-500"></i>
|
||||||
|
{{ project.title }}
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -81,7 +73,6 @@
|
|||||||
</aside>
|
</aside>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ZONE PRINCIPALE -->
|
|
||||||
<main class="flex-1 flex flex-col min-w-0 z-10 transition-all duration-300">
|
<main class="flex-1 flex flex-col min-w-0 z-10 transition-all duration-300">
|
||||||
<header class="flex items-center justify-between p-4 border-b border-gray-700 bg-aethas-panel h-[73px]">
|
<header class="flex items-center justify-between p-4 border-b border-gray-700 bg-aethas-panel h-[73px]">
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
@@ -131,10 +122,10 @@
|
|||||||
const isSidebarOpen = ref(true);
|
const isSidebarOpen = ref(true);
|
||||||
const prompt = ref("");
|
const prompt = ref("");
|
||||||
const promptTextarea = ref(null);
|
const promptTextarea = ref(null);
|
||||||
|
const projects = ref([]);
|
||||||
|
const isLoading = ref(false);
|
||||||
|
|
||||||
const toggleSidebar = () => {
|
const toggleSidebar = () => { isSidebarOpen.value = !isSidebarOpen.value; };
|
||||||
isSidebarOpen.value = !isSidebarOpen.value;
|
|
||||||
};
|
|
||||||
|
|
||||||
const autoResize = () => {
|
const autoResize = () => {
|
||||||
const el = promptTextarea.value;
|
const el = promptTextarea.value;
|
||||||
@@ -143,11 +134,45 @@
|
|||||||
el.style.height = el.scrollHeight + 'px';
|
el.style.height = el.scrollHeight + 'px';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchProjects = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/projects');
|
||||||
|
if (response.ok) {
|
||||||
|
projects.value = await response.json();
|
||||||
|
nextTick(() => lucide.createIcons());
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors de la récupération des projets", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const createNewProject = async () => {
|
||||||
|
isLoading.value = true;
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/projects', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ title: "Nouvelle discussion" })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const newProject = await response.json();
|
||||||
|
projects.value.unshift(newProject); // Ajoute le nouveau projet en haut de la liste
|
||||||
|
nextTick(() => lucide.createIcons());
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors de la création du projet", error);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
lucide.createIcons();
|
lucide.createIcons();
|
||||||
|
fetchProjects();
|
||||||
});
|
});
|
||||||
|
|
||||||
return { username, isSidebarOpen, toggleSidebar, prompt, autoResize, promptTextarea };
|
return { username, isSidebarOpen, toggleSidebar, prompt, autoResize, promptTextarea, projects, createNewProject, isLoading };
|
||||||
}
|
}
|
||||||
}).mount('#app');
|
}).mount('#app');
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user