Skip to content

Commit

Permalink
merge writting-review
Browse files Browse the repository at this point in the history
  • Loading branch information
lahiru-rajapakshe committed Nov 29, 2022
2 parents a7d5692 + c45e061 commit f3daf54
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 5 deletions.
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"jquery": "^3.6.1",
"jquery-ui": "^1.13.2",
"jquery-validation": "^1.19.5"
"jquery-validation": "^1.19.5",
"rateyo": "^3.0.0-alpha.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.demo2.controller.frontend.review;

import com.example.demo2.service.ReviewService;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "SubmitReviewServlet", value = "/SubmitReviewServlet")
public class SubmitReviewServlet extends HttpServlet {


@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ReviewService reviewService = new ReviewService(request, response);
reviewService.submitReview();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.demo2.controller.frontend.review;

import com.example.demo2.service.ReviewService;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet(name = "/write_review", value = "/ServletWriteReviewServlet")
public class WriteReviewServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ReviewService reviewService = new ReviewService(request, response);
reviewService.showReviewForm();
}


}
20 changes: 17 additions & 3 deletions src/main/java/com/example/demo2/dao/ReviewDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.example.demo2.entity.Review;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReviewDAO extends JpaDAO<Review> implements GenericDAO<Review> {
@Override
public Review get(Object reviewId) {
return super.find(Review.class,reviewId)
return super.find(Review.class, reviewId)
}

@Override
Expand All @@ -16,7 +18,7 @@ public Review create(Review entity) {

@Override
public void delete(Object reviewId) {
super.delete(Review.class,reviewId);
super.delete(Review.class, reviewId);

}

Expand All @@ -28,7 +30,19 @@ public List<Review> listAll() {
@Override
public long count() {

return super.contWithNamedQuery("Review.countAll");
return super.contWithNamedQuery("Review.countAll");
}

public Review findByCustomerAnBook(Integer customerId,Integer bookId){
Map<String, Object> parameters= new HashMap<>();
parameters.put("customerId",customerId);
parameters.put("bookId",bookId);

List<Review> result = super.findWithNamedQuery("Review.findByCustomerAndBook", parameters);
if(!result.isEmpty()){
return result.get(0);
}
return null;

}
}
2 changes: 2 additions & 0 deletions src/main/java/com/example/demo2/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@NamedQueries({
@NamedQuery(name ="Review.listAll" ,query = "SELECT r FROM Review ORDER BY r.reviewTime DESC"),
@NamedQuery(name ="Review.countAll" ,query = "SELECT Count(r) FROM Review r")
@NamedQuery(name ="Review.findByCustomerAndBook" ,
query = "SELECT r FROM Review r WHERE r.customer.customerId =: customerId AND r.book.bookId =: bookId")
})
public class Review {
private Integer reviewId;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/com/example/demo2/service/ReviewService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.demo2.service;

import com.example.demo2.dao.BookDAO;
import com.example.demo2.dao.ReviewDAO;
import com.example.demo2.entity.Book;
import com.example.demo2.entity.Review;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -87,5 +89,35 @@ public void deleteReview() throws ServletException, IOException {

listAllReview(message);

}

public void showReviewForm() throws ServletException, IOException {
Integer book_id = Integer.parseInt(request.getParameter("book_id"));
BookDAO bookDAO = new BookDAO();
bookDAO.get(book_id)

String targetPage="frontend/review_form.jsp";
RequestDispatcher requestDispatcher = request.getRequestDispatcher(targetPage);
requestDispatcher.forward(request,response);

}

public void submitReview() {
Integer book_id = Integer.parseInt(request.getParameter("book_id"));
Integer rating = Integer.parseInt(request.getParameter("rating"));
String headline = request.getParameter("headline");
String comment = request.getParameter("comment");

Review review = new Review();
review.setHeadline(headline);
review.setComment(comment);
review.setRating(rating);

Book book = new Book();
book.setBookId(book_id);




}
}

0 comments on commit f3daf54

Please sign in to comment.