From 60c07ea4e4174ed87f7a445e1822c66973d8d9ed Mon Sep 17 00:00:00 2001 From: Bibhabasu Date: Fri, 29 Mar 2024 05:03:54 +0530 Subject: [PATCH 1/2] movie upload added --- src/components/VideoUpload.js | 151 ++++++++++++++++------------------ 1 file changed, 72 insertions(+), 79 deletions(-) diff --git a/src/components/VideoUpload.js b/src/components/VideoUpload.js index dc2e006..4598b1f 100644 --- a/src/components/VideoUpload.js +++ b/src/components/VideoUpload.js @@ -1,3 +1,4 @@ +import axios from "axios"; import { Box, Button, @@ -55,44 +56,35 @@ const VideoUpload = () => { const [moviefile, setMovieFile] = useState(null); const [movieDetails, setMovieDetails] = useState({ - movieName: "", - movieCertification: [ - { - title: "", - }, - ], - genre: [ - { - title: "", - }, - ], + title: "", + plot: "", + genres: [], + runtime: "", cast: "", - country: [ - { - title: "", + languages: [], + released: "", + directors: [], + rated: "", + imdb: { + rating: "", + votes: "", + }, + countries: [], + type: "movie", + tomatoes: { + viewer: { + rating: "", + numReviews: "", + meter: "", }, - ], - director: "", - language: [ - { - title: "", - }, - ], - writer: "", - releasedDate: "", - imdbRating: "", - imdbVotes: "", - awardName: "", - totalAwards: "", - description: "", + }, }); const handleChange = (e) => { - console.log("e.target.id : ", e.target.id); - console.log("e.target.value : ", e.target.value); + console.log(e.target.value); setMovieDetails({ ...movieDetails, - [e.target.id]: e.target.value, + [e.target.name]: e.target.value, }); }; @@ -106,7 +98,7 @@ const VideoUpload = () => { const handleAutoCompleteChange = (event, value) => { setMovieDetails({ ...movieDetails, - movieCertification: value.map((item) => item), + [event.target.id]: value.map((item) => item.title), }); }; @@ -115,7 +107,22 @@ const VideoUpload = () => { console.log(event.target.files[0]); }; - const handleSubmit = (e) => {}; + const handleSubmit = async (e) => { + e.preventDefault(); + try { + const response = await axios.post("http://localhost:3001/admin/uploadmovie", movieDetails, { + headers: { + "Content-Type": "multipart/form-data", + "Authorization": `Bearer ${localStorage.getItem("token")}`, + }, + }); + console.log(movieDetails); + console.log("Movie uploaded successfully:", response.data); + // Reset form fields or navigate to another page upon successful upload + } catch (error) { + console.error("Error uploading movie:", error); + } + }; return (
@@ -133,14 +140,14 @@ const VideoUpload = () => { onChange={handleChange} required fullWidth - id="movieName" + id="title" // label="Enter email" - value={movieDetails.movieName} - name="movieName" + value={movieDetails.title} + name="title" sx={{ mt: 1, mb: 2 }} /> - + {/* Movie Certification @@ -157,7 +164,7 @@ const VideoUpload = () => { )} /> - + */} { > - Enter Genre + Genres option.title} - onChange={handleAutoCompleteChange} size="small" sx={{ mt: 1, mb: 2 }} - renderInput={(params) => } + renderInput={(params) => ( + + )} /> @@ -211,15 +220,16 @@ const VideoUpload = () => { multiple limitTags={2} onOpen={() => countries(dispatch)} - id="country" + id="countries" // Changed id to match schema options={Countries} getOptionLabel={(option) => option.title} onChange={handleAutoCompleteChange} size="small" sx={{ mt: 1, mb: 2 }} - renderInput={(params) => } + renderInput={(params) => } // Changed id to match schema /> + Enter Director Name @@ -232,13 +242,14 @@ const VideoUpload = () => { marginTop: "0.5rem", marginBottom: "1rem", }} - onChange={(value) => handleTagInputChange(value, "director")} - value={movieDetails.director} - id="director" + onChange={(value) => handleTagInputChange(value, "directors")} // Changed "director" to "directors" to match schema + value={movieDetails.directors} // Changed "director" to "directors" to match schema + id="directors" // Changed id to match schema menuStyle={{ width: "100%" }} size="lg" /> + { option.title} onChange={handleAutoCompleteChange} size="small" sx={{ mt: 1, mb: 2 }} renderInput={(params) => ( - + // Changed id to match schema )} /> + Enter Writer Name @@ -274,9 +286,9 @@ const VideoUpload = () => { marginTop: "0.5rem", marginBottom: "1rem", }} - id="writer" - onChange={(value) => handleTagInputChange(value, "writer")} - value={movieDetails.writer} + id="writers" // Changed id to match schema + onChange={(value) => handleTagInputChange(value, "writers")} // Changed "writer" to "writers" to match schema + value={movieDetails.writers} // Changed "writer" to "writers" to match schema menuStyle={{ width: "100%" }} size="lg" /> @@ -293,17 +305,18 @@ const VideoUpload = () => { option.title} size="small" sx={{ mt: 1, mb: 2 }} renderInput={(params) => ( - + // Changed id to match schema )} /> + Select Released Date @@ -317,7 +330,7 @@ const VideoUpload = () => { marginBottom: "1rem", }} onChange={(value) => handleTagInputChange(value, "releasedDate")} - id="released" + id="releasedDate" // Changed id to match schema size="lg" /> @@ -368,24 +381,6 @@ const VideoUpload = () => { sx={{ mt: 1, mb: 2 }} /> - - - Total Votes - - - { > - Some Information + Some Information. { - Description + plot From 95f7d7ee8941597284148a66adb21c3adc549dc8 Mon Sep 17 00:00:00 2001 From: Bibhabasu Date: Fri, 29 Mar 2024 23:59:26 +0530 Subject: [PATCH 2/2] content type changed --- src/components/VideoUpload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/VideoUpload.js b/src/components/VideoUpload.js index 4598b1f..963ea78 100644 --- a/src/components/VideoUpload.js +++ b/src/components/VideoUpload.js @@ -112,7 +112,7 @@ const VideoUpload = () => { try { const response = await axios.post("http://localhost:3001/admin/uploadmovie", movieDetails, { headers: { - "Content-Type": "multipart/form-data", + "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}`, }, });