categories = new ArrayList<>();
+ while (rs.next()) {
+ categories.add(extractCategory(rs));
+ }
+ return categories;
+ }
+}
diff --git a/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java b/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java
index 4e69e57044..642bbf1666 100644
--- a/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java
+++ b/src/main/java/com/codeup/adlister/dao/MySQLUsersDao.java
@@ -51,6 +51,86 @@ public Long insert(User user) {
}
}
+ @Override
+ public User findByUserID(long id) {
+ String query = "SELECT * FROM users WHERE id = ? LIMIT 1";
+ try {
+ PreparedStatement stmt = connection.prepareStatement(query);
+ stmt.setLong(1, id);
+ return extractUser(stmt.executeQuery());
+ } catch (SQLException e) {
+ throw new RuntimeException("Error finding a user by username", e);
+ }
+ }
+
+ @Override
+ public User findByAd(long ad_id) {
+ String query = "SELECT * from users where id in (select user_id FROM ads where id = ?)";
+ try {
+ PreparedStatement stmt = connection.prepareStatement(query);
+ stmt.setLong(1, ad_id);
+ ResultSet rs = stmt.executeQuery();
+ System.out.println(rs);
+// rs.next();
+ return extractUser(rs);
+ } catch (SQLException e) {
+ throw new RuntimeException("Error finding ad username", e);
+ }
+ }
+
+ @Override
+ public void updateUser(User user) {
+ //updates only password and email
+ String updateSql = "UPDATE users set password = ?, email = ? where id = ?";
+ try {
+ PreparedStatement stmt = connection.prepareStatement(updateSql, Statement.RETURN_GENERATED_KEYS);
+ stmt.setString(1, user.getPassword());
+ stmt.setString(2, user.getEmail());
+ stmt.setLong(3, user.getId());
+ stmt.executeUpdate();
+ ResultSet rs = stmt.getGeneratedKeys();
+ rs.next();
+ // testing for the expected messages.
+ System.out.println(stmt);
+ System.out.println(stmt.executeUpdate());
+
+ } catch (SQLException e) {
+ throw new RuntimeException("Error Editing an Ad by ID", e);
+ }
+
+ }
+
+
+
+
+ @Override
+ public User findByUserEmail(String email) {
+ String query = "SELECT * FROM users WHERE email = ? LIMIT 1";
+ try {
+ PreparedStatement stmt = connection.prepareStatement(query);
+ stmt.setString(1, email);
+ return extractUser(stmt.executeQuery());
+ } catch (SQLException e) {
+ throw new RuntimeException("Error finding a user by email", e);
+ }
+
+ }
+
+ @Override
+ public void deleteByID(long id) {
+ String query = "DELETE FROM users WHERE id = ? LIMIT 1";//? will be replaced by the ID to be deleted
+ try {
+ PreparedStatement stmt = connection.prepareStatement(query);
+ stmt.setLong(1, id);
+ System.out.println(stmt);
+ System.out.println(stmt.executeQuery());
+ stmt.execute();// EXECUTES A QUERY
+ } catch (SQLException e){
+ throw new RuntimeException("Error deleting a User by ID, e");
+ }
+
+ }
+
private User extractUser(ResultSet rs) throws SQLException {
if (! rs.next()) {
return null;
diff --git a/src/main/java/com/codeup/adlister/dao/Users.java b/src/main/java/com/codeup/adlister/dao/Users.java
index 62da74d20b..92a8879e53 100644
--- a/src/main/java/com/codeup/adlister/dao/Users.java
+++ b/src/main/java/com/codeup/adlister/dao/Users.java
@@ -7,4 +7,9 @@
public interface Users {
User findByUsername(String username);
Long insert(User user);
+ User findByUserID(long id);
+ void updateUser(User user);
+ User findByUserEmail(String email);
+ void deleteByID(long id);
+ User findByAd(long ad_id);
}
diff --git a/src/main/java/com/codeup/adlister/models/Category.java b/src/main/java/com/codeup/adlister/models/Category.java
new file mode 100644
index 0000000000..e6ea068ff1
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/models/Category.java
@@ -0,0 +1,29 @@
+package com.codeup.adlister.models;
+
+public class Category {
+ private long id;
+ private String category;
+
+
+ public Category(long id, String category) {
+ this.id = id;
+ this.category = category;
+ }
+
+ public long getId() {
+ return id;
+ }
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+}
+
+
diff --git a/src/main/java/com/codeup/adlister/util/Validate.java b/src/main/java/com/codeup/adlister/util/Validate.java
new file mode 100644
index 0000000000..b1e3e3a8d4
--- /dev/null
+++ b/src/main/java/com/codeup/adlister/util/Validate.java
@@ -0,0 +1,35 @@
+package com.codeup.adlister.util;
+
+import java.util.regex.Pattern;
+
+public class Validate {
+
+
+ //When a string of email gets passed it is ran against
+ //the regex and if it matches it will return true;
+ public static boolean emailVal(String email) {
+ //regex for emails to be like bob@mail.com
+ String emailRegex = "^[a-zA-Z0-9_+&*-]+(?:\\."+
+ "[a-zA-Z0-9_+&*-]+)*@" +
+ "(?:[a-zA-Z0-9-]+\\.)+[a-z" +
+ "A-Z]{2,7}$";
+
+ Pattern pat = Pattern.compile(emailRegex);
+
+ return pat.matcher(email).matches();
+
+ }
+
+ //When a string of password gets passed it is ran against
+ //the regex and if it matches it will return true;
+ public static boolean passVal(String password){
+ //regex for passwords to have 6-15 characters and at least one character
+ //of uppercase, lowercase, number, and symbol of @#$%^&+= example Java#@#8 is true
+ String passRegex ="^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])(?=\\S+$).{6,15}$";
+ Pattern pat = Pattern.compile(passRegex);
+
+ return pat.matcher(password).matches();
+
+ }
+
+}
diff --git a/src/main/webapp/WEB-INF/ads/ShowIndvAd.jsp b/src/main/webapp/WEB-INF/ads/ShowIndvAd.jsp
new file mode 100644
index 0000000000..9d08e14cc3
--- /dev/null
+++ b/src/main/webapp/WEB-INF/ads/ShowIndvAd.jsp
@@ -0,0 +1,60 @@
+<%--
+ Created by IntelliJ IDEA.
+ User: jose
+ Date: 2/14/22
+ Time: 2:03 PM
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+
+
+
+
+
+
+
Your Ad
+
+
+
+
Title: ${ad.title}
+ Description: ${ad.description}
+ User: ${userAd}
+
+
+
+
+
+ Back to Ads
+
+
+<%--after user logged in/ on user profile--%>
+
+
+
+
Title: ${ad.title}
+ Description: ${ad.description}
+ User: ${userAd}
+
+
+
+
+
+ Back to Profile
+ Back to Ads
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/ads/categories.jsp b/src/main/webapp/WEB-INF/ads/categories.jsp
new file mode 100644
index 0000000000..7056daa4df
--- /dev/null
+++ b/src/main/webapp/WEB-INF/ads/categories.jsp
@@ -0,0 +1,66 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%--
+ Created by IntelliJ IDEA.
+ User: jose
+ Date: 2/16/22
+ Time: 11:09 AM
+ To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+
+
+
+
+
+
+
+
+
+
+
All Categories
+
+
+
+
+
Category: ${category}
+
+
+<%--
--%>
+
+
+
+
+
+ Return Home
+ See all Ads
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/ads/create.jsp b/src/main/webapp/WEB-INF/ads/create.jsp
index f6332692f7..eaf39d8196 100644
--- a/src/main/webapp/WEB-INF/ads/create.jsp
+++ b/src/main/webapp/WEB-INF/ads/create.jsp
@@ -1,11 +1,14 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
Create a new Ad
-
+
+
+
+
+
+
+ ${category.category}
+
+
+
+ <%--createError attribute posts error message from createAdServlet --%>
+
+ ${createError}
+
+<%--added link to get back to profile- AG--%>
+ Back to Profile
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/ads/index.jsp b/src/main/webapp/WEB-INF/ads/index.jsp
index 6f4371f0bb..27379e8c94 100644
--- a/src/main/webapp/WEB-INF/ads/index.jsp
+++ b/src/main/webapp/WEB-INF/ads/index.jsp
@@ -5,20 +5,64 @@
+
-
+
Here Are all the ads!
+
+
+
+
+
+ <%-- --%>
+
+ <%-- --%>
+ ${ad.title}
+ ${ad.description}
+ Show Ad
+
+
+ <%--
${ad.description}
--%>
+
+
+
+
+
+
+ Return Home
+
+
+
+
+<%--after user logged in--%>
+
+
-
-
${ad.title}
+
+
+<%-- --%>
+
+<%-- --%>
+ ${ad.title}
${ad.description}
+ Show Ad
+
+
+<%--
${ad.description}
--%>
+
+
+
+
+ Back to Profile
+
+