github.com/ismailbayram/bigpicture@v0.0.0-20231225173155-e4b21f5efcff/internal/browser/javaproject/src/main/com/shashi/servlets/TicketBookingHistory.java (about)

     1  package com.shashi.servlets;
     2  
     3  import java.io.IOException;
     4  import java.io.PrintWriter;
     5  import java.util.List;
     6  
     7  import javax.servlet.RequestDispatcher;
     8  import javax.servlet.ServletException;
     9  import javax.servlet.annotation.WebServlet;
    10  import javax.servlet.http.HttpServlet;
    11  import javax.servlet.http.HttpServletRequest;
    12  import javax.servlet.http.HttpServletResponse;
    13  
    14  import com.shashi.beans.HistoryBean;
    15  import com.shashi.beans.TrainException;
    16  import com.shashi.constant.UserRole;
    17  import com.shashi.service.BookingService;
    18  import com.shashi.service.impl.BookingServiceImpl;
    19  import com.shashi.utility.TrainUtil;
    20  
    21  @SuppressWarnings("serial")
    22  @WebServlet("/bookingdetails")
    23  public class TicketBookingHistory extends HttpServlet {
    24  
    25  	BookingService bookingService = new BookingServiceImpl();
    26  
    27  	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    28  		res.setContentType("text/html");
    29  		PrintWriter pw = res.getWriter();
    30  		TrainUtil.validateUserAuthorization(req, UserRole.CUSTOMER);
    31  		try {
    32  			String customerId = TrainUtil.getCurrentUserEmail(req);
    33  			List<HistoryBean> details = bookingService.getAllBookingsByCustomerId(customerId);
    34  			if (details != null && !details.isEmpty()) {
    35  				RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html");
    36  				rd.include(req, res);
    37  				pw.println("<div class='main'><p1 class='menu'>Booked Ticket History</p1></div>");
    38  				pw.println("<div class='tab'><table><tr><th>Transaction ID</th><th>Train Number</th>"
    39  						+ "<th>From Station</th><th>To Station</th><th>Journey Date</th><th>Seat</th><th>Amount Paid</th></tr>");
    40  
    41  				for (HistoryBean trans : details) {
    42  
    43  					pw.println("" + "<tr> " + "" + "<td>" + trans.getTransId() + "</td>" + "<td>" + trans.getTr_no()
    44  							+ "</td>" + "<td>" + trans.getFrom_stn() + "</td>" + "<td>" + trans.getTo_stn() + "</td>"
    45  							+ "<td>" + trans.getDate() + "</td>" + "<td>" + trans.getSeats() + "</td><td>"
    46  							+ trans.getAmount() + "</td>" + "</tr>");
    47  				}
    48  				pw.println("</table></div>");
    49  			} else {
    50  				RequestDispatcher rd = req.getRequestDispatcher("UserViewTrains.html");
    51  				rd.include(req, res);
    52  				pw.println("<div class='main'><p1 class='menu red'> No any ticket booked, book your first ticket now!!</p1></div>");
    53  			}
    54  		} catch (Exception e) {
    55  			throw new TrainException(422, this.getClass().getName() + "_FAILED", e.getMessage());
    56  		}
    57  
    58  	}
    59  
    60  }