lab6 mvc done

This commit is contained in:
Татьяна Артамонова 2023-09-25 22:12:27 +04:00
parent 5e6d8104dc
commit 421baebbf7
4 changed files with 34 additions and 21 deletions

View File

@ -300,18 +300,25 @@ export default {
console.log(error);
});
},
addAlbum(album){
addAlbum(album) {
console.log(this.album);
axios .create({
axios
.create({
headers: {
'Authorization': 'Bearer ' + localStorage.getItem("token")
}}).post(this.URL + "album", album)
}
})
.post(this.URL + "album", album)
.then(() => {
this.getAlbums();
this.closeModal();
})
.catch(error => {
console.log(error);
if (error.response && error.response.status === 403) {
console.error("Forbidden: User does not have permission to perform this operation");
} else {
console.error(error);
}
});
},
deleteAlbum(id){

View File

@ -60,6 +60,8 @@ import 'axios';
import axios from "axios";
import Song from "@/models/Song";
export default {
name: 'Songs',
emits: ['login'],
created() {
this.getSongs();
this.getAlbums();

View File

@ -47,7 +47,11 @@ export default {
this.users = response.data;
})
.catch(error => {
console.log(error);
if (error.response && error.response.status === 403) {
console.error("Forbidden: User does not have permission to perform this operation");
} else {
console.error(error);
}
});
},
methods:{

View File

@ -2,6 +2,7 @@ package ru.ulstu.is.sbapp.controllers;
import javax.validation.Valid;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import ru.ulstu.is.sbapp.database.model.User;
import ru.ulstu.is.sbapp.database.model.Role;
@ -39,12 +40,11 @@ public class UserController {
}
}
@GetMapping("/{id}")
@Secured({Role.AsString.ADMIN})
public UserDTO getUser(@PathVariable Long id) {
return new UserDTO(userService.findUser(id));
}
@GetMapping("/")
@Secured({Role.AsString.ADMIN})
@PreAuthorize("hasAuthority('ADMIN')")
public List<UserDTO> getUsers() {
return userService.findAllUsers().stream()
.map(UserDTO::new)