Skip to content

Commit

Permalink
saving updates to a few pages
Browse files Browse the repository at this point in the history
  • Loading branch information
AshNlandofOzz committed Oct 27, 2022
1 parent 6141b63 commit 7073ce2
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,38 @@ public String userDeleted(HttpSession session) {
session.invalidate();
return "redirect:home.do";
}

// @RequestMapping(path="getUser.do", params = {"userSearch", "searchType" })
// public String switchSearchMethods(String userSearch, int searchType, HttpSession session) {
// switch (searchType) {
// case 1:
// return getUserByUserName(session, userSearch);
// case 2:
// return getUserByFirstName(session, userSearch);
// case 3:
// return getUserByLastName(session, userSearch);
// default:
// return userListsPage(session);
// }
// }
//
// @RequestMapping(path="userSearch.do")
// public String userListsPage(HttpSession session) {
// return "user/userListsPage";
// }
//
// private String getUserByUserName(HttpSession session, String username) {
// session.setAttribute("user", userDao.findUserByUsername(username));
// return "user/userProfile";
// }
//
// private String getUserByFirstName(HttpSession session, String firstName) {
// session.setAttribute("user", userDao.findUserByFirstName(firstName));
// return "user/userProfile";
// }
//
// private String getUserByLastName(HttpSession session, String lastName) {
// session.setAttribute("user", userDao.findUserByLastName(lastName));
// return "user/userProfile";
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.skilldistillery.jpaclubindex.data;

import java.util.List;

import com.skilldistillery.jpaclubindex.entities.User;

public interface UserDAO {
Expand Down Expand Up @@ -40,16 +42,16 @@ public interface UserDAO {
User findUserByUsername(String username);

/**
* Given a first name will find the associated User
* @return User
* Given a first name will find the associated Users
* @return List<User>
* @author ashleyosburn
*/
User findUserByFirstName(String firstName);
List<User> findUserByFirstName(String firstName);

/**
* Given a last name will find the associated User
* @return User
* @return List<User>
* @author ashleyosburn
*/
User findUserByLastName(String lastName);
List<User> findUserByLastName(String lastName);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.skilldistillery.jpaclubindex.data;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
Expand Down Expand Up @@ -78,4 +80,16 @@ public User findUserByUsername(String username) {
return null;
}
}

@Override
public List<User> findUserByFirstName(String firstName) {
String query = "SELECT u FROM User u WHERE u.firstName = :firstName";
return em.createQuery(query, User.class).setParameter("firstName", firstName).getResultList();
}

@Override
public List<User> findUserByLastName(String lastName) {
String query = "SELECT u FROM User u WHERE u.lastName = :lastName";
return em.createQuery(query, User.class).setParameter("lastName", lastName).getResultList();
}
}
2 changes: 1 addition & 1 deletion ClubIndex/src/main/webapp/WEB-INF/author/author.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<tbody>
<tr>
<c:if test="${! empty aList.headshotUrl}">
<td><img src="${aList.headshotUrl}" alt="${aList.firstName} ${aList.lastName}" height="300" width="250"></td>
<td><img src="${aList.headshotUrl}" alt="${aList.firstName} ${aList.lastName}" style="height:300px;width:250px;height:100%;width:100%;img-fit:contain"></td>
</c:if>
<td>${aList.firstName} ${aList.lastName}</td>
<td>${aList.biography}</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<c:forEach var="bookClub" items="${bookClubs}">
<tr>
<td><img src="${bookClub.profileUrl}" height="50" width="50" alt="${bookClub.name}"></td>
<td><a href="bookClub.do?id=${bookClub.id}">${bookClub.name}</a></td>
<td><a href="showBookClub.do?id=${bookClub.id}">${bookClub.name}</a></td>
<td>${bookClub.aboutClub}</td>
<td>${bookClub.owner.username}</td>
<td>${bookClub.maxMembers}</td>
Expand Down
1 change: 1 addition & 0 deletions ClubIndex/src/main/webapp/WEB-INF/includes/nav.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<td><a href="getAuthor.do" class="btn btn-dark">Authors</a></td>
<td><a href="showUserRL.do" class="btn btn-dark">ReadingList</a></td>
<td><a href="bookClubSearch.do" class="btn btn-dark">Book Club Search</a></td>
<!-- <td><a href="userSearch.do" class="btn btn-dark">User Search</a></td> -->
<c:choose>
<c:when test="${not empty user}">
<td><a href="account.do" class="btn btn-dark">Account view</a></td>
Expand Down
30 changes: 30 additions & 0 deletions ClubIndex/src/main/webapp/WEB-INF/user/userLists.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../includes/header.jsp" />
</head>
<body>
<jsp:include page="../includes/nav.jsp" />
<table>
<tr>
<th>Profile Pic</th>
<th>Name</th>
<th>About Me</th>
<th>First Name</th>
</tr>
<c:forEach var="user" items="${users}">
<tr>
<td><img src="${user.profileUrl}" height="50" width="50" alt="${user.username}"></td>
<td><a href="userProfile.do?id=${user.id}">${user.username}</a></td>
<td>${user.aboutMe}</td>
<td>${user.firstName}</td>
</tr>
</c:forEach>
</table>
<a href="bookClubSearch.do" class="btn btn-primary">Not what you're looking for?</a>
<jsp:include page="../includes/footer.jsp"/>
</body>
</html>
12 changes: 8 additions & 4 deletions ClubIndex/src/main/webapp/WEB-INF/user/userProfile.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
<body>
<jsp:include page="../includes/nav.jsp"/>
<div class="container">
<div class="container">
<div class="banner">
<h1>${user.username}</h1>
</div>
<div class="row">
<div class="col-6">
<div class="col-8">
<table>
<thead>
<tr>
Expand Down Expand Up @@ -39,10 +43,10 @@
</table>
</div>
<div class="col-4">
<img src="${user.profileUrl}" style="height:300px;width:250px;height:100%;width:100%;img-fit:contain;border:4px solid black;padding:12px" alt="ImageNotFound"/>
<img src="${user.profileUrl}" style="height:300px;width:250px;img-fit:cover;border:4px solid black;padding:12px" alt="ImageNotFound"/>
</div>
<p>${user.username}<p>
<p>${user.aboutMe}</p>
<%-- <p>${user.username}<p>
<p>${user.aboutMe}</p> --%>
</div>
</div>
<div class="row">
Expand Down
31 changes: 31 additions & 0 deletions ClubIndex/src/main/webapp/WEB-INF/user/userSearch.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>

<jsp:include page="../includes/header.jsp" />
</head>
<body>
<jsp:include page="../includes/nav.jsp" />
<div class="container">
<div class="col">
<div class="input-group mb-3">
<form action="getUser.do">
<input type="text" name="userSearch" class="form-control"
aria-describedby="basic-addon2">
<input type="radio" id="username" name="searchType" value="1">
<label for="username">Find Friends By Username</label>
<input type="radio" id="firstName" name="searchType" value="2">
<label for="firstName">Find Friends by First Name</label>
<input type="radio" id="lastName" name="searchType" value="3">
<label for="lastName">Find Friends by Last Name</label>

<input type="submit" value="Search" />
</form>
</div>
</div>
<jsp:include page="../includes/footer.jsp"/>
</body>
</html>

0 comments on commit 7073ce2

Please sign in to comment.