Skip to content

completed task 5 & 6 #329

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions final_project/router/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,20 @@ let users = require("./auth_users.js").users;
const public_users = express.Router();


public_users.post("/register", (req,res) => {
//Write your code here
return res.status(300).json({message: "Yet to be implemented"});
});
public_user.post("/register", (req,res) =>{
const {username, password} = req.body;

if(!username || !password){
return res.status(400).json({message: "username and password are required"});
}
const userExists = user.some(user => user.username === username);
if(userExists){
return res.status(409).json({message: "User already exists"});
}
user.push({username, password});
return res.status(200).json({messsage: "user registerd successfulluy"});
}
)};

// Get the book list available in the shop
public_users.get('/',function (req, res) {
Expand Down Expand Up @@ -36,8 +46,13 @@ public_users.get('/title/:title',function (req, res) {

// Get book review
public_users.get('/review/:isbn',function (req, res) {
//Write your code here
return res.status(300).json({message: "Yet to be implemented"});
const isbn = req.params.isbn;
const book = book[isbn];
if(book && book.reviews){
return res.status(200).json(book.reviews);
}else{
return res.status(404).json({message: "Noreviews found for this book"});
}
});

module.exports.general = public_users;