Lab 6 react все еще продолжаю делать (на всякий случай коммит)
This commit is contained in:
parent
814cc54767
commit
053eab0019
@ -20,7 +20,9 @@ export default function Catalog(props) {
|
||||
loadItems();
|
||||
},[userId])
|
||||
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
useEffect(()=>
|
||||
{
|
||||
loadItems2();
|
||||
@ -30,15 +32,27 @@ export default function Catalog(props) {
|
||||
setUserId(id);
|
||||
}
|
||||
const loadItems = async function() {
|
||||
const requestUrl = `http://localhost:8080/user/${userId}/posts`;
|
||||
const response = await fetch(requestUrl);
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = `http://localhost:8080/api/1.0/user/${userId}/posts`;
|
||||
const response = await fetch(requestUrl,requestParams);
|
||||
const posts = await response.json();
|
||||
setItems(posts);
|
||||
}
|
||||
|
||||
const loadItems2 = async function() {
|
||||
const requestUrl = `http://localhost:8080/post/filteredposts?Text=${value}`;
|
||||
const response = await fetch(requestUrl);
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = `http://localhost:8080/api/1.0/post/filteredposts?Text=${value}`;
|
||||
const response = await fetch(requestUrl,requestParams);
|
||||
const posts = await response.json();
|
||||
console.log(posts);
|
||||
setItems(posts);
|
||||
@ -46,7 +60,7 @@ export default function Catalog(props) {
|
||||
|
||||
const saveItem = async function() {
|
||||
if (!isEdit) {
|
||||
const requestUrl = `http://localhost:8080/user/${userId}/Post`;
|
||||
const requestUrl = `http://localhost:8080/api/1.0/user/${userId}/Post`;
|
||||
const temppost=JSON.stringify(props.data)
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
@ -58,7 +72,7 @@ export default function Catalog(props) {
|
||||
await fetch(requestUrl,requestParams).then(() => loadItems());
|
||||
|
||||
} else {
|
||||
const requestUrl = "http://localhost:8080/post/"+props.data.id;
|
||||
const requestUrl = "http://localhost:8080/api/1.0/post/"+props.data.id;
|
||||
const temppost=JSON.stringify(props.data)
|
||||
const requestParams = {
|
||||
method: "PUT",
|
||||
@ -81,7 +95,7 @@ export default function Catalog(props) {
|
||||
|
||||
|
||||
const edit = async function(editedId) {
|
||||
const requestUrl = "http://localhost:8080/post/"+editedId;
|
||||
const requestUrl = "http://localhost:8080/api/1.0/post/"+editedId;
|
||||
const requestParams = {
|
||||
mode: 'cors'
|
||||
}
|
||||
@ -100,7 +114,7 @@ export default function Catalog(props) {
|
||||
|
||||
const handleRemove = async function(id) {
|
||||
if (confirm('Удалить выбранные элементы?')) {
|
||||
const requestUrl = `http://localhost:8080/user/${userId}/Post/`+id;
|
||||
const requestUrl = `http://localhost:8080/api/1.0/user/${userId}/Post/`+id;
|
||||
const requestParams = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
|
@ -3,7 +3,7 @@ import Catalog from './Catalog';
|
||||
import New from '../../models/NewDto';
|
||||
|
||||
export default function News(props) {
|
||||
const url = 'post/';
|
||||
const url = '/api/1.0/post/';
|
||||
const transformer = (data) => new New(data);
|
||||
const catalogStudHeaders = [
|
||||
{ name: 'image', label: 'Картинка' },
|
||||
|
@ -6,7 +6,23 @@ export default function Card(props) {
|
||||
function edit(id) {
|
||||
props.onEdit(id);
|
||||
}
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
|
||||
const getUser = async function () {
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
let login = localStorage.getItem("user");
|
||||
const requestUrl = host + `/user?login=${login}`;
|
||||
const response = await fetch(requestUrl, requestParams);
|
||||
const user = await response.json();
|
||||
return user;
|
||||
}
|
||||
function remove(id) {
|
||||
props.onRemove(id);
|
||||
}
|
||||
@ -14,12 +30,18 @@ export default function Card(props) {
|
||||
getAll();
|
||||
}, []);
|
||||
|
||||
const [clients, setClientst] = useState([]);
|
||||
const [clients, setClients] = useState([]);
|
||||
const getAll = async function () {
|
||||
const requestUrl = "http://localhost:8080/user";
|
||||
const response = await fetch(requestUrl);
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = "http://localhost:8080/api/1.0/userList";
|
||||
const response = await fetch(requestUrl,requestParams);
|
||||
const users = await response.json();
|
||||
setClientst(users);
|
||||
setClients(users);
|
||||
}
|
||||
const [modalTable, setModalTable] = useState(false);
|
||||
const [currEditItem, setCurrEditItem] = useState(0);
|
||||
@ -33,7 +55,7 @@ export default function Card(props) {
|
||||
const handleSubmitEdit = async (e, id) => {
|
||||
console.info('Start synchronize edit');
|
||||
e.preventDefault(); // страница перестает перезагружаться
|
||||
const requestUrl = `http://localhost:8080/post/${id}/Comment/${props.userId}?Text=${text}`;
|
||||
const requestUrl = `http://localhost:8080/api/1.0/post/${id}/Comment/${props.userId}?Text=${text}`;
|
||||
const requestParams = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
@ -6,16 +6,25 @@ export default function Toolbar(props) {
|
||||
props.onAdd();
|
||||
}
|
||||
const [clients, setClientst] = useState([]);
|
||||
|
||||
const getTokenForHeader = function () {
|
||||
return "Bearer " + localStorage.getItem("token");
|
||||
}
|
||||
useEffect(() => {
|
||||
getAll();
|
||||
}, []);
|
||||
const getAll = async function () {
|
||||
const requestUrl = "http://localhost:8080/user";
|
||||
const response = await fetch(requestUrl);
|
||||
const requestParams = {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Authorization": getTokenForHeader(),
|
||||
}
|
||||
};
|
||||
const requestUrl = "http://localhost:8080/api/1.0/userList";
|
||||
const response = await fetch(requestUrl,requestParams);
|
||||
const users = await response.json();
|
||||
setClientst(users);
|
||||
}
|
||||
|
||||
function getuser(){
|
||||
var selectBox = document.getElementById("selectBox");
|
||||
var selectedValue = selectBox.options[selectBox.selectedIndex].value;
|
||||
@ -28,7 +37,7 @@ export default function Toolbar(props) {
|
||||
<option disabled value="">Выбор...</option>
|
||||
{
|
||||
clients.map((client) => (
|
||||
<option className='text-black' key={client.id} value={client.id}>{client.firstName}</option>
|
||||
<option className='text-black' key={client.id} value={client.id}>{client.login}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
@ -47,7 +47,13 @@ public class UserController {
|
||||
.toList();
|
||||
return new Pair<>(users, pageNumbers);
|
||||
}
|
||||
@GetMapping("/{id}/posts")
|
||||
@GetMapping(OpenAPI30Configuration.API_PREFIX + "/userList")
|
||||
public List<UserDto> getListUsers() {
|
||||
return userService.findAllUsers().stream()
|
||||
.map(UserDto::new)
|
||||
.toList();
|
||||
}
|
||||
@GetMapping(OpenAPI30Configuration.API_PREFIX +"/user/{id}/posts")
|
||||
public List<PostDto> getPosts(@PathVariable Long id) {
|
||||
return userService.GetUserPosts(id).stream()
|
||||
.map(PostDto::new)
|
||||
|
Loading…
Reference in New Issue
Block a user