LabWork04: Работа готова (Сдана)
This commit is contained in:
parent
2918fee687
commit
8348a9bf31
@ -1,5 +1,41 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="ms-5">
|
<div class="ms-5">
|
||||||
|
<div class="col-7">
|
||||||
|
<div class="row">
|
||||||
|
<input type="text" v-bind:id="'searchString'" class="col-4"/>
|
||||||
|
<button type="button" v-on:click="getSearchResult()" class="button col-2 secondary outline">Поиск</button>
|
||||||
|
<button type="button" v-on:click="searchMode = -1;" class="button col-2 secondary outline">Отмена</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="!(searchMode == -1)">
|
||||||
|
<div v-if="!(searchResults.length == 0)" class="row">
|
||||||
|
<div class="col-5">
|
||||||
|
<div class="row mb-5 card" v-for="result in searchResults">
|
||||||
|
<div class="col">
|
||||||
|
|
||||||
|
<div v-if="result['title'] == null">
|
||||||
|
<div class="row is-left mt-2">
|
||||||
|
<span class="h3">Комментарий</span>
|
||||||
|
<!-- <p class="text-primary h2">Пользователь: {{ result['customerName'] }}</p> -->
|
||||||
|
<span class="h3">Контент: {{ result['content'] }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div class="row is-left mt-2">
|
||||||
|
<span class="h3">Пост</span>
|
||||||
|
<!-- <p class="text-primary h2">Пользователь: {{ result['customerName'] }}</p> -->
|
||||||
|
<span class="h3">Оглавление: {{ result['title'] }}</span>
|
||||||
|
<span class="h3">Контент: {{ result['content'] }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="searchMode == -1">
|
||||||
<p class='h3 m-3'>Посты</p>
|
<p class='h3 m-3'>Посты</p>
|
||||||
|
|
||||||
<div class="row" v-if="currentCustomerId != -1">
|
<div class="row" v-if="currentCustomerId != -1">
|
||||||
@ -65,6 +101,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
@ -118,6 +155,7 @@ import axios from 'axios'
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
searchResults: [],
|
||||||
customers: [],
|
customers: [],
|
||||||
selectedCustomerId: 0,
|
selectedCustomerId: 0,
|
||||||
currentCustomer: {},
|
currentCustomer: {},
|
||||||
@ -129,9 +167,27 @@ export default {
|
|||||||
postContentModal: '',
|
postContentModal: '',
|
||||||
selectedCommentId: 0,
|
selectedCommentId: 0,
|
||||||
currentCustomerId: -1,
|
currentCustomerId: -1,
|
||||||
|
searchMode: -1,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async getSearchResult(){
|
||||||
|
const content = document.getElementById("searchString").value
|
||||||
|
if (content != ''){
|
||||||
|
this.searchMode = 0;
|
||||||
|
this.searchResults = [];
|
||||||
|
const responseSearch = await axios.post('http://localhost:8080/search?searchStr=' + content);
|
||||||
|
responseSearch.data.forEach(element => {
|
||||||
|
this.searchResults.push(element);
|
||||||
|
console.log(element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
this.searchMode = -1;
|
||||||
|
this.refreshList();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
selectedCustomerContainsComment(comment) {
|
selectedCustomerContainsComment(comment) {
|
||||||
var customer = this.customers.find(element => element['id'] == this.currentCustomerId);
|
var customer = this.customers.find(element => element['id'] == this.currentCustomerId);
|
||||||
console.log(customer);
|
console.log(customer);
|
||||||
|
@ -1,11 +1,17 @@
|
|||||||
package ru.ulstu.is.labwork.Lab4.controller;
|
package ru.ulstu.is.labwork.Lab4.controller;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.DTO.CommentDto;
|
||||||
import ru.ulstu.is.labwork.Lab4.DTO.PostDto;
|
import ru.ulstu.is.labwork.Lab4.DTO.PostDto;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.model.Comment;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.model.Post;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.services.CommentService;
|
||||||
import ru.ulstu.is.labwork.Lab4.services.CustomerService;
|
import ru.ulstu.is.labwork.Lab4.services.CustomerService;
|
||||||
import ru.ulstu.is.labwork.Lab4.services.PostService;
|
import ru.ulstu.is.labwork.Lab4.services.PostService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/post")
|
@RequestMapping("/post")
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package ru.ulstu.is.labwork.Lab4.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.DTO.CommentDto;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.DTO.PostDto;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.services.CommentService;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.services.PostService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/search")
|
||||||
|
public class SearchController {
|
||||||
|
private final CommentService commentService;
|
||||||
|
private final PostService postService;
|
||||||
|
|
||||||
|
public SearchController(PostService postService, CommentService commentService){
|
||||||
|
this.commentService = commentService;
|
||||||
|
this.postService = postService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public List<Object> getResult(@RequestParam("searchStr") String searchStr) {
|
||||||
|
List<Object> result = new ArrayList<>();
|
||||||
|
result.addAll(commentService.findFilteredComments(searchStr).stream()
|
||||||
|
.map(CommentDto::new)
|
||||||
|
.toList());
|
||||||
|
result.addAll(postService.findFilteredPosts(searchStr).stream()
|
||||||
|
.map(PostDto::new)
|
||||||
|
.toList());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -3,5 +3,8 @@ package ru.ulstu.is.labwork.Lab4.repositories;
|
|||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import ru.ulstu.is.labwork.Lab4.model.Comment;
|
import ru.ulstu.is.labwork.Lab4.model.Comment;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface CommentRepository extends JpaRepository<Comment, Long> {
|
public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||||
|
List<Comment> findByContentLikeIgnoreCase(String text);
|
||||||
}
|
}
|
@ -1,7 +1,11 @@
|
|||||||
package ru.ulstu.is.labwork.Lab4.repositories;
|
package ru.ulstu.is.labwork.Lab4.repositories;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import ru.ulstu.is.labwork.Lab4.model.Post;
|
import ru.ulstu.is.labwork.Lab4.model.Post;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface PostRepository extends JpaRepository<Post, Long> {
|
public interface PostRepository extends JpaRepository<Post, Long> {
|
||||||
|
List<Post> findByContentLikeIgnoreCase(String text);
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,13 @@ public class CommentService {
|
|||||||
public CommentService(CommentRepository commentRepository) {
|
public CommentService(CommentRepository commentRepository) {
|
||||||
this.commentRepository = commentRepository;
|
this.commentRepository = commentRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public List<Comment> findFilteredComments(String filter) {
|
||||||
|
return commentRepository.findByContentLikeIgnoreCase("%" + filter + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Comment findComment(Long id) {
|
public Comment findComment(Long id) {
|
||||||
final Optional<Comment> comment = commentRepository.findById(id);
|
final Optional<Comment> comment = commentRepository.findById(id);
|
||||||
|
@ -2,10 +2,12 @@ package ru.ulstu.is.labwork.Lab4.services;
|
|||||||
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.model.Comment;
|
||||||
import ru.ulstu.is.labwork.Lab4.model.Customer;
|
import ru.ulstu.is.labwork.Lab4.model.Customer;
|
||||||
import ru.ulstu.is.labwork.Lab4.model.Post;
|
import ru.ulstu.is.labwork.Lab4.model.Post;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
import ru.ulstu.is.labwork.Lab4.repositories.CommentRepository;
|
||||||
import ru.ulstu.is.labwork.Lab4.repositories.PostRepository;
|
import ru.ulstu.is.labwork.Lab4.repositories.PostRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -18,6 +20,10 @@ public class PostService {
|
|||||||
public PostService(PostRepository postRepository) {
|
public PostService(PostRepository postRepository) {
|
||||||
this.postRepository = postRepository;
|
this.postRepository = postRepository;
|
||||||
}
|
}
|
||||||
|
@Transactional
|
||||||
|
public List<Post> findFilteredPosts(String filter) {
|
||||||
|
return postRepository.findByContentLikeIgnoreCase("%" + filter + "%");
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Post findPost(Long id) {
|
public Post findPost(Long id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user