From cd7462ffb1b4ffaa89089eca3969e8743854717a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 15 May 2024 18:27:48 +0200 Subject: [PATCH] Refactor API routes --- geneit_app/src/api/FamilyApi.ts | 2 +- .../src/api/{ => genealogy}/CoupleApi.ts | 18 ++++----- geneit_app/src/api/{ => genealogy}/DataApi.ts | 6 +-- .../src/api/{ => genealogy}/MemberApi.ts | 16 ++++---- .../src/routes/family/FamilyCoupleRoute.tsx | 4 +- .../routes/family/FamilyCouplesListRoute.tsx | 4 +- .../src/routes/family/FamilyMemberRoute.tsx | 4 +- .../routes/family/FamilyMembersListRoute.tsx | 7 +++- .../src/routes/family/FamilySettingsRoute.tsx | 2 +- geneit_app/src/utils/family_tree.ts | 4 +- geneit_app/src/widgets/BaseFamilyRoute.tsx | 4 +- geneit_app/src/widgets/BasicFamilyTree.tsx | 4 +- geneit_app/src/widgets/CouplePhoto.tsx | 2 +- geneit_app/src/widgets/MemberItem.tsx | 2 +- geneit_app/src/widgets/MemberPhoto.tsx | 2 +- geneit_app/src/widgets/forms/DateInput.tsx | 2 +- geneit_app/src/widgets/forms/MemberInput.tsx | 2 +- geneit_app/src/widgets/forms/SexSelection.tsx | 2 +- .../simple_family_tree/SimpleFamilyTree.tsx | 4 +- geneit_backend/src/main.rs | 38 +++++++++---------- 20 files changed, 67 insertions(+), 62 deletions(-) rename geneit_app/src/api/{ => genealogy}/CoupleApi.ts (90%) rename geneit_app/src/api/{ => genealogy}/DataApi.ts (78%) rename geneit_app/src/api/{ => genealogy}/MemberApi.ts (94%) diff --git a/geneit_app/src/api/FamilyApi.ts b/geneit_app/src/api/FamilyApi.ts index 1518cac..94128c0 100644 --- a/geneit_app/src/api/FamilyApi.ts +++ b/geneit_app/src/api/FamilyApi.ts @@ -1,6 +1,6 @@ import { APIClient } from "./ApiClient"; import { Couple } from "./CoupleApi"; -import { Member } from "./MemberApi"; +import { Member } from "./genealogy/MemberApi"; interface FamilyAPI { user_id: number; diff --git a/geneit_app/src/api/CoupleApi.ts b/geneit_app/src/api/genealogy/CoupleApi.ts similarity index 90% rename from geneit_app/src/api/CoupleApi.ts rename to geneit_app/src/api/genealogy/CoupleApi.ts index 41234bd..bb12ae3 100644 --- a/geneit_app/src/api/CoupleApi.ts +++ b/geneit_app/src/api/genealogy/CoupleApi.ts @@ -1,6 +1,6 @@ -import { APIClient } from "./ApiClient"; +import { APIClient } from "../ApiClient"; import { DateValue, Member } from "./MemberApi"; -import { ServerApi } from "./ServerApi"; +import { ServerApi } from "../ServerApi"; interface CoupleApiInterface { id: number; @@ -161,7 +161,7 @@ export class CoupleApi { */ static async Create(m: Couple): Promise { const res = await APIClient.exec({ - uri: `/family/${m.family_id}/couple/create`, + uri: `/family/${m.family_id}/genealogy/couple/create`, method: "POST", jsonData: m, }); @@ -177,7 +177,7 @@ export class CoupleApi { couple_id: number ): Promise { const res = await APIClient.exec({ - uri: `/family/${family_id}/couple/${couple_id}`, + uri: `/family/${family_id}/genealogy/couple/${couple_id}`, method: "GET", }); @@ -189,7 +189,7 @@ export class CoupleApi { */ static async GetEntireList(family_id: number): Promise { const res = await APIClient.exec({ - uri: `/family/${family_id}/couples`, + uri: `/family/${family_id}/genealogy/couples`, method: "GET", }); @@ -201,7 +201,7 @@ export class CoupleApi { */ static async Update(m: Couple): Promise { await APIClient.exec({ - uri: `/family/${m.family_id}/couple/${m.id}`, + uri: `/family/${m.family_id}/genealogy/couple/${m.id}`, method: "PUT", jsonData: m, }); @@ -214,7 +214,7 @@ export class CoupleApi { const fd = new FormData(); fd.append("photo", b); await APIClient.exec({ - uri: `/family/${m.family_id}/couple/${m.id}/photo`, + uri: `/family/${m.family_id}/genealogy/couple/${m.id}/photo`, method: "PUT", formData: fd, }); @@ -225,7 +225,7 @@ export class CoupleApi { */ static async RemoveCouplePhoto(m: Couple): Promise { await APIClient.exec({ - uri: `/family/${m.family_id}/couple/${m.id}/photo`, + uri: `/family/${m.family_id}/genealogy/couple/${m.id}/photo`, method: "DELETE", }); } @@ -235,7 +235,7 @@ export class CoupleApi { */ static async Delete(m: Couple): Promise { await APIClient.exec({ - uri: `/family/${m.family_id}/couple/${m.id}`, + uri: `/family/${m.family_id}/genealogy/couple/${m.id}`, method: "DELETE", }); } diff --git a/geneit_app/src/api/DataApi.ts b/geneit_app/src/api/genealogy/DataApi.ts similarity index 78% rename from geneit_app/src/api/DataApi.ts rename to geneit_app/src/api/genealogy/DataApi.ts index 2b9a735..2c5281d 100644 --- a/geneit_app/src/api/DataApi.ts +++ b/geneit_app/src/api/genealogy/DataApi.ts @@ -1,4 +1,4 @@ -import { APIClient } from "./ApiClient"; +import { APIClient } from "../ApiClient"; /** * Data management api client @@ -9,7 +9,7 @@ export class DataApi { */ static async ExportData(family_id: number): Promise { const res = await APIClient.exec({ - uri: `/family/${family_id}/data/export`, + uri: `/family/${family_id}/genealogy/data/export`, method: "GET", }); return res.data; @@ -22,7 +22,7 @@ export class DataApi { const fd = new FormData(); fd.append("archive", archive); const res = await APIClient.exec({ - uri: `/family/${family_id}/data/import`, + uri: `/family/${family_id}/genealogy/data/import`, method: "PUT", formData: fd, }); diff --git a/geneit_app/src/api/MemberApi.ts b/geneit_app/src/api/genealogy/MemberApi.ts similarity index 94% rename from geneit_app/src/api/MemberApi.ts rename to geneit_app/src/api/genealogy/MemberApi.ts index 66b0d73..db989ab 100644 --- a/geneit_app/src/api/MemberApi.ts +++ b/geneit_app/src/api/genealogy/MemberApi.ts @@ -1,4 +1,4 @@ -import { APIClient } from "./ApiClient"; +import { APIClient } from "../ApiClient"; import { Couple } from "./CoupleApi"; export type Sex = "M" | "F"; @@ -278,7 +278,7 @@ export class MemberApi { */ static async Create(m: Member): Promise { const res = await APIClient.exec({ - uri: `/family/${m.family_id}/member/create`, + uri: `/family/${m.family_id}/genealogy/member/create`, method: "POST", jsonData: m, }); @@ -294,7 +294,7 @@ export class MemberApi { member_id: number ): Promise { const res = await APIClient.exec({ - uri: `/family/${family_id}/member/${member_id}`, + uri: `/family/${family_id}/genealogy/member/${member_id}`, method: "GET", }); @@ -306,7 +306,7 @@ export class MemberApi { */ static async GetEntireList(family_id: number): Promise { const res = await APIClient.exec({ - uri: `/family/${family_id}/members`, + uri: `/family/${family_id}/genealogy/members`, method: "GET", }); @@ -318,7 +318,7 @@ export class MemberApi { */ static async Update(m: Member): Promise { await APIClient.exec({ - uri: `/family/${m.family_id}/member/${m.id}`, + uri: `/family/${m.family_id}/genealogy/member/${m.id}`, method: "PUT", jsonData: m, }); @@ -331,7 +331,7 @@ export class MemberApi { const fd = new FormData(); fd.append("photo", b); await APIClient.exec({ - uri: `/family/${m.family_id}/member/${m.id}/photo`, + uri: `/family/${m.family_id}/genealogy/member/${m.id}/photo`, method: "PUT", formData: fd, }); @@ -342,7 +342,7 @@ export class MemberApi { */ static async RemoveMemberPhoto(m: Member): Promise { await APIClient.exec({ - uri: `/family/${m.family_id}/member/${m.id}/photo`, + uri: `/family/${m.family_id}/genealogy/member/${m.id}/photo`, method: "DELETE", }); } @@ -352,7 +352,7 @@ export class MemberApi { */ static async Delete(m: Member): Promise { await APIClient.exec({ - uri: `/family/${m.family_id}/member/${m.id}`, + uri: `/family/${m.family_id}/genealogy/member/${m.id}`, method: "DELETE", }); } diff --git a/geneit_app/src/routes/family/FamilyCoupleRoute.tsx b/geneit_app/src/routes/family/FamilyCoupleRoute.tsx index 172e870..3de9873 100644 --- a/geneit_app/src/routes/family/FamilyCoupleRoute.tsx +++ b/geneit_app/src/routes/family/FamilyCoupleRoute.tsx @@ -6,8 +6,8 @@ import SaveIcon from "@mui/icons-material/Save"; import { Button, Grid, Stack } from "@mui/material"; import React from "react"; import { useNavigate, useParams } from "react-router-dom"; -import { Couple, CoupleApi } from "../../api/CoupleApi"; -import { Member } from "../../api/MemberApi"; +import { Couple, CoupleApi } from "../../api/genealogy/CoupleApi"; +import { Member } from "../../api/genealogy/MemberApi"; import { ServerApi } from "../../api/ServerApi"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../../hooks/context_providers/ConfirmDialogProvider"; diff --git a/geneit_app/src/routes/family/FamilyCouplesListRoute.tsx b/geneit_app/src/routes/family/FamilyCouplesListRoute.tsx index c34c1f1..41d1a53 100644 --- a/geneit_app/src/routes/family/FamilyCouplesListRoute.tsx +++ b/geneit_app/src/routes/family/FamilyCouplesListRoute.tsx @@ -6,8 +6,8 @@ import { Button, TextField, Tooltip } from "@mui/material"; import { DataGrid, GridActionsCellItem, GridColDef } from "@mui/x-data-grid"; import React from "react"; import { useNavigate } from "react-router-dom"; -import { Couple, CoupleApi } from "../../api/CoupleApi"; -import { dateTimestamp, fmtDate } from "../../api/MemberApi"; +import { Couple, CoupleApi } from "../../api/genealogy/CoupleApi"; +import { dateTimestamp, fmtDate } from "../../api/genealogy/MemberApi"; import { ServerApi } from "../../api/ServerApi"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../../hooks/context_providers/ConfirmDialogProvider"; diff --git a/geneit_app/src/routes/family/FamilyMemberRoute.tsx b/geneit_app/src/routes/family/FamilyMemberRoute.tsx index 7502189..c394f53 100644 --- a/geneit_app/src/routes/family/FamilyMemberRoute.tsx +++ b/geneit_app/src/routes/family/FamilyMemberRoute.tsx @@ -14,8 +14,8 @@ import { import * as EmailValidator from "email-validator"; import React from "react"; import { useNavigate, useParams } from "react-router-dom"; -import { Couple } from "../../api/CoupleApi"; -import { Member, MemberApi, fmtDate } from "../../api/MemberApi"; +import { Couple } from "../../api/genealogy/CoupleApi"; +import { Member, MemberApi, fmtDate } from "../../api/genealogy/MemberApi"; import { ServerApi } from "../../api/ServerApi"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../../hooks/context_providers/ConfirmDialogProvider"; diff --git a/geneit_app/src/routes/family/FamilyMembersListRoute.tsx b/geneit_app/src/routes/family/FamilyMembersListRoute.tsx index 49cc89a..25dcffc 100644 --- a/geneit_app/src/routes/family/FamilyMembersListRoute.tsx +++ b/geneit_app/src/routes/family/FamilyMembersListRoute.tsx @@ -8,7 +8,12 @@ import { Button, TextField, Tooltip, Typography } from "@mui/material"; import { DataGrid, GridActionsCellItem, GridColDef } from "@mui/x-data-grid"; import React from "react"; import { useNavigate } from "react-router-dom"; -import { Member, MemberApi, dateTimestamp, fmtDate } from "../../api/MemberApi"; +import { + Member, + MemberApi, + dateTimestamp, + fmtDate, +} from "../../api/genealogy/MemberApi"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../../hooks/context_providers/ConfirmDialogProvider"; import { useSnackbar } from "../../hooks/context_providers/SnackbarProvider"; diff --git a/geneit_app/src/routes/family/FamilySettingsRoute.tsx b/geneit_app/src/routes/family/FamilySettingsRoute.tsx index 9f98d70..c99cfbd 100644 --- a/geneit_app/src/routes/family/FamilySettingsRoute.tsx +++ b/geneit_app/src/routes/family/FamilySettingsRoute.tsx @@ -14,7 +14,7 @@ import { } from "@mui/material"; import React from "react"; import { useNavigate } from "react-router-dom"; -import { DataApi } from "../../api/DataApi"; +import { DataApi } from "../../api/genealogy/DataApi"; import { FamilyApi } from "../../api/FamilyApi"; import { ServerApi } from "../../api/ServerApi"; import { useAlert } from "../../hooks/context_providers/AlertDialogProvider"; diff --git a/geneit_app/src/utils/family_tree.ts b/geneit_app/src/utils/family_tree.ts index 5444540..62c9167 100644 --- a/geneit_app/src/utils/family_tree.ts +++ b/geneit_app/src/utils/family_tree.ts @@ -1,5 +1,5 @@ -import { Couple, CouplesList } from "../api/CoupleApi"; -import { Member, MembersList, dateTimestamp } from "../api/MemberApi"; +import { Couple, CouplesList } from "../api/genealogy/CoupleApi"; +import { Member, MembersList, dateTimestamp } from "../api/genealogy/MemberApi"; export interface CoupleInformation { couple: Couple; diff --git a/geneit_app/src/widgets/BaseFamilyRoute.tsx b/geneit_app/src/widgets/BaseFamilyRoute.tsx index 178b6d4..6f83a03 100644 --- a/geneit_app/src/widgets/BaseFamilyRoute.tsx +++ b/geneit_app/src/widgets/BaseFamilyRoute.tsx @@ -26,9 +26,9 @@ import { } from "@mui/material"; import React from "react"; import { Outlet, useLocation, useParams } from "react-router-dom"; -import { CoupleApi, CouplesList } from "../api/CoupleApi"; +import { CoupleApi, CouplesList } from "../api/genealogy/CoupleApi"; import { ExtendedFamilyInfo, FamilyApi } from "../api/FamilyApi"; -import { MemberApi, MembersList } from "../api/MemberApi"; +import { MemberApi, MembersList } from "../api/genealogy/MemberApi"; import { useAlert } from "../hooks/context_providers/AlertDialogProvider"; import { useConfirm } from "../hooks/context_providers/ConfirmDialogProvider"; import { useSnackbar } from "../hooks/context_providers/SnackbarProvider"; diff --git a/geneit_app/src/widgets/BasicFamilyTree.tsx b/geneit_app/src/widgets/BasicFamilyTree.tsx index eb450ae..87a2e3f 100644 --- a/geneit_app/src/widgets/BasicFamilyTree.tsx +++ b/geneit_app/src/widgets/BasicFamilyTree.tsx @@ -5,8 +5,8 @@ import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; import { TreeItem, SimpleTreeView } from "@mui/x-tree-view"; import React from "react"; import { useNavigate } from "react-router-dom"; -import { Couple } from "../api/CoupleApi"; -import { Member, fmtDate } from "../api/MemberApi"; +import { Couple } from "../api/genealogy/CoupleApi"; +import { Member, fmtDate } from "../api/genealogy/MemberApi"; import { FamilyTreeNode } from "../utils/family_tree"; import { useFamily } from "./BaseFamilyRoute"; import { MemberPhoto } from "./MemberPhoto"; diff --git a/geneit_app/src/widgets/CouplePhoto.tsx b/geneit_app/src/widgets/CouplePhoto.tsx index 059733f..323aef6 100644 --- a/geneit_app/src/widgets/CouplePhoto.tsx +++ b/geneit_app/src/widgets/CouplePhoto.tsx @@ -1,5 +1,5 @@ import { Avatar } from "@mui/material"; -import { Couple } from "../api/CoupleApi"; +import { Couple } from "../api/genealogy/CoupleApi"; export function CouplePhoto(p: { couple: Couple; diff --git a/geneit_app/src/widgets/MemberItem.tsx b/geneit_app/src/widgets/MemberItem.tsx index 0865076..99e11eb 100644 --- a/geneit_app/src/widgets/MemberItem.tsx +++ b/geneit_app/src/widgets/MemberItem.tsx @@ -5,7 +5,7 @@ import { ListItemSecondaryAction, ListItemText, } from "@mui/material"; -import { Member, fmtDate } from "../api/MemberApi"; +import { Member, fmtDate } from "../api/genealogy/MemberApi"; import { MemberPhoto } from "./MemberPhoto"; import Icon from "@mdi/react"; import FemaleIcon from "@mui/icons-material/Female"; diff --git a/geneit_app/src/widgets/MemberPhoto.tsx b/geneit_app/src/widgets/MemberPhoto.tsx index 5e19f06..fdbbf73 100644 --- a/geneit_app/src/widgets/MemberPhoto.tsx +++ b/geneit_app/src/widgets/MemberPhoto.tsx @@ -1,5 +1,5 @@ import { Avatar } from "@mui/material"; -import { Member } from "../api/MemberApi"; +import { Member } from "../api/genealogy/MemberApi"; export function MemberPhoto(p: { member?: Member; diff --git a/geneit_app/src/widgets/forms/DateInput.tsx b/geneit_app/src/widgets/forms/DateInput.tsx index 363aefa..64bdab9 100644 --- a/geneit_app/src/widgets/forms/DateInput.tsx +++ b/geneit_app/src/widgets/forms/DateInput.tsx @@ -1,6 +1,6 @@ import { Stack, TextField, Typography } from "@mui/material"; import { NumberConstraint, ServerApi } from "../../api/ServerApi"; -import { DateValue, fmtDate } from "../../api/MemberApi"; +import { DateValue, fmtDate } from "../../api/genealogy/MemberApi"; import { PropEdit } from "./PropEdit"; export function DateInput(p: { diff --git a/geneit_app/src/widgets/forms/MemberInput.tsx b/geneit_app/src/widgets/forms/MemberInput.tsx index 54c37e5..d35d212 100644 --- a/geneit_app/src/widgets/forms/MemberInput.tsx +++ b/geneit_app/src/widgets/forms/MemberInput.tsx @@ -2,7 +2,7 @@ import ClearIcon from "@mui/icons-material/Clear"; import { Autocomplete, IconButton, TextField, Typography } from "@mui/material"; import React from "react"; import { useNavigate } from "react-router-dom"; -import { Member } from "../../api/MemberApi"; +import { Member } from "../../api/genealogy/MemberApi"; import { useFamily } from "../BaseFamilyRoute"; import { MemberItem } from "../MemberItem"; diff --git a/geneit_app/src/widgets/forms/SexSelection.tsx b/geneit_app/src/widgets/forms/SexSelection.tsx index 49f53e5..941379f 100644 --- a/geneit_app/src/widgets/forms/SexSelection.tsx +++ b/geneit_app/src/widgets/forms/SexSelection.tsx @@ -6,7 +6,7 @@ import { Radio, Typography, } from "@mui/material"; -import { Sex } from "../../api/MemberApi"; +import { Sex } from "../../api/genealogy/MemberApi"; export function SexSelection(p: { readonly?: boolean; diff --git a/geneit_app/src/widgets/simple_family_tree/SimpleFamilyTree.tsx b/geneit_app/src/widgets/simple_family_tree/SimpleFamilyTree.tsx index e13c041..c784dc2 100644 --- a/geneit_app/src/widgets/simple_family_tree/SimpleFamilyTree.tsx +++ b/geneit_app/src/widgets/simple_family_tree/SimpleFamilyTree.tsx @@ -5,8 +5,8 @@ import { IconButton, Tooltip } from "@mui/material"; import jsPDF from "jspdf"; import React from "react"; import { TransformComponent, TransformWrapper } from "react-zoom-pan-pinch"; -import { Couple } from "../../api/CoupleApi"; -import { Member } from "../../api/MemberApi"; +import { Couple } from "../../api/genealogy/CoupleApi"; +import { Member } from "../../api/genealogy/MemberApi"; import { useDarkTheme } from "../../hooks/context_providers/DarkThemeProvider"; import { FamilyTreeNode } from "../../utils/family_tree"; import { downloadBlob } from "../../utils/files_utils"; diff --git a/geneit_backend/src/main.rs b/geneit_backend/src/main.rs index 711766b..683dfcb 100644 --- a/geneit_backend/src/main.rs +++ b/geneit_backend/src/main.rs @@ -137,71 +137,71 @@ async fn main() -> std::io::Result<()> { "/family/{id}/user/{user_id}", web::delete().to(families_controller::delete_membership), ) - // Members controller + // [GENEALOGY] Members controller .route( - "/family/{id}/member/create", + "/family/{id}/genealogy/member/create", web::post().to(members_controller::create), ) .route( - "/family/{id}/members", + "/family/{id}/genealogy/members", web::get().to(members_controller::get_all), ) .route( - "/family/{id}/member/{member_id}", + "/family/{id}/genealogy/member/{member_id}", web::get().to(members_controller::get_single), ) .route( - "/family/{id}/member/{member_id}", + "/family/{id}/genealogy/member/{member_id}", web::put().to(members_controller::update), ) .route( - "/family/{id}/member/{member_id}", + "/family/{id}/genealogy/member/{member_id}", web::delete().to(members_controller::delete), ) .route( - "/family/{id}/member/{member_id}/photo", + "/family/{id}/genealogy/member/{member_id}/photo", web::put().to(members_controller::set_photo), ) .route( - "/family/{id}/member/{member_id}/photo", + "/family/{id}/genealogy/member/{member_id}/photo", web::delete().to(members_controller::remove_photo), ) - // Couples controller + // [GENEALOGY] Couples controller .route( - "/family/{id}/couple/create", + "/family/{id}/genealogy/couple/create", web::post().to(couples_controller::create), ) .route( - "/family/{id}/couples", + "/family/{id}/genealogy/couples", web::get().to(couples_controller::get_all), ) .route( - "/family/{id}/couple/{couple_id}", + "/family/{id}/genealogy/couple/{couple_id}", web::get().to(couples_controller::get_single), ) .route( - "/family/{id}/couple/{couple_id}", + "/family/{id}/genealogy/couple/{couple_id}", web::put().to(couples_controller::update), ) .route( - "/family/{id}/couple/{couple_id}", + "/family/{id}/genealogy/couple/{couple_id}", web::delete().to(couples_controller::delete), ) .route( - "/family/{id}/couple/{couple_id}/photo", + "/family/{id}/genealogy/couple/{couple_id}/photo", web::put().to(couples_controller::set_photo), ) .route( - "/family/{id}/couple/{couple_id}/photo", + "/family/{id}/genealogy/couple/{couple_id}/photo", web::delete().to(couples_controller::remove_photo), ) - // Data controller + // [GENEALOGY] Data controller .route( - "/family/{id}/data/export", + "/family/{id}/genealogy/data/export", web::get().to(data_controller::export_family), ) .route( - "/family/{id}/data/import", + "/family/{id}/genealogy/data/import", web::put().to(data_controller::import_family), ) // Photos controller