lab5
This commit is contained in:
parent
7a49635284
commit
d12e8a5f61
10
build.gradle
10
build.gradle
@ -17,7 +17,15 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'com.h2database:h2:2.1.210'
|
||||
implementation group: 'org.springdoc', name: 'springdoc-openapi-ui', version: '1.6.5'
|
||||
implementation 'org.jetbrains:annotations:24.0.0'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
|
||||
implementation 'org.webjars:bootstrap:5.1.3'
|
||||
implementation 'org.webjars:jquery:3.6.0'
|
||||
implementation 'org.webjars:font-awesome:6.1.0'
|
||||
|
||||
implementation 'org.jetbrains:annotations:24.0.0'
|
||||
implementation 'org.jetbrains:annotations:24.0.0'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
||||
implementation 'org.hibernate.validator:hibernate-validator'
|
||||
|
@ -8,6 +8,6 @@ import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import java.util.List;
|
||||
|
||||
public interface ISongRepository extends JpaRepository<Song, Long> {
|
||||
@Query("SELECT s.songs FROM Album s WHERE :song MEMBER OF s.songs")
|
||||
@Query("SELECT a.songs FROM Album a WHERE :song MEMBER OF a.songs")
|
||||
List<Song> findSongsInAlbum(@Param("song") Song song);
|
||||
}
|
||||
|
@ -2,12 +2,19 @@ package ru.ulstu.is.sbapp;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
class WebConfiguration implements WebMvcConfigurer {
|
||||
public class WebConfiguration implements WebMvcConfigurer {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
public static final String REST_API = "/api";
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
WebMvcConfigurer.super.addViewControllers(registry);
|
||||
registry.addViewController("artist");
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package ru.ulstu.is.sbapp.controllers;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.WebConfiguration;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
@ -11,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/album")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/album")
|
||||
public class AlbumController {
|
||||
private final AlbumService albumService;
|
||||
|
||||
|
@ -0,0 +1,154 @@
|
||||
package ru.ulstu.is.sbapp.controllers;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
import ru.ulstu.is.sbapp.database.service.ArtistService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/album")
|
||||
public class AlbumMvcController {
|
||||
private final AlbumService albumService;
|
||||
private final ArtistService artistService;
|
||||
|
||||
public AlbumMvcController(AlbumService albumService, ArtistService artistService)
|
||||
{
|
||||
this.albumService = albumService;
|
||||
this.artistService = artistService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getAlbums(Model model) {
|
||||
model.addAttribute("albums",
|
||||
albumService.findAllAlbums().stream()
|
||||
.map(AlbumDTO::new)
|
||||
.toList());
|
||||
return "album";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editAlbum(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("albumDTO", new AlbumDTO());
|
||||
} else {
|
||||
model.addAttribute("albumId", id);
|
||||
model.addAttribute("albumDTO", new AlbumDTO(albumService.findAlbum(id)));
|
||||
}
|
||||
return "album-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveAlbum(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid AlbumDTO albumDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "album-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
albumService.addAlbum(albumDTO.getAlbumName());
|
||||
} else {
|
||||
albumService.updateAlbum(id, albumDTO.getAlbumName());
|
||||
}
|
||||
return "redirect:/album";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteAlbum(@PathVariable Long id) {
|
||||
albumService.deleteAlbum(id);
|
||||
return "redirect:/album";
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/songs/{id}")
|
||||
public String getSongsFromAlbum(@PathVariable Long id, Model model) {
|
||||
List<Song> songs = albumService.getSongFromAlbum(id);
|
||||
model.addAttribute("songs", songs);
|
||||
return "view-songs";
|
||||
}
|
||||
|
||||
@GetMapping("/artists/{id}")
|
||||
public String getArtistsFromAlbum(@PathVariable Long id, Model model) {
|
||||
List<Artist> artists = albumService.getArtistInAlbum(id);
|
||||
model.addAttribute("artists", artists);
|
||||
return "view-artists";
|
||||
}
|
||||
|
||||
@GetMapping("/getSongsUndefined/{id}")
|
||||
public String getSongsFromUndefinedAlbum(@PathVariable Long id, Model model){
|
||||
List<Song> songs = albumService.getSongsUndefined();
|
||||
model.addAttribute("undefinedSongs", songs);
|
||||
model.addAttribute("albumId", id);
|
||||
model.addAttribute("albumDTO", new AlbumDTO(albumService.findAlbum(id)));
|
||||
return "add-songs-to-album";
|
||||
}
|
||||
|
||||
@PostMapping("/addSongs/{id}")
|
||||
public String addSongToAlbum(@PathVariable Long id,
|
||||
@RequestParam("songId") List<String> songsIds){
|
||||
List<Long> songIdsAsLong = songsIds.stream()
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
albumService.addSongToAlbum(id, songIdsAsLong);
|
||||
return "redirect:/album";
|
||||
}
|
||||
|
||||
@PostMapping("/deleteSongFromAlbum/{id}")
|
||||
public String deleteSongFromAlbum(@PathVariable Long id) {
|
||||
albumService.deleteSongFromAlbum(id);
|
||||
return "redirect:/album";
|
||||
}
|
||||
|
||||
@GetMapping("/getArtistsUndefined/{id}")
|
||||
public String getArtistsFromUndefinedAlbum(@PathVariable Long id, Model model){
|
||||
List<Artist> artists = albumService.getArtistsUndefined(id);
|
||||
model.addAttribute("undefinedArtists", artists);
|
||||
model.addAttribute("albumId", id);
|
||||
model.addAttribute("albumDTO", new AlbumDTO(albumService.findAlbum(id)));
|
||||
return "add-artist-to-album";
|
||||
}
|
||||
|
||||
@PostMapping("/addArtists/{id}")
|
||||
public String addArtistToAlbum(@PathVariable Long id,
|
||||
@RequestParam("artistId") List<String> artistIds){
|
||||
List<Long> artistIdsAsLong = artistIds.stream()
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
albumService.addArtistToAlbum(id, artistIdsAsLong);
|
||||
return "redirect:/album";
|
||||
}
|
||||
|
||||
@GetMapping("/getAll")
|
||||
public String getAll(Model model){
|
||||
Map<String, List<String>> report = albumService.getAll();
|
||||
return "report";
|
||||
}
|
||||
|
||||
// @GetMapping("/addArtistToAlbum/{id}")
|
||||
// public String addArtistToAlbumForm(@PathVariable Long id, Model model) {
|
||||
// model.addAttribute("albumDTO", new AlbumDTO(albumService.findAlbum(id)));
|
||||
// model.addAttribute("albumId", id);
|
||||
// model.addAttribute("artists", artistService.findAllArtists());
|
||||
// return "add-artist-to-album";
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/addArtistToAlbum/{id}")
|
||||
// public String addArtistToAlbum(@PathVariable Long id,
|
||||
// @RequestParam("artistId") List<Long> artistIds) {
|
||||
// albumService.addArtistToAlbum(id, artistIds);
|
||||
// return "redirect:/album";
|
||||
// }
|
||||
}
|
@ -2,12 +2,13 @@ package ru.ulstu.is.sbapp.controllers;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.WebConfiguration;
|
||||
import ru.ulstu.is.sbapp.database.service.ArtistService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/artist")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/artist")
|
||||
public class ArtistController {
|
||||
private final ArtistService artistService;
|
||||
|
||||
|
@ -37,6 +37,9 @@ public class ArtistDTO {
|
||||
public void setGenre(String genre){
|
||||
this.genre = genre;
|
||||
}
|
||||
public void setArtistName(String artistName){
|
||||
this.artistName = artistName;
|
||||
}
|
||||
|
||||
public List<Long> getAlbumIds(){
|
||||
return albumIds;
|
||||
|
@ -0,0 +1,84 @@
|
||||
package ru.ulstu.is.sbapp.controllers;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
import ru.ulstu.is.sbapp.database.service.ArtistService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/artist")
|
||||
public class ArtistMvcController {
|
||||
private final ArtistService artistService;
|
||||
|
||||
private final AlbumService albumService;
|
||||
|
||||
public ArtistMvcController(ArtistService artistService, AlbumService albumService)
|
||||
{
|
||||
this.artistService = artistService;
|
||||
this.albumService = albumService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getArtists(Model model) {
|
||||
model.addAttribute("artists",
|
||||
artistService.findAllArtists().stream()
|
||||
.map(ArtistDTO::new)
|
||||
.toList());
|
||||
return "artist";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editArtist(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("artistDTO", new ArtistDTO());
|
||||
} else {
|
||||
model.addAttribute("artistId", id);
|
||||
model.addAttribute("artistDTO", new ArtistDTO(artistService.findArtist(id)));
|
||||
}
|
||||
return "artist-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveArtist(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid ArtistDTO artistDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "artist-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
artistService.addArtist(artistDTO.getArtistName(), artistDTO.getGenre());
|
||||
} else {
|
||||
artistService.updateArtist(id, artistDTO.getArtistName(), artistDTO.getGenre());
|
||||
}
|
||||
return "redirect:/artist";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteArtist(@PathVariable Long id) {
|
||||
artistService.deleteArtist(id);
|
||||
return "redirect:/artist";
|
||||
}
|
||||
|
||||
@GetMapping("/addArtistToAlbum/{id}")
|
||||
public String addArtistToAlbumForm(@PathVariable Long id, Model model) {
|
||||
model.addAttribute("artistDTO", new ArtistDTO(artistService.findArtist(id)));
|
||||
model.addAttribute("artistId", id);
|
||||
model.addAttribute("albums", albumService.findAllAlbums());
|
||||
return "add-artist-to-album";
|
||||
}
|
||||
|
||||
@PostMapping("/addArtistToAlbum/{id}")
|
||||
public String addArtistToAlbum(@PathVariable Long id,
|
||||
@RequestParam("albumId") List<Long> albumIds) {
|
||||
artistService.addArtistToAlbum(id, albumIds);
|
||||
return "redirect:/artist";
|
||||
}
|
||||
}
|
@ -2,13 +2,14 @@ package ru.ulstu.is.sbapp.controllers;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.WebConfiguration;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
import ru.ulstu.is.sbapp.database.service.SongService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/song")
|
||||
@RequestMapping(WebConfiguration.REST_API + "/song")
|
||||
public class SongController {
|
||||
private final SongService songService;
|
||||
private final AlbumService albumService;
|
||||
@ -51,5 +52,4 @@ public class SongController {
|
||||
.map(AlbumDTO::new)
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,11 +39,11 @@ public class SongDTO {
|
||||
return albumId;
|
||||
}
|
||||
|
||||
public void setAlbumId(long id){
|
||||
public void setAlbumId(Long id){
|
||||
this.albumId = id;
|
||||
}
|
||||
|
||||
public void setId(long id){
|
||||
public void setId(Long id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,67 @@
|
||||
package ru.ulstu.is.sbapp.controllers;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
import ru.ulstu.is.sbapp.database.service.SongService;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/song")
|
||||
public class SongMvcController {
|
||||
private final SongService songService;
|
||||
private final AlbumService albumService;
|
||||
|
||||
public SongMvcController(SongService songService, AlbumService albumService)
|
||||
{
|
||||
this.songService = songService;
|
||||
this.albumService = albumService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String getSongs(Model model) {
|
||||
model.addAttribute("songs",
|
||||
songService.findAllSongs().stream()
|
||||
.map(SongDTO::new)
|
||||
.toList());
|
||||
return "song";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/edit", "/edit/{id}"})
|
||||
public String editSong(@PathVariable(required = false) Long id,
|
||||
Model model) {
|
||||
model.addAttribute("Albums", albumService.findAllAlbums());
|
||||
if (id == null || id <= 0) {
|
||||
model.addAttribute("songDTO", new SongDTO());
|
||||
} else {
|
||||
model.addAttribute("songId", id);
|
||||
model.addAttribute("songDTO", new SongDTO(songService.findSong(id)));
|
||||
}
|
||||
return "song-edit";
|
||||
}
|
||||
|
||||
@PostMapping(value = {"/", "/{id}"})
|
||||
public String saveSong(@PathVariable(required = false) Long id,
|
||||
@ModelAttribute @Valid SongDTO songDTO,
|
||||
BindingResult bindingResult,
|
||||
Model model) {
|
||||
if (bindingResult.hasErrors()) {
|
||||
model.addAttribute("errors", bindingResult.getAllErrors());
|
||||
return "song-edit";
|
||||
}
|
||||
if (id == null || id <= 0) {
|
||||
songService.addSong(songDTO.getSongName(), songDTO.getDuration());
|
||||
} else {
|
||||
songService.updateSong(id, songDTO.getSongName(), songDTO.getDuration());
|
||||
}
|
||||
return "redirect:/song";
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public String deleteSong(@PathVariable Long id) {
|
||||
songService.deleteSong(id);
|
||||
return "redirect:/song";
|
||||
}
|
||||
}
|
@ -127,6 +127,17 @@ public class AlbumService {
|
||||
albumRepository.save(currentAlbum);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Artist> getArtistsUndefined(Long albumId){
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
for(Artist artist : artistService.findAllArtists()){
|
||||
if(!artist.getAlbumIds().contains(albumId)){
|
||||
artists.add(artist);
|
||||
}
|
||||
}
|
||||
return artists;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Map<String, List<String>> getAll(){
|
||||
return albumRepository.getAll().stream()
|
||||
|
@ -47,6 +47,7 @@ public class ArtistService {
|
||||
}
|
||||
final Artist currentArtist = findArtist(id);
|
||||
currentArtist.setArtistName(name);
|
||||
currentArtist.setGenre(genre);
|
||||
return artistRepository.save(currentArtist);
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class SongService {
|
||||
|
||||
@Transactional
|
||||
public Song addSong(String songName, Double duration){
|
||||
if (!StringUtils.hasText(songName) || !StringUtils.hasText(String.valueOf(duration))) {
|
||||
if (!StringUtils.hasText(songName) || duration == null) {
|
||||
throw new IllegalArgumentException("Song name or duration is null or empty");
|
||||
}
|
||||
final Song song = new Song(songName, duration);
|
||||
@ -43,7 +43,7 @@ public class SongService {
|
||||
|
||||
@Transactional
|
||||
public Song updateSong(Long id, String name, Double duration) {
|
||||
if (!StringUtils.hasText(name) || !StringUtils.hasText(String.valueOf(duration))) {
|
||||
if (!StringUtils.hasText(name) || duration == null) {
|
||||
throw new IllegalArgumentException("Song name or duration is null or empty");
|
||||
}
|
||||
final Song currentSong = findSong(id);
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumNotFoundException;
|
||||
import ru.ulstu.is.sbapp.database.service.ArtistNotFoundException;
|
||||
import ru.ulstu.is.sbapp.database.service.SongNotFoundException;
|
||||
@ -13,7 +14,7 @@ import ru.ulstu.is.sbapp.database.util.validation.ValidationException;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ControllerAdvice
|
||||
@ControllerAdvice(annotations = RestController.class)
|
||||
public class AdviceController {
|
||||
@ExceptionHandler({
|
||||
AlbumNotFoundException.class,
|
||||
|
37
src/main/resources/templates/add-artist-to-album.html
Normal file
37
src/main/resources/templates/add-artist-to-album.html
Normal file
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/album/addArtists/{id}(id=${albumId})}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="albumName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="albumName" th:field="${albumDTO.albumName}" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="albumName">Выберите исполнителей для добавления:</label>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" th:each="artist, iterator: ${undefinedArtists}">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="artistId" th:value="${artist.id}">
|
||||
<label class="form-check-label" th:text="${artist.artistName}"></label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/album}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
37
src/main/resources/templates/add-songs-to-album.html
Normal file
37
src/main/resources/templates/add-songs-to-album.html
Normal file
@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/album/addSongs/{id}(id=${albumId})}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="albumName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="albumName" th:field="${albumDTO.albumName}" readonly>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="albumName">Выберите песни:</label>
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item" th:each="song, iterator: ${undefinedSongs}">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="songId" th:value="${song.id}">
|
||||
<label class="form-check-label" th:text="${song.songName}"></label>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span>Добавить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/album}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
27
src/main/resources/templates/album-edit.html
Normal file
27
src/main/resources/templates/album-edit.html
Normal file
@ -0,0 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/album/{id}(id=${id})}" th:object="${albumDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="albumName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="albumName" th:field="${albumDTO.albumName}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${albumId == null}">Добавить</span>
|
||||
<span th:if="${albumId != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/album}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
56
src/main/resources/templates/album.html
Normal file
56
src/main/resources/templates/album.html
Normal file
@ -0,0 +1,56 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h1 class="text-center mb-4">Альбомы</h1>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/album/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="album, iterator: ${albums}">
|
||||
<td th:text="${album.albumName}"></td>
|
||||
<td>
|
||||
<div class="btn-album" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/album/edit/{id}(id=${album.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${album.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
<a class="btn btn-primary button-fixed button-sm"
|
||||
th:href="@{/album/songs/{id}(id=${album.id})}">Посмотреть песни</a>
|
||||
<a class="btn btn-primary button-fixed button-sm"
|
||||
th:href="@{/album/getSongsUndefined/{id}(id=${album.id})}">Добавить песни</a>
|
||||
<a class="btn btn-primary button-fixed button-sm"
|
||||
th:href="@{/album/getArtistsUndefined/{id}(id=${album.id})}"> Добавить исполнителей</a>
|
||||
<a class="btn btn-primary button-fixed button-sm"
|
||||
th:href="@{/album/artists/{id}(id=${album.id})}">Посмотреть исполнителей</a>
|
||||
</div>
|
||||
<form th:action="@{/album/delete/{id}(id=${album.id})}" method="post">
|
||||
<button th:id="'remove-' + ${album.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
29
src/main/resources/templates/artist-edit.html
Normal file
29
src/main/resources/templates/artist-edit.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/artist/{id}(id=${id})}" th:object="${artistDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="artistName" class="form-label">Имя</label>
|
||||
<input type="text" class="form-control" id="artistName" th:field="${artistDTO.artistName}" required="true">
|
||||
<label for="genre" class="form-label">Жанр</label>
|
||||
<input type="text" class="form-control" id="genre" th:field="${artistDTO.genre}" required="true">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${artistId == null}">Добавить</span>
|
||||
<span th:if="${artistId != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/artist}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
50
src/main/resources/templates/artist.html
Normal file
50
src/main/resources/templates/artist.html
Normal file
@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h1 class="text-center mb-4">Исполнители</h1>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/artist/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Имя</th>
|
||||
<th scope="col">Жанр</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="artist, iterator: ${artists}">
|
||||
<td th:text="${artist.artistName}"></td>
|
||||
<td th:text="${artist.genre}"></td>
|
||||
<td>
|
||||
<div class="btn-album" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/artist/edit/{id}(id=${artist.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${artist.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/artist/delete/{id}(id=${artist.id})}" method="post">
|
||||
<button th:id="'remove-' + ${artist.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
40
src/main/resources/templates/default.html
Normal file
40
src/main/resources/templates/default.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ru"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Streaming Service</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="icon" href="/favicon.svg">
|
||||
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
|
||||
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
|
||||
<link rel="stylesheet" href="/css/style.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
<button class="navbar-toggler" type="button"
|
||||
data-bs-toggle="collapse" data-bs-target="#navbarNav"
|
||||
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<a class="nav-link">Стриминговый сервис</a>
|
||||
<a class="nav-link" href="/song" th:classappend="${#strings.equals(activeLink, '/song')} ? 'active' : ''">Песни</a>
|
||||
<a class="nav-link" href="/album" th:classappend="${#strings.equals(activeLink, '/album')} ? 'active' : ''">Альбомы</a>
|
||||
<a class="nav-link" href="/artist" th:classappend="${#strings.equals(activeLink, '/artist')} ? 'active' : ''">Исполнители</a>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid">
|
||||
<div class="container container-padding" layout:fragment="content">
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<th:block layout:fragment="scripts">
|
||||
</th:block>
|
||||
</html>
|
13
src/main/resources/templates/error.html
Normal file
13
src/main/resources/templates/error.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div><span th:text="${error}"></span></div>
|
||||
<a href="/">На главную</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
13
src/main/resources/templates/index.html
Normal file
13
src/main/resources/templates/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div>It's works!</div>
|
||||
<a href="123">ERROR</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
29
src/main/resources/templates/song-edit.html
Normal file
29
src/main/resources/templates/song-edit.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div th:text="${errors}" class="margin-bottom alert-danger"></div>
|
||||
<form action="#" th:action="@{/song/{id}(id=${id})}" th:object="${songDTO}" method="post">
|
||||
<div class="mb-3">
|
||||
<label for="songName" class="form-label">Название</label>
|
||||
<input type="text" class="form-control" id="songName" th:field="${songDTO.songName}" required>
|
||||
<label for="duration" class="form-label">Продолжительность</label>
|
||||
<input type="number" step="0.1" class="form-control" id="duration" th:field="${songDTO.duration}" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-primary button-fixed">
|
||||
<span th:if="${songId == null}">Добавить</span>
|
||||
<span th:if="${songId != null}">Обновить</span>
|
||||
</button>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/song}">
|
||||
Назад
|
||||
</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
54
src/main/resources/templates/song.html
Normal file
54
src/main/resources/templates/song.html
Normal file
@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<h1 class="text-center mb-4">Песни</h1>
|
||||
<div>
|
||||
<a class="btn btn-success button-fixed"
|
||||
th:href="@{/song/edit}">
|
||||
<i class="fa-solid fa-plus"></i> Добавить
|
||||
</a>
|
||||
</div>
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Продолжительность</th>
|
||||
<th scope="col">Альбом</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="song, iterator: ${songs}">
|
||||
<td th:text="${song.songName}"></td>
|
||||
<td th:text="${song.duration}"></td>
|
||||
<td th:text="${song.albumName}"></td>
|
||||
<td>
|
||||
<div class="btn-album" role="group" aria-label="Basic example">
|
||||
<a class="btn btn-warning button-fixed button-sm"
|
||||
th:href="@{/song/edit/{id}(id=${song.id})}">
|
||||
<i class="fa fa-pencil" aria-hidden="true"></i> Изменить
|
||||
</a>
|
||||
<button type="button" class="btn btn-danger button-fixed button-sm"
|
||||
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${song.id}').click()|">
|
||||
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<form th:action="@{/song/delete/{id}(id=${song.id})}" method="post">
|
||||
<button th:id="'remove-' + ${song.id}" type="submit" style="display: none">
|
||||
Удалить
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
30
src/main/resources/templates/view-artists.html
Normal file
30
src/main/resources/templates/view-artists.html
Normal file
@ -0,0 +1,30 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Имя</th>
|
||||
<th scope="col">Жанр</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="artist, iterator: ${artists}">
|
||||
<td th:text="${artist.artistName}"></td>
|
||||
<td th:text="${artist.genre}"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/album}">
|
||||
Назад
|
||||
</a>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
36
src/main/resources/templates/view-songs.html
Normal file
36
src/main/resources/templates/view-songs.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en"
|
||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<div layout:fragment="content">
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Название</th>
|
||||
<th scope="col">Продолжительность</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="song, iterator: ${songs}">
|
||||
<td th:text="${song.songName}"></td>
|
||||
<td th:text="${song.duration}"></td>
|
||||
<td>
|
||||
<form method="post" th:action="@{/album/deleteSongFromAlbum/{id}(id=${song.id})}">
|
||||
<button type="submit" class="btn btn-danger button-fixed button-sm">Удалить</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<a class="btn btn-secondary button-fixed" th:href="@{/album}">
|
||||
Назад
|
||||
</a>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user