LabWork04: Работа готова (Сдана)
This commit is contained in:
parent
2918fee687
commit
8348a9bf31
@ -1,65 +1,102 @@
|
||||
<template>
|
||||
<div class="ms-5">
|
||||
<p class='h3 m-3'>Посты</p>
|
||||
<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 class="row" v-if="currentCustomerId != -1">
|
||||
<div class="col-7">
|
||||
<div class="row is-left">
|
||||
<p class="col-2 is-left mb-2">Заголовок:</p>
|
||||
<input type="text" class="col-5" v-model="titleModal"/>
|
||||
</div>
|
||||
<div class="row is-left">
|
||||
<p class="col-2 is-left mb-2">Текст:</p>
|
||||
<textarea type="textarea" class="col-5" v-model="postContentModal"/>
|
||||
</div>
|
||||
<div class="row is-left">
|
||||
<button type='button' class="button btn-primary col-7" v-on:click='createPost'>
|
||||
Опубликовать
|
||||
</button>
|
||||
<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="!(posts.length == 0)" class="row">
|
||||
<div class="col-5">
|
||||
<div class="row mb-5 card" v-for="post in posts">
|
||||
<div class="col">
|
||||
<div class="row is-left my-3">
|
||||
<p class="h2"><router-link v-bind:to="'/customers/' + post['customerId']" class="text-primary">{{ post['customerName'] }}</router-link></p>
|
||||
</div>
|
||||
<div v-if="searchMode == -1">
|
||||
<p class='h3 m-3'>Посты</p>
|
||||
|
||||
<div class="row text-left">
|
||||
<span class="h2">{{ post['title'] }}</span>
|
||||
<span class="h3">{{ post['content'] }}</span>
|
||||
</div>
|
||||
<div class="row" v-if="currentCustomerId != -1">
|
||||
<div class="col-7">
|
||||
<div class="row is-left">
|
||||
<p class="col-2 is-left mb-2">Заголовок:</p>
|
||||
<input type="text" class="col-5" v-model="titleModal"/>
|
||||
</div>
|
||||
<div class="row is-left">
|
||||
<p class="col-2 is-left mb-2">Текст:</p>
|
||||
<textarea type="textarea" class="col-5" v-model="postContentModal"/>
|
||||
</div>
|
||||
<div class="row is-left">
|
||||
<button type='button' class="button btn-primary col-7" v-on:click='createPost'>
|
||||
Опубликовать
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div v-if="!(post['comments'].length == 0)">
|
||||
<p class="row h3 is-left my-3">Комментарии:</p>
|
||||
<div v-if="!(posts.length == 0)" class="row">
|
||||
<div class="col-5">
|
||||
<div class="row mb-5 card" v-for="post in posts">
|
||||
<div class="col">
|
||||
<div class="row is-left my-3">
|
||||
<p class="h2"><router-link v-bind:to="'/customers/' + post['customerId']" class="text-primary">{{ post['customerName'] }}</router-link></p>
|
||||
</div>
|
||||
|
||||
<div class="row text-left mb-4 card" v-for="comment in post['comments']">
|
||||
<div class="row is-left">
|
||||
<span class="h2"><router-link v-bind:to="'/customers/' + post['customerId']" class="text-primary">{{ post['customerName'] }}</router-link></span>
|
||||
<span class="h3">{{ comment['content'] }}</span>
|
||||
<div class="row text-left">
|
||||
<span class="h2">{{ post['title'] }}</span>
|
||||
<span class="h3">{{ post['content'] }}</span>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div v-if="!(post['comments'].length == 0)">
|
||||
<p class="row h3 is-left my-3">Комментарии:</p>
|
||||
|
||||
<div class="row text-left mb-4 card" v-for="comment in post['comments']">
|
||||
<div class="row is-left">
|
||||
<span class="h2"><router-link v-bind:to="'/customers/' + post['customerId']" class="text-primary">{{ post['customerName'] }}</router-link></span>
|
||||
<span class="h3">{{ comment['content'] }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedCustomerContainsComment(comment) == true" class="row mt-3">
|
||||
<button v-on:click="selectedCommentId = comment['id']; selectedPostTitle = post['title']" class="button primary outline col" data-bs-toggle="modal" data-bs-target="#commentEdit">Изменить</button>
|
||||
<button v-on:click="deleteComment(comment['id'])" class="button error col">Удалить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedCustomerContainsComment(comment) == true" class="row mt-3">
|
||||
<button v-on:click="selectedCommentId = comment['id']; selectedPostTitle = post['title']" class="button primary outline col" data-bs-toggle="modal" data-bs-target="#commentEdit">Изменить</button>
|
||||
<button v-on:click="deleteComment(comment['id'])" class="button error col">Удалить</button>
|
||||
</div>
|
||||
<div class="row" v-if="currentCustomerId != -1">
|
||||
<input type="text" v-bind:id="'post-comment-' + post['id']" class="col-7"/>
|
||||
<button type="button" v-on:click="selectedPostId = post['id']; selectedPostTitle = post['title']; createComment()" class="button col-5 secondary outline">Комментировать</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" v-if="currentCustomerId != -1">
|
||||
<input type="text" v-bind:id="'post-comment-' + post['id']" class="col-7"/>
|
||||
<button type="button" v-on:click="selectedPostId = post['id']; selectedPostTitle = post['title']; createComment()" class="button col-5 secondary outline">Комментировать</button>
|
||||
<div class="row" v-if="post['customerId'] == currentCustomerId">
|
||||
<button type="button" v-on:click="deletePost(post['id'])" class="col button dark outline">Удалить пост</button>
|
||||
<button type="button" v-on:click="selectedPostId = post['id']" class="col button primary outline" data-bs-toggle="modal" data-bs-target="#postEdit">Изменить пост</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" v-if="post['customerId'] == currentCustomerId">
|
||||
<button type="button" v-on:click="deletePost(post['id'])" class="col button dark outline">Удалить пост</button>
|
||||
<button type="button" v-on:click="selectedPostId = post['id']" class="col button primary outline" data-bs-toggle="modal" data-bs-target="#postEdit">Изменить пост</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -118,6 +155,7 @@ import axios from 'axios'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
searchResults: [],
|
||||
customers: [],
|
||||
selectedCustomerId: 0,
|
||||
currentCustomer: {},
|
||||
@ -129,9 +167,27 @@ export default {
|
||||
postContentModal: '',
|
||||
selectedCommentId: 0,
|
||||
currentCustomerId: -1,
|
||||
searchMode: -1,
|
||||
}
|
||||
},
|
||||
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) {
|
||||
var customer = this.customers.find(element => element['id'] == this.currentCustomerId);
|
||||
console.log(customer);
|
||||
|
@ -1,11 +1,17 @@
|
||||
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.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.PostService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@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 ru.ulstu.is.labwork.Lab4.model.Comment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||
List<Comment> findByContentLikeIgnoreCase(String text);
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
package ru.ulstu.is.labwork.Lab4.repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import ru.ulstu.is.labwork.Lab4.model.Post;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PostRepository extends JpaRepository<Post, Long> {
|
||||
List<Post> findByContentLikeIgnoreCase(String text);
|
||||
}
|
||||
|
@ -19,6 +19,13 @@ public class CommentService {
|
||||
public CommentService(CommentRepository commentRepository) {
|
||||
this.commentRepository = commentRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Comment> findFilteredComments(String filter) {
|
||||
return commentRepository.findByContentLikeIgnoreCase("%" + filter + "%");
|
||||
}
|
||||
|
||||
|
||||
@Transactional
|
||||
public Comment findComment(Long 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.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.Post;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.labwork.Lab4.repositories.CommentRepository;
|
||||
import ru.ulstu.is.labwork.Lab4.repositories.PostRepository;
|
||||
|
||||
import java.util.List;
|
||||
@ -18,6 +20,10 @@ public class PostService {
|
||||
public PostService(PostRepository postRepository) {
|
||||
this.postRepository = postRepository;
|
||||
}
|
||||
@Transactional
|
||||
public List<Post> findFilteredPosts(String filter) {
|
||||
return postRepository.findByContentLikeIgnoreCase("%" + filter + "%");
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Post findPost(Long id) {
|
||||
|
Loading…
Reference in New Issue
Block a user