feat: add filter
This commit is contained in:
parent
e868169f3d
commit
73b6f86aab
@ -1,48 +1,116 @@
|
|||||||
<%@ page contentType="text/html;charset=UTF-8" %>
|
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Charm Profiles</title>
|
<title>Charm Profiles</title>
|
||||||
<%@ include file="style.html" %>
|
<%@ include file="style.html" %>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<%@ include file="header.jsp" %>
|
<%@ include file="header.jsp" %>
|
||||||
<div>
|
<div>
|
||||||
<table>
|
<form action="/profiles" method="get">
|
||||||
<tr>
|
<table>
|
||||||
<td><h3>id</h3></td>
|
<tr class="hiddenRow">
|
||||||
<td><h3>${requestScope.wordBundle.getWord("email")}</h3></td>
|
<td>
|
||||||
<td><h3>${requestScope.wordBundle.getWord("name")}</h3></td>
|
<input type="image" src="content/app/img/filter.png" width="75" alt="submit" class="icon"/>
|
||||||
<td><h3>${requestScope.wordBundle.getWord("surname")}</h3></td>
|
</td>
|
||||||
<td><h3>${requestScope.wordBundle.getWord("age")}</h3></td>
|
<td>
|
||||||
<td><h3>${requestScope.wordBundle.getWord("status")}</h3></td>
|
<table>
|
||||||
</tr>
|
<tr class="hiddenRow">
|
||||||
<c:forEach var="profile" items="${requestScope.profiles}">
|
<td>${wordBundle.getWord("email")}</td>
|
||||||
<tr>
|
<td><input type="text" name="emailStartWith" value="${filter.emailStartWith}"
|
||||||
<td><h4>${profile.id}</h4></td>
|
class="filterInput"></td>
|
||||||
<td><h4>${profile.email}</h4></td>
|
</tr>
|
||||||
<td><h4>${profile.name}</h4></td>
|
<tr class="hiddenRow">
|
||||||
<td><h4>${profile.surname}</h4></td>
|
<td>${wordBundle.getWord("name")}</td>
|
||||||
<td><h4>${profile.age}</h4></td>
|
<td><input type="text" name="nameStartWith" value="${filter.nameStartWith}"
|
||||||
<td>
|
class="filterInput"></td>
|
||||||
<form action="/profile" method="post">
|
</tr>
|
||||||
<input type="hidden" name="_method" value="put"/>
|
</table>
|
||||||
<input type="hidden" name="id" value="${profile.id}">
|
</td>
|
||||||
<select name="status">
|
<td>
|
||||||
<option value="${profile.status}" selected hidden>
|
<table>
|
||||||
${requestScope.wordBundle.getWord(profile.status)}
|
<tr class="hiddenRow">
|
||||||
</option>
|
<td>${wordBundle.getWord("surname")}</td>
|
||||||
<c:forEach var="status" items="${applicationScope.statuses}">
|
<td><input type="text" name="surnameStartWith" value="${filter.surnameStartWith}"
|
||||||
<option value="${status}">${requestScope.wordBundle.getWord(status)}</option>
|
class="filterInput"></td>
|
||||||
</c:forEach>
|
</tr>
|
||||||
</select>
|
<tr class="hiddenRow">
|
||||||
<button type="submit">${requestScope.wordBundle.getWord("save")}</button>
|
<td>${wordBundle.getWord("status")}</td>
|
||||||
</form>
|
<td>
|
||||||
</td>
|
<select name="status" class="filterInput">
|
||||||
</tr>
|
<option selected value></option>
|
||||||
</c:forEach>
|
<c:forEach var="statusVar" items="${applicationScope.statuses}">
|
||||||
</table>
|
<c:if test="${statusVar == filter.status}">
|
||||||
</div>
|
<option value="${statusVar}" selected>
|
||||||
<%@ include file="footer.jsp" %>
|
${wordBundle.getWord(statusVar)}
|
||||||
</body>
|
</option>
|
||||||
|
</c:if>
|
||||||
|
<c:if test="${statusVar != filter.status}">
|
||||||
|
<option value="${statusVar}">${wordBundle.getWord(statusVar)}
|
||||||
|
</option>
|
||||||
|
</c:if>
|
||||||
|
</c:forEach>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<table>
|
||||||
|
<tr class="hiddenRow">
|
||||||
|
<td>${wordBundle.getWord("age")}</td>
|
||||||
|
<td><input type="number" name="gteAge" min="18" max="100" value="${filter.gteAge}"
|
||||||
|
style="width: 50px;"></td>
|
||||||
|
<td>-</td>
|
||||||
|
<td><input type="number" name="ltAge" min="18" max="100" value="${filter.ltAge}"
|
||||||
|
style="width: 50px;"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><h3>id</h3></td>
|
||||||
|
<td><h3>${wordBundle.getWord("email")}</h3></td>
|
||||||
|
<td><h3>${wordBundle.getWord("name")}</h3></td>
|
||||||
|
<td><h3>${wordBundle.getWord("surname")}</h3></td>
|
||||||
|
<td><h3>${wordBundle.getWord("age")}</h3></td>
|
||||||
|
<td><h3>${wordBundle.getWord("status")}</h3></td>
|
||||||
|
</tr>
|
||||||
|
<c:forEach var="profile" items="${profiles}">
|
||||||
|
<tr>
|
||||||
|
<td><h4>${profile.id}</h4></td>
|
||||||
|
<td><h4>${profile.email}</h4></td>
|
||||||
|
<td><h4>${profile.name}</h4></td>
|
||||||
|
<td><h4>${profile.surname}</h4></td>
|
||||||
|
<td><h4>${profile.age}</h4></td>
|
||||||
|
<td>
|
||||||
|
<form action="/profile" method="post" enctype="multipart/form-data">
|
||||||
|
<input type="hidden" name="_method" value="put"/>
|
||||||
|
<input type="hidden" name="id" value="${profile.id}">
|
||||||
|
<select name="status" class="filterInput">
|
||||||
|
<c:forEach var="statusVar" items="${applicationScope.statuses}">
|
||||||
|
<c:if test="${statusVar == profile.status}">
|
||||||
|
<option value="${statusVar}" selected>
|
||||||
|
${wordBundle.getWord(statusVar)}
|
||||||
|
</option>
|
||||||
|
</c:if>
|
||||||
|
<c:if test="${statusVar != profile.status}">
|
||||||
|
<option value="${statusVar}">${wordBundle.getWord(statusVar)}
|
||||||
|
</option>
|
||||||
|
</c:if>
|
||||||
|
</c:forEach>
|
||||||
|
</select>
|
||||||
|
<button type="submit">${wordBundle.getWord("save")}</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</c:forEach>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<%@ include file="footer.jsp" %>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -10,6 +10,7 @@ import jakarta.servlet.annotation.WebServlet;
|
|||||||
import jakarta.servlet.http.HttpServlet;
|
import jakarta.servlet.http.HttpServlet;
|
||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import ru.charm.back.dto.ProfileFilter;
|
import ru.charm.back.dto.ProfileFilter;
|
||||||
import ru.charm.back.dto.ProfileGetDto;
|
import ru.charm.back.dto.ProfileGetDto;
|
||||||
import ru.charm.back.dto.ProfileUpdateDto;
|
import ru.charm.back.dto.ProfileUpdateDto;
|
||||||
@ -22,9 +23,11 @@ import java.io.OutputStream;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||||
|
import static ru.charm.back.utils.UrlUtils.PROFILE_URL;
|
||||||
|
|
||||||
@WebServlet("/profile/*")
|
@WebServlet(PROFILE_URL + "/*")
|
||||||
@MultipartConfig
|
@MultipartConfig
|
||||||
|
@Slf4j
|
||||||
public class ProfileController extends HttpServlet {
|
public class ProfileController extends HttpServlet {
|
||||||
private final ProfileService service = ProfileService.getInstance();
|
private final ProfileService service = ProfileService.getInstance();
|
||||||
|
|
||||||
|
|||||||
33
src/ru/charm/back/controller/ProfilesController.java
Normal file
33
src/ru/charm/back/controller/ProfilesController.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package ru.charm.back.controller;
|
||||||
|
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import ru.charm.back.dto.ProfileFilter;
|
||||||
|
import ru.charm.back.mapper.RequestToProfileFilterMapper;
|
||||||
|
import ru.charm.back.service.ProfileService;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static ru.charm.back.utils.UrlUtils.PROFILES_URL;
|
||||||
|
import static ru.charm.back.utils.UrlUtils.getJspPath;
|
||||||
|
|
||||||
|
|
||||||
|
@WebServlet(PROFILES_URL)
|
||||||
|
@Slf4j
|
||||||
|
public class ProfilesController extends HttpServlet {
|
||||||
|
private final ProfileService service = ProfileService.getInstance();
|
||||||
|
private final RequestToProfileFilterMapper requestToProfileFilterMapper = RequestToProfileFilterMapper.getInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
|
||||||
|
ProfileFilter filter = requestToProfileFilterMapper.map(req);
|
||||||
|
req.setAttribute("profiles", service.findAll(filter));
|
||||||
|
req.setAttribute("filter", filter);
|
||||||
|
req.getRequestDispatcher(getJspPath(PROFILES_URL)).forward(req, res);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,15 +8,19 @@ import java.util.Set;
|
|||||||
public class UrlUtils {
|
public class UrlUtils {
|
||||||
|
|
||||||
public static final String PROFILE_URL = "/profile";
|
public static final String PROFILE_URL = "/profile";
|
||||||
|
public static final String PROFILES_URL = "/profiles";
|
||||||
public static final String CREDENTIALS_URL = "/credentials";
|
public static final String CREDENTIALS_URL = "/credentials";
|
||||||
public static final String LOGIN_URL = "/login";
|
public static final String LOGIN_URL = "/login";
|
||||||
public static final String LOGOUT_URL = "/logout";
|
public static final String LOGOUT_URL = "/logout";
|
||||||
public static final String REGISTRATION_URL = "/registration";
|
public static final String REGISTRATION_URL = "/registration";
|
||||||
public static final String LANG_URL = "/lang";
|
public static final String LANG_URL = "/lang";
|
||||||
public static final String CONTENT_URL = "/content";
|
public static final String CONTENT_URL = "/content";
|
||||||
public static final String BASE_CONTENT_PATH = "/Users/andrey.s.eliseev/Downloads";
|
public static final String PDF_URL = "/pdf";
|
||||||
|
public static final String REST_URL = "/api/v1";
|
||||||
|
public static final String LOGIN_REST_URL = REST_URL + LOGIN_URL;
|
||||||
|
public static final String BASE_CONTENT_PATH = ConfigFileUtils.get("app.base-content-path");
|
||||||
|
|
||||||
public static final Set<String> PRIVATE_PATHS = Set.of(PROFILE_URL, CREDENTIALS_URL);
|
public static final Set<String> PRIVATE_PATHS = Set.of(PROFILE_URL, PROFILES_URL, CREDENTIALS_URL, REST_URL);
|
||||||
|
|
||||||
public static final Set<String> ENTRY_PATHS = Set.of(LOGIN_URL, REGISTRATION_URL);
|
public static final Set<String> ENTRY_PATHS = Set.of(LOGIN_URL, REGISTRATION_URL);
|
||||||
|
|
||||||
@ -24,9 +28,6 @@ public class UrlUtils {
|
|||||||
return "/WEB-INF/jsp" + url + ".jsp";
|
return "/WEB-INF/jsp" + url + ".jsp";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String REST_URL = "/api/v1";
|
|
||||||
public static final String LOGIN_REST_URL = REST_URL + LOGIN_URL;
|
|
||||||
|
|
||||||
public static String getProfilePhotoPath(Long id, String fileName) {
|
public static String getProfilePhotoPath(Long id, String fileName) {
|
||||||
return "/profiles/" + id + "/" + fileName;
|
return "/profiles/" + id + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user