From 91c8abd8c626478859ec245179f7f78c1d50523f Mon Sep 17 00:00:00 2001 From: kristijanjakimov Date: Fri, 25 Oct 2024 17:32:46 +0200 Subject: [PATCH] create form gets restored to no values --- .../com/example/backend/service/MovieActorService.java | 9 ++++----- .../example/backend/service/MovieDirectorService.java | 9 ++++----- frontend/src/Component/App/Details/MovieControls.tsx | 4 ++-- .../Component/App/EditMovieForm/EditablePersonList.tsx | 3 ++- frontend/src/Component/App/Header.tsx | 1 + frontend/src/Component/App/Main.tsx | 2 ++ frontend/src/Component/App/Main/CreateButton.tsx | 4 ++-- 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/com/example/backend/service/MovieActorService.java b/backend/src/main/java/com/example/backend/service/MovieActorService.java index 0c4f410..f6d0158 100644 --- a/backend/src/main/java/com/example/backend/service/MovieActorService.java +++ b/backend/src/main/java/com/example/backend/service/MovieActorService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -42,11 +43,9 @@ public MovieActorRelation addActor(String movieId, String actorId) { } public void removeActor(String movieId, String actorId) { - MovieActorRelation relation = movieActorRelationRepository - .findByMovieIdAndActorId(movieId, actorId) - .orElseThrow(); - - movieActorRelationRepository.delete(relation); + Optional relation = movieActorRelationRepository + .findByMovieIdAndActorId(movieId, actorId); + relation.ifPresent(movieActorRelationRepository::delete); } public void removeRelationsByMovieId(String movieId) { diff --git a/backend/src/main/java/com/example/backend/service/MovieDirectorService.java b/backend/src/main/java/com/example/backend/service/MovieDirectorService.java index 9428b57..d8f585b 100644 --- a/backend/src/main/java/com/example/backend/service/MovieDirectorService.java +++ b/backend/src/main/java/com/example/backend/service/MovieDirectorService.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -41,11 +42,9 @@ public MovieDirectorRelation addRelation(String movieId, String directorId) { } public void removeRelation(String movieId, String directorId) { - MovieDirectorRelation relation = movieDirectorRelationRepository - .findByMovieIdAndDirectorId(movieId, directorId) - .orElseThrow(); - - movieDirectorRelationRepository.delete(relation); + Optional relation = movieDirectorRelationRepository + .findByMovieIdAndDirectorId(movieId, directorId); + relation.ifPresent(movieDirectorRelationRepository::delete); } public void removeRelationsByMovieId(String movieId) { diff --git a/frontend/src/Component/App/Details/MovieControls.tsx b/frontend/src/Component/App/Details/MovieControls.tsx index b2fe268..7cdc206 100644 --- a/frontend/src/Component/App/Details/MovieControls.tsx +++ b/frontend/src/Component/App/Details/MovieControls.tsx @@ -54,7 +54,7 @@ export default function MovieControls( if (actorInstance.id) { const data = { movieId: movieResponse.data.id, - actorId: actorInstance.id + personId: actorInstance.id } await axios.post(`/api/movie-actor`, data); } @@ -65,7 +65,7 @@ export default function MovieControls( if (directorInstance.id) { const data = { movieId: movieResponse.data.id, - directorId: directorInstance.id + personId: directorInstance.id } await axios.post(`/api/movie-director`, data); } diff --git a/frontend/src/Component/App/EditMovieForm/EditablePersonList.tsx b/frontend/src/Component/App/EditMovieForm/EditablePersonList.tsx index c17806f..fd85a4d 100644 --- a/frontend/src/Component/App/EditMovieForm/EditablePersonList.tsx +++ b/frontend/src/Component/App/EditMovieForm/EditablePersonList.tsx @@ -23,6 +23,7 @@ export default function EditablePersonList({legend, staff, setStaff, autocomplet person ] ); + setPerson({id: "", name: ""}); } return ( @@ -32,7 +33,7 @@ export default function EditablePersonList({legend, staff, setStaff, autocomplet {Array.isArray(staff) && staff.length > 0 ? ( staff.map((person) => ( -
+
diff --git a/frontend/src/Component/App/Header.tsx b/frontend/src/Component/App/Header.tsx index e7047a4..41bda0d 100644 --- a/frontend/src/Component/App/Header.tsx +++ b/frontend/src/Component/App/Header.tsx @@ -14,6 +14,7 @@ export default function Header( function login() { const host = window.location.host === 'localhost:5173' ? 'http://localhost:8080' : window.location.origin window.open(host + '/oauth2/authorization/github', '_self') + navigate("/") } const loadUser = () => { diff --git a/frontend/src/Component/App/Main.tsx b/frontend/src/Component/App/Main.tsx index ef421aa..a8e9f5a 100644 --- a/frontend/src/Component/App/Main.tsx +++ b/frontend/src/Component/App/Main.tsx @@ -46,6 +46,8 @@ export default function Main( isWatched: true, movieId: "" }) + setActorsData([]) + setDirectorsData([]) }, [isUpdated, userName]); const [movieData, setMovieData] = useState({ diff --git a/frontend/src/Component/App/Main/CreateButton.tsx b/frontend/src/Component/App/Main/CreateButton.tsx index fd631c9..dc72fb8 100644 --- a/frontend/src/Component/App/Main/CreateButton.tsx +++ b/frontend/src/Component/App/Main/CreateButton.tsx @@ -49,7 +49,7 @@ export default function CreateButton( if (actorInstance.id) { const data = { movieId: movieResponse.data.id, - actorId: actorInstance.id + personId: actorInstance.id } await axios.post(`/api/movie-actor`, data); } @@ -60,7 +60,7 @@ export default function CreateButton( if (directorInstance.id) { const data = { movieId: movieResponse.data.id, - directorId: directorInstance.id + personId: directorInstance.id } await axios.post(`/api/movie-director`, data); }