Skip to content

Commit

Permalink
set initial rating
Browse files Browse the repository at this point in the history
  • Loading branch information
RbAvci committed May 23, 2024
1 parent fa39a7e commit 9dd8510
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/src/NewVideoForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./NewVideoForm.css";
const NewVideoForm = ({ onSubmit }) => {
const [title, setTitle] = useState("");
const [src, setSrc] = useState("");


const handleSubmit = (e) => {
e.preventDefault();
Expand Down
8 changes: 6 additions & 2 deletions server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.post("/videos", async (req, res) => {
return res.status(422).json({ message: "src field is required" });
}
const result = await db.query(
`INSERT INTO videos (title,src) VALUES ('${req.body.title}','${req.body.src}') RETURNING id`
`INSERT INTO videos (title,src,rating) VALUES ('${req.body.title}','${req.body.src}', 0) RETURNING id`
);
const newVideoId = result.rows[0].id;
res.status(200).json({ success: true, data: { id: newVideoId } });
Expand Down Expand Up @@ -57,7 +57,11 @@ router.put("/videos/:id/rating", async (req, res) => {

res
.status(200)
.json({ success: true, message: "Video updated successfully", data:{rating:rating} });
.json({
success: true,
message: "Video updated successfully",
data: { rating: rating },
});
} catch (error) {
res.status(500).json({ success: false, error: "Internal server error" });
}
Expand Down

0 comments on commit 9dd8510

Please sign in to comment.