lab6 mvc done

This commit is contained in:
Татьяна Артамонова 2023-09-25 22:54:46 +04:00
parent b6b676717c
commit 322353ff16
3 changed files with 11 additions and 0 deletions

View File

@ -2,10 +2,12 @@ package ru.ulstu.is.sbapp.controllers;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ru.ulstu.is.sbapp.configuration.WebConfiguration; import ru.ulstu.is.sbapp.configuration.WebConfiguration;
import ru.ulstu.is.sbapp.database.model.Artist; import ru.ulstu.is.sbapp.database.model.Artist;
import ru.ulstu.is.sbapp.database.model.Song; import ru.ulstu.is.sbapp.database.model.Song;
import ru.ulstu.is.sbapp.database.model.UserRole;
import ru.ulstu.is.sbapp.database.service.AlbumService; import ru.ulstu.is.sbapp.database.service.AlbumService;
import java.util.List; import java.util.List;
@ -33,6 +35,7 @@ public class AlbumController {
} }
@PostMapping @PostMapping
@Secured({UserRole.AsString.ADMIN})
public AlbumDTO createAlbum(@RequestBody @Valid AlbumDTO albumDTO){ public AlbumDTO createAlbum(@RequestBody @Valid AlbumDTO albumDTO){
return new AlbumDTO(albumService.addAlbum(albumDTO.getAlbumName())); return new AlbumDTO(albumService.addAlbum(albumDTO.getAlbumName()));
} }

View File

@ -1,8 +1,11 @@
package ru.ulstu.is.sbapp.controllers; package ru.ulstu.is.sbapp.controllers;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ru.ulstu.is.sbapp.configuration.WebConfiguration; import ru.ulstu.is.sbapp.configuration.WebConfiguration;
import ru.ulstu.is.sbapp.database.model.UserRole;
import ru.ulstu.is.sbapp.database.service.ArtistService; import ru.ulstu.is.sbapp.database.service.ArtistService;
import java.util.List; import java.util.List;
@ -29,6 +32,7 @@ public class ArtistController {
} }
@PostMapping @PostMapping
@Secured({UserRole.AsString.ADMIN})
public ArtistDTO createArtist(@RequestBody @Valid ArtistDTO artistDTO){ public ArtistDTO createArtist(@RequestBody @Valid ArtistDTO artistDTO){
return new ArtistDTO(artistService.addArtist(artistDTO.getArtistName(), artistDTO.getGenre())); return new ArtistDTO(artistService.addArtist(artistDTO.getArtistName(), artistDTO.getGenre()));
} }

View File

@ -1,8 +1,11 @@
package ru.ulstu.is.sbapp.controllers; package ru.ulstu.is.sbapp.controllers;
import javax.validation.Valid; import javax.validation.Valid;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import ru.ulstu.is.sbapp.configuration.WebConfiguration; import ru.ulstu.is.sbapp.configuration.WebConfiguration;
import ru.ulstu.is.sbapp.database.model.UserRole;
import ru.ulstu.is.sbapp.database.service.AlbumService; import ru.ulstu.is.sbapp.database.service.AlbumService;
import ru.ulstu.is.sbapp.database.service.SongService; import ru.ulstu.is.sbapp.database.service.SongService;
@ -32,6 +35,7 @@ public class SongController {
} }
@PostMapping @PostMapping
@Secured({UserRole.AsString.ADMIN})
public SongDTO createSong(@RequestBody @Valid SongDTO songDTO){ public SongDTO createSong(@RequestBody @Valid SongDTO songDTO){
return new SongDTO(songService.addSong(songDTO.getSongName(), songDTO.getDuration())); return new SongDTO(songService.addSong(songDTO.getSongName(), songDTO.getDuration()));
} }