Skip to content

Commit a54eb35

Browse files
update
2 parents 959b779 + 9a2fd36 commit a54eb35

7 files changed

Lines changed: 46 additions & 17 deletions

File tree

src/main/java/com/codeup/adlister/controllers/DeleteAdsServlet.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class DeleteAdsServlet extends HttpServlet {
1717

1818
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
1919

20-
String title = (String) request.getParameter("title");
21-
System.out.println(title);
20+
long id = Long.parseLong( request.getParameter("id"));
21+
System.out.println(id);
2222

23-
Ad ad = DaoFactory.getAdsDao().ByTitle(title); //FIND THE AD TO DELETE
23+
Ad ad = DaoFactory.getAdsDao().ById(id); //FIND THE AD TO DELETE
2424
DaoFactory.getAdsDao().delete(ad); // DELETE AD
2525
response.sendRedirect("/ads");
2626

src/main/java/com/codeup/adlister/controllers/RegisterServlet.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
5252
request.setAttribute("passwordMismatch", "Please confirm your password you re-entered is correct.");
5353
request.getRequestDispatcher("/WEB-INF/register.jsp").forward(request, response);
5454

55+
<<<<<<< HEAD
5556
} else if (password.length() <= 6) {
5657
request.setAttribute("passwordLength", "Please confirm your password you re-entered is the correct length.");
5758
request.getRequestDispatcher("/WEB-INF/register.jsp").forward(request, response);
@@ -63,6 +64,15 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
6364

6465

6566

67+
=======
68+
69+
} else {
70+
correctInfo = true;
71+
}
72+
}
73+
}
74+
>>>>>>> 9a2fd364ccc8157288adddc4a51e0f568c34fd8d
75+
6676

6777

6878

src/main/java/com/codeup/adlister/controllers/UpdateAdServlet.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
@WebServlet(name = "controllers.UpdateAdServlet", urlPatterns = "/updateAd")
1515
public class UpdateAdServlet extends HttpServlet {
1616
String titleOld;
17+
long id;
18+
String oldDescription;
1719
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
1820

1921
titleOld = request.getParameter("title");
22+
id = Long.parseLong(request.getParameter("id"));
23+
oldDescription = request.getParameter("description");
24+
2025

2126
request.getRequestDispatcher("/WEB-INF/ads/updateAd.jsp")
2227
.forward(request, response);
@@ -26,10 +31,17 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
2631
User user = (User) request.getSession().getAttribute("user");
2732

2833
String title = request.getParameter("title");
29-
String description = request.getParameter("description");
34+
if( title.isEmpty()){title = titleOld;}
35+
36+
String description = request.getParameter("description");
37+
if( description.isEmpty()){ description = oldDescription;}
38+
39+
40+
3041

31-
System.out.println(titleOld);
32-
Ad ad = DaoFactory.getAdsDao().ByTitle(titleOld); //FIND THE AD TO UPDATE
42+
System.out.println(id);
43+
System.out.println(oldDescription);
44+
Ad ad = DaoFactory.getAdsDao().ById(id); //FIND THE AD TO UPDATE
3345
DaoFactory.getAdsDao().update(ad,title,description); // UPDATE AD
3446
response.sendRedirect("/ads");
3547

src/main/java/com/codeup/adlister/dao/Ads.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public interface Ads {
1616

1717

1818

19-
Ad ByTitle(String title);
19+
Ad ById(long id);
2020

2121
void delete(Ad ad);
2222

src/main/java/com/codeup/adlister/dao/ListAdsDao.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ public void update(Ad ad, String title, String description) {
3333
}
3434

3535
@Override
36-
public Ad ByTitle(String title) {
36+
public Ad ById(long id) {
3737
return null;
3838
}
3939

4040

41+
42+
4143
@Override
4244
public void delete(Ad ad) {
4345

src/main/java/com/codeup/adlister/dao/MySQLAdsDao.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ public void update(Ad ad, String title,String description) {
9696

9797

9898

99-
//**********************Find ad by the ad id to delete****************************
99+
//**********************Find ad by id to delete****************************
100100

101-
public Ad ByTitle(String title) {
101+
public Ad ById(long id) {
102102

103-
String sql = "SELECT * FROM ads WHERE title LIKE ?";
103+
String sql = "SELECT * FROM ads WHERE id = ?";
104104
PreparedStatement stmt = null;
105105
try {
106106
stmt = connection.prepareStatement(sql);
107-
stmt.setString(1,"%"+title+"%");
107+
stmt.setLong(1,id);
108108
ResultSet rs = stmt.executeQuery();
109109
List<Ad> ad = createAdsFromResults(rs);
110110

src/main/webapp/WEB-INF/profile.jsp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@
3030
<p class="card-text">${ad.description}</p>
3131

3232
<div class="row">
33-
<div class="col-6">
33+
<div class="col-6 mt-4">
3434
<form method="get" action="updateAd" >
3535

36-
<label for="edit"></label>
37-
<input id="edit" class="invisible" type="text" name="title" value="${ad.title}">
36+
<label for="update"></label>
37+
<input id="update" type="text" class="invisible" name="description" value="${ad.description}">
38+
<input type="text" class="invisible" name="title" value="${ad.title}">
39+
40+
<input type="text" class="invisible" name="id" value="${ad.id}">
3841
<button class="btn btn-primary" type="submit" >Update Ad</button>
3942
</form>
4043
</div>
4144

4245

43-
<div class="col-6">
46+
<div class="col-6 mt-4">
4447
<form method="post" action="deleteAd" >
4548
<label for="delete"></label>
46-
<input id="delete" class="invisible" type="text" name="title" value="${ad.title}">
49+
<input type="text" class="invisible" name="description" value="${ad.description}">
50+
51+
<input id="delete" type="text" class="invisible" name="id" value="${ad.id}">
4752

4853
<button class="btn btn-primary" type="submit" >Delete Ad</button>
4954
</form>

0 commit comments

Comments
 (0)