-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistapetController.jsp
116 lines (103 loc) · 4.55 KB
/
listapetController.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="pawfect_home.*" %>
<%@ page import="java.sql.Date" %>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.time.LocalDate" %>
<%@ page import="java.util.* , java.io.*"%>
<%@ page import="java.util.Base64" %>
<%
request.setCharacterEncoding("UTF-8");
String stayHome = request.getParameter("stay_home");
boolean stayAtOwner = true;
if (stayHome == null){
stayAtOwner = false;
}
java.time.LocalDate currentDate = java.time.LocalDate.now();
java.sql.Date uploadDate = java.sql.Date.valueOf(currentDate);
String stringStart = request.getParameter("start");
java.sql.Date startDate = java.sql.Date.valueOf(stringStart);
String stringEnd=request.getParameter("end");
java.sql.Date endDate = java.sql.Date.valueOf(stringEnd);
String description = request.getParameter("description");
int price = Integer.parseInt(request.getParameter("price"));
String name = request.getParameter("petName");
String animal = request.getParameter("animal");
String breed = request.getParameter("breed");
int size = Integer.parseInt(request.getParameter("petSize"));
User user = (User) session.getAttribute("userCookie");
String username = user.getUsername();
String imageUrl = request.getParameter("imageUrl");
int f_key = 0;
int comparison = startDate.compareTo(endDate);
int validRangeofDates = startDate.compareTo(uploadDate);
List<String> errorMessages = new ArrayList<String>();
if (comparison > 0) {
errorMessages.add("Start date must be before end date");
}
if (validRangeofDates<0){
errorMessages.add("Start date must be valid");
}
if(size <= 0){
errorMessages.add("Pet size must be bigger than zero");
}
if (price < 0) {
errorMessages.add("Price must be bigger or equal to zero");
}
if (name.length() <= 1) {
errorMessages.add("Pet Name cannot be one letter");
}
if (errorMessages.size() > 0) {
request.setAttribute("messages", errorMessages);
%>
<jsp:forward page="listapet.jsp" />
<%
} else{
Listing listing = new Listing(uploadDate, stayAtOwner, startDate, endDate, price, description, username);
ListingDAO listingdao = new ListingDAO();
f_key = listingdao.createListing(listing);
Pet pet = new Pet(name, animal, breed, size, imageUrl);
PetDAO petdao = new PetDAO();
petdao.createPet(pet, f_key);
%>
<meta http-equiv="refresh" content="4;url=index.jsp" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.7">
<title>Pet Sharing Platform</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- Include Bootstrap Datepicker CSS -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css">
<link
href="https://fonts.googleapis.com/css?family=Quicksand:400,700&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="css/listapet.css">
<style>
.centered {
position: fixed;
top: 40%;
}
</style>
<body id="bodylisting">
<div class="container theme-showcase" role="main">
<div class="alert alert-success text-center centered col-10 offset-1 col-md-4 offset-md-2" role="alert" style="background-color: white; border-radius: 1rem;">
Your Listing has been submitted to the platform!
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0m-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/>
</svg>
</div>
</div>
<!-- Include Bootstrap JS (optional) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Include Bootstrap Datepicker JS -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</body>
<% } %>