Compare commits

...

2 Commits

Author SHA1 Message Date
004ba73684 fix 2023-05-15 15:40:33 +04:00
858188c8ad . 2023-05-15 14:19:01 +04:00
6 changed files with 43 additions and 11 deletions

View File

@ -25,12 +25,14 @@ export default function Container(props) {
<a <a
className="text-end align-self-end" className="text-end align-self-end"
href="#" href="#"
type="button"
onClick={()=>props.onRemove(item.id)} onClick={()=>props.onRemove(item.id)}
> >
Удалить Удалить
</a> </a>
<a <a
className="px-2 text-end align-self-end" className="px-2 text-end align-self-end"
type="button"
href="#" href="#"
onClick={()=>props.onEdit(item.id)} onClick={()=>props.onEdit(item.id)}
> >
@ -39,6 +41,7 @@ export default function Container(props) {
<a <a
className="px-2 text-end align-self-end" className="px-2 text-end align-self-end"
href="#" href="#"
type="button"
onClick={()=>props.onUpdateGenre(item.id)} onClick={()=>props.onUpdateGenre(item.id)}
> >
Изменить жанры Изменить жанры

View File

@ -49,7 +49,7 @@ export default function UsersPage(props) {
<nav> <nav>
<ul className="pagination"> <ul className="pagination">
{pageNumbers.map((number) => ( {pageNumbers.map((number) => (
<li className={`page-item ${number === pageNumber + 1 ? "active" : ""}`} <li className={`page-item ${number === pageNumber ? "active" : ""}`}
onClick={() => pageButtonOnClick(number)}> onClick={() => pageButtonOnClick(number)}>
<a className="page-link" href="#">{number}</a> <a className="page-link" href="#">{number}</a>
</li> </li>

View File

@ -29,7 +29,11 @@ export default class DataService {
return response.data.map(item => transformer(item)); return response.data.map(item => transformer(item));
} }
static async read(dataUrlPrefix, url, id, transformer) { static async read(dataUrlPrefix, url, id, transformer) {
const response = await axios.get(dataUrlPrefix + url + '/' + id); const response = await axios.get(dataUrlPrefix + url + '/' + id,{
headers:{
"Authorization": "Bearer " + localStorage.getItem("token")
}
});
return transformer(response.data); return transformer(response.data);
} }
@ -53,23 +57,27 @@ export default class DataService {
} }
static async createGenre(dataUrlPrefix, url, data){ static async createGenre(dataUrlPrefix, url, data){
const headers = { const headers = {
"Content-Type": "application/json" "Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}; };
const response = await axios.post(dataUrlPrefix + url + `?name=${data.name}&login=${localStorage.getItem("login")}`, JSON.stringify(data), headers); const response = await axios.post(dataUrlPrefix + url + `?name=${data.name}&login=${localStorage.getItem("login")}`, JSON.stringify(data), headers);
return true; return true;
} }
static async updateBook(dataUrlPrefix, url, data) { static async updateBook(dataUrlPrefix, url, data) {
const headers = {
"Content-Type": "application/json"
};
const response = await axios.put(dataUrlPrefix + url + '/' + data.id + `?name=${data.name}&desc=${data.description} const response = await axios.put(dataUrlPrefix + url + '/' + data.id + `?name=${data.name}&desc=${data.description}
&authorId=${data.author}`, JSON.stringify(data), headers); &authorId=${data.author}`, JSON.stringify(data), {
headers:{
"Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}
});
return true; return true;
} }
static async updateAuthor(dataUrlPrefix, url, data) { static async updateAuthor(dataUrlPrefix, url, data) {
const headers = { const headers = {
"Content-Type": "application/json" "Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}; };
const response = await axios.put(dataUrlPrefix + url + '/' + data.id + `?name=${data.name}&surname=${data.surname} const response = await axios.put(dataUrlPrefix + url + '/' + data.id + `?name=${data.name}&surname=${data.surname}
&patronymic=${data.patronymic}`, JSON.stringify(data), headers); &patronymic=${data.patronymic}`, JSON.stringify(data), headers);
@ -77,14 +85,16 @@ export default class DataService {
} }
static async updateGenre(dataUrlPrefix, url, data) { static async updateGenre(dataUrlPrefix, url, data) {
const headers = { const headers = {
"Content-Type": "application/json" "Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}; };
const response = await axios.put(dataUrlPrefix + url + '/' + data.id + `?name=${data.name}`, JSON.stringify(data), headers); const response = await axios.put(dataUrlPrefix + url + '/' + data.id + `?name=${data.name}`, JSON.stringify(data), headers);
return true; return true;
} }
static async updateBookGenre(dataUrlPrefix, url, data, genreId, param){ static async updateBookGenre(dataUrlPrefix, url, data, genreId, param){
const headers = { const headers = {
"Content-Type": "application/json" "Content-Type": "application/json",
"Authorization": "Bearer " + localStorage.getItem("token")
}; };
if(param === true){ if(param === true){
const response = await axios.put(dataUrlPrefix + url + '/' + data.id + '/genres/' + genreId, JSON.stringify(data), headers); const response = await axios.put(dataUrlPrefix + url + '/' + data.id + '/genres/' + genreId, JSON.stringify(data), headers);
@ -96,7 +106,11 @@ export default class DataService {
} }
static async delete(dataUrlPrefix,url, id) { static async delete(dataUrlPrefix,url, id) {
const response = await axios.delete(dataUrlPrefix + url + '/' + id); const response = await axios.delete(dataUrlPrefix + url + '/' + id,{
headers:{
"Authorization": "Bearer " + localStorage.getItem("token")
}
});
return response.data.id; return response.data.id;
} }
} }

View File

@ -1,6 +1,8 @@
package com.labwork01.app.author.controller; package com.labwork01.app.author.controller;
import com.labwork01.app.author.service.AuthorService; import com.labwork01.app.author.service.AuthorService;
import com.labwork01.app.user.model.UserRole;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -13,6 +15,7 @@ public class AuthorController {
this.authorService = authorService; this.authorService = authorService;
} }
@GetMapping("/{id}") @GetMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public AuthorDto getAuthor(@PathVariable Long id) { public AuthorDto getAuthor(@PathVariable Long id) {
return new AuthorDto(authorService.findAuthor(id)); return new AuthorDto(authorService.findAuthor(id));
} }
@ -33,6 +36,7 @@ public class AuthorController {
} }
@PutMapping("/{id}") @PutMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public AuthorDto updateAuthor(@PathVariable Long id, public AuthorDto updateAuthor(@PathVariable Long id,
@RequestParam("name") String name, @RequestParam("name") String name,
@RequestParam("surname") String surname, @RequestParam("surname") String surname,
@ -41,6 +45,7 @@ public class AuthorController {
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public AuthorDto deleteAuthor(@PathVariable Long id) { public AuthorDto deleteAuthor(@PathVariable Long id) {
return new AuthorDto(authorService.deleteAuthor(id)); return new AuthorDto(authorService.deleteAuthor(id));
} }

View File

@ -4,6 +4,8 @@ import com.labwork01.app.author.service.AuthorService;
import com.labwork01.app.book.service.BookService; import com.labwork01.app.book.service.BookService;
import com.labwork01.app.genre.model.Genre; import com.labwork01.app.genre.model.Genre;
import com.labwork01.app.genre.service.GenreService; import com.labwork01.app.genre.service.GenreService;
import com.labwork01.app.user.model.UserRole;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +23,7 @@ public class BookController {
this.genreService = genreService; this.genreService = genreService;
} }
@GetMapping("/{id}") @GetMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public BookDto getBook(@PathVariable Long id) { public BookDto getBook(@PathVariable Long id) {
return new BookDto(bookService.findBook(id)); return new BookDto(bookService.findBook(id));
} }
@ -49,6 +52,7 @@ public class BookController {
} }
@PutMapping("/{id}") @PutMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public BookDto updateBook(@PathVariable Long id, public BookDto updateBook(@PathVariable Long id,
@RequestParam("name") String name, @RequestParam("name") String name,
@RequestParam("desc") String description, @RequestParam("desc") String description,
@ -66,6 +70,7 @@ public class BookController {
return new BookDto(bookService.removeGenreFromBook(id, genreService.findGenre(genreId))); return new BookDto(bookService.removeGenreFromBook(id, genreService.findGenre(genreId)));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public BookDto deleteBook(@PathVariable Long id) { public BookDto deleteBook(@PathVariable Long id) {
return new BookDto(bookService.deleteBook(id)); return new BookDto(bookService.deleteBook(id));
} }

View File

@ -1,6 +1,8 @@
package com.labwork01.app.genre.controller; package com.labwork01.app.genre.controller;
import com.labwork01.app.genre.service.GenreService; import com.labwork01.app.genre.service.GenreService;
import com.labwork01.app.user.model.UserRole;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@ -13,6 +15,7 @@ public class GenreController {
this.genreService = genreService; this.genreService = genreService;
} }
@GetMapping("/{id}") @GetMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public GenreDto getGenre(@PathVariable Long id) { public GenreDto getGenre(@PathVariable Long id) {
return new GenreDto(genreService.findGenre(id)); return new GenreDto(genreService.findGenre(id));
} }
@ -30,12 +33,14 @@ public class GenreController {
} }
@PutMapping("/{id}") @PutMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public GenreDto updateGenre(@PathVariable Long id, public GenreDto updateGenre(@PathVariable Long id,
@RequestParam("name") String name) { @RequestParam("name") String name) {
return new GenreDto(genreService.updateGenre(id, name)); return new GenreDto(genreService.updateGenre(id, name));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@Secured({UserRole.AsString.ADMIN})
public GenreDto deleteGenre(@PathVariable Long id) { public GenreDto deleteGenre(@PathVariable Long id) {
return new GenreDto(genreService.deleteGenre(id)); return new GenreDto(genreService.deleteGenre(id));
} }