Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
final_exam_lyalya_aldamzharova
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Алдамжарова Ляйла
final_exam_lyalya_aldamzharova
Commits
9b88f2c9
Commit
9b88f2c9
authored
Nov 06, 2021
by
Алдамжарова Ляйла
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Реализовала поиск на странице всех заведений.
Добавила стили
parent
677a4873
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
30 additions
and
6 deletions
+30
-6
PlaceController.java
.../com/example/final_exam_l/controller/PlaceController.java
+14
-3
PlaceRepository.java
.../com/example/final_exam_l/repository/PlaceRepository.java
+1
-0
PlaceService.java
...n/java/com/example/final_exam_l/service/PlaceService.java
+4
-1
application.properties
src/main/resources/application.properties
+1
-0
main.css
src/main/resources/static/css/main.css
+2
-0
places.ftlh
src/main/resources/templates/place/places.ftlh
+8
-2
No files found.
src/main/java/com/example/final_exam_l/controller/PlaceController.java
View file @
9b88f2c9
...
...
@@ -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/{review
Id}"
)
public
String
deletePhoto
(
@PathVariable
Integer
id
,
@PathVariable
Integer
review
Id
){
placePhotoService
.
delete
(
review
Id
);
@PostMapping
(
"/{id}/
photo/{photo
Id}"
)
public
String
deletePhoto
(
@PathVariable
Integer
id
,
@PathVariable
Integer
photo
Id
){
placePhotoService
.
delete
(
photo
Id
);
return
"redirect:/"
+
id
;
}
...
...
src/main/java/com/example/final_exam_l/repository/PlaceRepository.java
View file @
9b88f2c9
...
...
@@ -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
);
}
src/main/java/com/example/final_exam_l/service/PlaceService.java
View file @
9b88f2c9
...
...
@@ -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
);
}
...
...
src/main/resources/application.properties
View file @
9b88f2c9
...
...
@@ -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
src/main/resources/static/css/main.css
View file @
9b88f2c9
...
...
@@ -63,6 +63,8 @@ label{
display
:
flex
;
flex-direction
:
column
;
max-width
:
300px
;
border
:
1px
grey
solid
;
margin
:
7px
;
}
.item
img
{
width
:
70%
;
...
...
src/main/resources/templates/place/places.ftlh
View file @
9b88f2c9
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment