feat(v3): restructure project + add complete frontend
- Restructure: move backend from new_project/ to backend/ - Add full React/TypeScript frontend (37 pages, 17 services, 16 type defs, 11 query hooks) - Add docs/ with SRS specs, user stories, and workflow documentation - Update .gitignore for new directory layout Workflows implemented: WF1 User Signup, WF2 Placement Test, WF3 Exam Configuration, WF4 General English Exam, WF5 Course Generation, WF6 Entity Student Onboarding, AI Course Generation, Adaptive Learning Engine UI, White-Label Branding, Score Release Made-with: Cursor
This commit is contained in:
79
frontend/src/hooks/queries/useLibrary.ts
Normal file
79
frontend/src/hooks/queries/useLibrary.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { queryKeys } from "./keys";
|
||||
import { libraryService } from "@/services/library.service";
|
||||
import type { PaginationParams } from "@/types";
|
||||
import type { MediaCreateRequest, MediaMovement } from "@/types/library";
|
||||
|
||||
type MovementWrite = Partial<
|
||||
Omit<MediaMovement, "id" | "media_name" | "student_name" | "faculty_name">
|
||||
>;
|
||||
|
||||
export function useLibraryMedia(params?: PaginationParams) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.libraryMedia.list(params),
|
||||
queryFn: () => libraryService.listMedia(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateMedia() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: MediaCreateRequest) => libraryService.createMedia(data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.libraryMedia.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useLibraryMovements(params?: PaginationParams) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.libraryMovements.list(params),
|
||||
queryFn: () => libraryService.listMovements(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateMovement() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: MovementWrite) => libraryService.createMovement(data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.libraryMovements.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateMovement() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: MovementWrite }) =>
|
||||
libraryService.updateMovement(id, data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.libraryMovements.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteMedia() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => libraryService.deleteMedia(id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.libraryMedia.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useReturnMovement() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => libraryService.returnMovement(id),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.libraryMovements.all }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useLibraryCards(params?: PaginationParams) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.libraryCards.list(params),
|
||||
queryFn: () => libraryService.listCards(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateCard() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: { student_id: number }) => libraryService.createCard(data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: queryKeys.libraryCards.all }),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user