Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NW6 | Rabia Avci | Full-Stack-Project | Week-3 | Update videos endpoint #36

Merged
merged 4 commits into from
May 26, 2024

Conversation

RbAvci
Copy link
Owner

@RbAvci RbAvci commented May 22, 2024

Completed these tasks for this ticket:

  • Created an endpoint to update video ratings.
  • Configured the endpoint to accept the appropriate HTTP method.
  • Defined a suitable URL for the endpoint.
  • Implemented functionality for the endpoint to update video ratings in the database.

Copy link

netlify bot commented May 22, 2024

Deploy Preview for watch-next-cyf ready!

Name Link
🔨 Latest commit f68931d
🔍 Latest deploy log https://app.netlify.com/sites/watch-next-cyf/deploys/6653b3d8f81cb700087d108d
😎 Deploy Preview https://deploy-preview-36--watch-next-cyf.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@RbAvci RbAvci requested a review from zelihapala May 22, 2024 22:30
Copy link
Collaborator

@Ara225 Ara225 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback on the implementation details, but all in all, it works 👍

db/initdb.sql Outdated
INSERT INTO videos (title,src) VALUES ('Coding Adventure: Chess AI','https://www.youtube.com/watch?v=U4ogK0MIzqk');
INSERT INTO videos (title,src) VALUES ('Coding Adventure: Ant and Slime Simulations','https://www.youtube.com/watch?v=X-iSQQgOd1A');
INSERT INTO videos (title,src) VALUES ('Why the Tour de France is so brutal','https://www.youtube.com/watch?v=ZacOS8NBK6U');
INSERT INTO videos (title,src,rating) VALUES ('Never Gonna Give You Up','https://www.youtube.com/watch?v=dQw4w9WgXcQ', 5);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite an interesting choice to me. Without the users' input, you can't know what their rating is. Personally, I would always use null or -1 as a default value here.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Anna, default rate is set to NULL. I will update the front-end with 'not rated' when the value is null.

server/api.js Outdated
const { rating } = req.body;

try {
const result = await db.query(`SELECT * FROM videos WHERE id=${videoId}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned last time, this way of composing SQL isn't very secure - talk to Zeliha about the way she does it which is correct

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done it!

server/api.js Outdated
.status(200)
.json({ success: true, message: "Video rating successfully" });
} catch (error) {
res.status(500).json({ success: false, error: "Internal server error" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that you're using an appropriate error code, but I would like to see you being more specific here, yes an internal server error happened but why?

const result = await db.query(`SELECT * FROM videos WHERE id=${videoId}`);
let video = result.rows[0];
if (!video) {
return res.status(404).json({ error: "Video not found" });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@RbAvci RbAvci force-pushed the RB/Update_videos_endpoint branch from f538bb4 to 961f4cd Compare May 26, 2024 22:03
@RbAvci RbAvci merged commit 9151072 into main May 26, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants