feat: add filter
This commit is contained in:
parent
e868169f3d
commit
73b6f86aab
@ -1,23 +1,86 @@
|
||||
<%@ page contentType="text/html;charset=UTF-8" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<head>
|
||||
<title>Charm Profiles</title>
|
||||
<%@ include file="style.html" %>
|
||||
</head>
|
||||
<body>
|
||||
<%@ include file="header.jsp" %>
|
||||
<div>
|
||||
</head>
|
||||
<body>
|
||||
<%@ include file="header.jsp" %>
|
||||
<div>
|
||||
<form action="/profiles" method="get">
|
||||
<table>
|
||||
<tr class="hiddenRow">
|
||||
<td>
|
||||
<input type="image" src="content/app/img/filter.png" width="75" alt="submit" class="icon"/>
|
||||
</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr class="hiddenRow">
|
||||
<td>${wordBundle.getWord("email")}</td>
|
||||
<td><input type="text" name="emailStartWith" value="${filter.emailStartWith}"
|
||||
class="filterInput"></td>
|
||||
</tr>
|
||||
<tr class="hiddenRow">
|
||||
<td>${wordBundle.getWord("name")}</td>
|
||||
<td><input type="text" name="nameStartWith" value="${filter.nameStartWith}"
|
||||
class="filterInput"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
<td>
|
||||
<table>
|
||||
<tr class="hiddenRow">
|
||||
<td>${wordBundle.getWord("surname")}</td>
|
||||
<td><input type="text" name="surnameStartWith" value="${filter.surnameStartWith}"
|
||||
class="filterInput"></td>
|
||||
</tr>
|
||||
<tr class="hiddenRow">
|
||||
<td>${wordBundle.getWord("status")}</td>
|
||||
<td>
|
||||
<select name="status" class="filterInput">
|
||||
<option selected value></option>
|
||||
<c:forEach var="statusVar" items="${applicationScope.statuses}">
|
||||
<c:if test="${statusVar == filter.status}">
|
||||
<option value="${statusVar}" selected>
|
||||
${wordBundle.getWord(statusVar)}
|
||||
</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>${requestScope.wordBundle.getWord("email")}</h3></td>
|
||||
<td><h3>${requestScope.wordBundle.getWord("name")}</h3></td>
|
||||
<td><h3>${requestScope.wordBundle.getWord("surname")}</h3></td>
|
||||
<td><h3>${requestScope.wordBundle.getWord("age")}</h3></td>
|
||||
<td><h3>${requestScope.wordBundle.getWord("status")}</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="${requestScope.profiles}">
|
||||
<c:forEach var="profile" items="${profiles}">
|
||||
<tr>
|
||||
<td><h4>${profile.id}</h4></td>
|
||||
<td><h4>${profile.email}</h4></td>
|
||||
@ -25,24 +88,29 @@
|
||||
<td><h4>${profile.surname}</h4></td>
|
||||
<td><h4>${profile.age}</h4></td>
|
||||
<td>
|
||||
<form action="/profile" method="post">
|
||||
<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">
|
||||
<option value="${profile.status}" selected hidden>
|
||||
${requestScope.wordBundle.getWord(profile.status)}
|
||||
<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:forEach var="status" items="${applicationScope.statuses}">
|
||||
<option value="${status}">${requestScope.wordBundle.getWord(status)}</option>
|
||||
</c:if>
|
||||
<c:if test="${statusVar != profile.status}">
|
||||
<option value="${statusVar}">${wordBundle.getWord(statusVar)}
|
||||
</option>
|
||||
</c:if>
|
||||
</c:forEach>
|
||||
</select>
|
||||
<button type="submit">${requestScope.wordBundle.getWord("save")}</button>
|
||||
<button type="submit">${wordBundle.getWord("save")}</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</c:forEach>
|
||||
</table>
|
||||
</div>
|
||||
<%@ include file="footer.jsp" %>
|
||||
</body>
|
||||
</div>
|
||||
<%@ include file="footer.jsp" %>
|
||||
</body>
|
||||
</html>
|
||||
@ -10,6 +10,7 @@ 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.dto.ProfileGetDto;
|
||||
import ru.charm.back.dto.ProfileUpdateDto;
|
||||
@ -22,9 +23,11 @@ import java.io.OutputStream;
|
||||
import java.util.Optional;
|
||||
|
||||
import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND;
|
||||
import static ru.charm.back.utils.UrlUtils.PROFILE_URL;
|
||||
|
||||
@WebServlet("/profile/*")
|
||||
@WebServlet(PROFILE_URL + "/*")
|
||||
@MultipartConfig
|
||||
@Slf4j
|
||||
public class ProfileController extends HttpServlet {
|
||||
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 static final String PROFILE_URL = "/profile";
|
||||
public static final String PROFILES_URL = "/profiles";
|
||||
public static final String CREDENTIALS_URL = "/credentials";
|
||||
public static final String LOGIN_URL = "/login";
|
||||
public static final String LOGOUT_URL = "/logout";
|
||||
public static final String REGISTRATION_URL = "/registration";
|
||||
public static final String LANG_URL = "/lang";
|
||||
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);
|
||||
|
||||
@ -24,9 +28,6 @@ public class UrlUtils {
|
||||
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) {
|
||||
return "/profiles/" + id + "/" + fileName;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user