Реализовала поиск на странице всех заведений.

Добавила стили
parent 677a4873
......@@ -24,6 +24,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.security.Principal;
import java.util.stream.Collectors;
@Controller
@RequiredArgsConstructor
......@@ -52,6 +53,16 @@ public class PlaceController {
return "place/places";
}
@RequestMapping(path = "/", params = "search", method = RequestMethod.GET)
public String all(@RequestParam String search, Pageable pageable, HttpServletRequest uriBuilder,
Model model){
Page<Place> places = service.filter(pageable, search);
model.addAttribute("places", places);
String uri = uriBuilder.getRequestURI();
PageableView.constructPageable(places, propertiesService.getDefaultPageSize(), model, uri);
return "place/places";
}
@PreAuthorize("hasAuthority('USER') || hasAuthority('ADMIN')")
@GetMapping("/add")
public String add(){
......@@ -121,9 +132,9 @@ public class PlaceController {
}
@PreAuthorize("hasAuthority('ADMIN')")
@PostMapping("/{id}/review/{reviewId}")
public String deletePhoto(@PathVariable Integer id, @PathVariable Integer reviewId){
placePhotoService.delete(reviewId);
@PostMapping("/{id}/photo/{photoId}")
public String deletePhoto(@PathVariable Integer id, @PathVariable Integer photoId){
placePhotoService.delete(photoId);
return "redirect:/" + id;
}
......
......@@ -10,4 +10,5 @@ import org.springframework.stereotype.Repository;
public interface PlaceRepository extends JpaRepository<Place, Integer> {
boolean existsByName(String name);
Page<Place> findAll(Pageable pageable);
Page<Place> findAllByNameContains(Pageable pageable, String name);
}
......@@ -23,11 +23,14 @@ public class PlaceService {
return new ResourceNotFoundException("Завдеение", id);
});
}
public Page<Place> all(Pageable pageable){
return repository.findAll(pageable);
}
public Page<Place> filter(Pageable pageable, String name){
return repository.findAllByNameContains(pageable, name);
}
public boolean isUnique(String name){
return repository.existsByName(name);
}
......
......@@ -2,3 +2,4 @@ spring.datasource.url= jdbc:mysql://localhost:3306/final_exam
spring.datasource.username=root
spring.datasource.password=12345
server.port=8002
spring.data.web.pageable.default-page-size=3
......@@ -63,6 +63,8 @@ label{
display: flex;
flex-direction: column;
max-width: 300px;
border: 1px grey solid;
margin: 7px;
}
.item img{
width: 70%;
......
......@@ -2,6 +2,10 @@
<@main.renderWith title="Заведения">
<h1>Заведения</h1>
<form action="/">
<input type="text" name="search" placeholder="поиск">
<button type="submit">Искать</button>
</form>
<div class="items">
<#if places?? && places?size != 0>
<#list places as c>
......@@ -10,15 +14,17 @@
<a href="/${c.id}">
<img src="/file/${c.placePhoto.filePath}" alt="Изображение">
<p class="info">Наименование ${c.name}</p>
</a>
<p class="info">Создал ${c.user.login}</p>
<p class="info">Рейтинг ${c.rating}</p>
<p class="info">Отзывов ${c.reviews?size}</p>
<p class="info">Фото ${c.photos?size}</p>
</a>
</div>
</#if>
</#list>
<#include "../pagination.ftlh">
</div>
<#include "../pagination.ftlh">
<div>
<#else>
<p>Заведений нет</p>
<a href="/add">Добавить заведение</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment