3 dop
This commit is contained in:
parent
feefeadbd3
commit
0c189c0e34
@ -17,6 +17,7 @@ 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.hibernate.validator:hibernate-validator'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
}
|
||||
|
||||
|
@ -1,15 +1,48 @@
|
||||
{
|
||||
"name": "IP",
|
||||
"version": "1.0.0",
|
||||
"main": "index.html",
|
||||
"scripts": {
|
||||
"start": "http-server -p 3001 ./",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"name": "pages_react",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"bootstrap": "5.2.1"
|
||||
"@fortawesome/fontawesome-free": "^6.2.1",
|
||||
"axios": "^1.1.3",
|
||||
"bootstrap": "^5.2.3",
|
||||
"react": "^18.2.0",
|
||||
"react-bootstrap": "^2.7.2",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-router-dom": "^6.6.1",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"http-server": "^14.1.1"
|
||||
"@types/react": "^18.0.24",
|
||||
"@types/react-dom": "^18.0.8",
|
||||
"@vitejs/plugin-react": "^2.2.0",
|
||||
"json-server": "^0.17.1",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"vite": "^3.2.3"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
'use strict'
|
||||
async function calculate(){
|
||||
let num1 = document.getElementById("input1").value
|
||||
let num2 = document.getElementById("input2").value
|
||||
let operator = document.getElementById("operator").value
|
||||
let result = document.getElementById("result")
|
||||
let type = document.getElementById("Type").value
|
||||
|
||||
|
||||
let response = await fetch(`http://localhost:8080/${operator}?Type=${type}&value1=${num1}&value2=${num2}`)
|
||||
let res = await response.text()
|
||||
result.value = res
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package ru.ulstu.is.sbapp.database.controllers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
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 ru.ulstu.is.sbapp.database.service.SongService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class Controller {
|
||||
private final SongService songService;
|
||||
private final AlbumService albumService;
|
||||
private final ArtistService artistService;
|
||||
@Autowired
|
||||
public Controller(SongService songService, AlbumService albumService, ArtistService artistService) {
|
||||
this.albumService = albumService;
|
||||
this.artistService = artistService;
|
||||
this.songService = songService;
|
||||
}
|
||||
|
||||
@GetMapping("/find")
|
||||
public Map<String, List<Object>> GetResult (@RequestParam(value = "name") String value) {
|
||||
Map<String, List<Object>> resultMap = new HashMap<>();
|
||||
List<Object> resultList = new ArrayList<>();
|
||||
List<Song> songList = songService.findAllSongsByName(value);
|
||||
List<Album> albumList = albumService.findAllAlbumsByName(value);
|
||||
List<Artist> artistList = artistService.findAllArtistsByName(value);
|
||||
for(Song song : songList) {
|
||||
resultList.add(song);
|
||||
resultMap.put(song.getSongName(), resultList);
|
||||
for(Album album : albumList) {
|
||||
resultList.add(album);
|
||||
resultMap.put(album.getAlbumName(), resultList);
|
||||
for (Artist artist : artistList) {
|
||||
resultList.add(artist);
|
||||
resultMap.put(artist.getArtistName(), resultList);
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
}
|
@ -9,18 +9,21 @@ import java.util.Objects;
|
||||
@Table(name = "album")
|
||||
public class Album {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String albumName;
|
||||
@OneToMany(cascade = {CascadeType.MERGE})
|
||||
@JoinColumn(name = "songs", nullable = true)
|
||||
private List<Song> songs;
|
||||
@ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.EAGER)
|
||||
|
||||
@OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Song> songs = new ArrayList<>();
|
||||
|
||||
@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
|
||||
@JoinTable(name = "albums_artists",
|
||||
joinColumns = @JoinColumn(name = "album_fk"),
|
||||
inverseJoinColumns = @JoinColumn(name = "artist_fk"))
|
||||
private List<Artist> artists;
|
||||
joinColumns = @JoinColumn(name = "album_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "artist_id"))
|
||||
private List<Artist> artists = new ArrayList<>();
|
||||
|
||||
public Album(){
|
||||
}
|
||||
public Album(String albumName){
|
||||
|
@ -8,14 +8,17 @@ import java.util.Objects;
|
||||
@Table(name = "song")
|
||||
public class Song {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String songName;
|
||||
|
||||
@Column(name = "duration")
|
||||
private Double duration;
|
||||
@ManyToOne(cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "album", nullable = true)
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "album_id")
|
||||
private Album album;
|
||||
public Song(){
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -130,4 +131,9 @@ public class AlbumService {
|
||||
}
|
||||
return albumList;
|
||||
}
|
||||
@Transactional
|
||||
public List<Album> findAllAlbumsByName(String name){
|
||||
return em.createQuery("select A from Album A where A.albumName = :name", Album.class)
|
||||
.setParameter("name", name).getResultList();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,9 @@ import ru.ulstu.is.sbapp.database.model.Album;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ArtistService {
|
||||
@ -76,14 +78,19 @@ public class ArtistService {
|
||||
em.remove(currentArtist);
|
||||
return currentArtist;
|
||||
}
|
||||
// @Transactional
|
||||
// public List<Song> findAllSongsProducedArtist(Artist currentArtist){
|
||||
// if(currentArtist.getAlbum().size() == 0){
|
||||
// throw new IllegalArgumentException("Artist doesn`t produced");
|
||||
// }
|
||||
// List songList = em.createQuery("SELECT DISTINCT a.songs FROM Album a where :artistAlbum MEMBER OF a.artists")
|
||||
// .setParameter("artistAlbum", currentArtist).getResultList();
|
||||
// return songList;
|
||||
// }
|
||||
@Transactional
|
||||
public List<Song> findAllSongsProducedArtist(Artist currentArtist){
|
||||
if(currentArtist.getAlbum().size() == 0){
|
||||
throw new IllegalArgumentException("Artist doesn`t produced");
|
||||
}
|
||||
List songList = em.createQuery("SELECT DISTINCT a.songs FROM Album a where :artistAlbum MEMBER OF a.artists")
|
||||
.setParameter("artistAlbum", currentArtist).getResultList();
|
||||
return songList;
|
||||
public List<Artist> findAllArtistsByName(String name){
|
||||
return em.createQuery("select A from Artist A where A.artistName = :name", Artist.class)
|
||||
.setParameter("name", name).getResultList();
|
||||
}
|
||||
@Transactional
|
||||
public void deleteAllArtists() {
|
||||
|
@ -0,0 +1,47 @@
|
||||
package ru.ulstu.is.sbapp.database.service;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class FindSongByNameService {
|
||||
@PersistenceContext
|
||||
EntityManager em;
|
||||
// @Transactional
|
||||
// public Map<String, List<Object>> findByName(String name) {
|
||||
// List<Song> songList = em.createQuery("select S from Song S where S.songName = :name", Song.class)
|
||||
// .setParameter("name", name)
|
||||
// .getResultList();
|
||||
// Map<String, List<Object>> resultMap = new HashMap<>(); // создаем пустую map
|
||||
// List<Object> resultList = new ArrayList<>(); // создаем пустой список объектов
|
||||
//
|
||||
// for(Song song : songList) { // перебираем список объектов Song
|
||||
//
|
||||
// Album album = song.getAlbum(); // получаем объект Album, связанный с текущей песней
|
||||
// String albumName = "";
|
||||
// List<Artist> artists = new ArrayList<>();
|
||||
// if(album != null) {
|
||||
// albumName = album.getAlbumName(); // получаем название альбома
|
||||
// artists = album.getArtists(); // получаем список исполнителей, связанный с текущим альбомом
|
||||
// }
|
||||
// resultList.add(song);
|
||||
// resultList.add(album); // добавляем объект Album в список
|
||||
// resultList.addAll(artists); // добавляем все объекты Artist в список
|
||||
//
|
||||
// resultMap.put(albumName, resultList); // добавляем результаты в map, используя название альбома как ключ
|
||||
// }
|
||||
// return resultMap; // возвращаем map
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -3,12 +3,15 @@ package ru.ulstu.is.sbapp.database.service;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class SongService {
|
||||
@ -84,4 +87,11 @@ public class SongService {
|
||||
public void deleteAllSongs() {
|
||||
em.createQuery("delete from Song").executeUpdate();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Song> findAllSongsByName(String name){
|
||||
return em.createQuery("select S from Song S where S.songName = :name", Song.class)
|
||||
.setParameter("name", name).getResultList();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import ru.ulstu.is.sbapp.database.model.Artist;
|
||||
import ru.ulstu.is.sbapp.database.model.Song;
|
||||
import ru.ulstu.is.sbapp.database.model.Album;
|
||||
import ru.ulstu.is.sbapp.database.service.ArtistService;
|
||||
import ru.ulstu.is.sbapp.database.service.FindSongByNameService;
|
||||
import ru.ulstu.is.sbapp.database.service.SongService;
|
||||
import ru.ulstu.is.sbapp.database.service.AlbumService;
|
||||
|
||||
@ -23,6 +24,43 @@ public class SbappApplicationTests {
|
||||
private SongService songService;
|
||||
@Autowired
|
||||
private ArtistService artistService;
|
||||
@Autowired
|
||||
private FindSongByNameService findService;
|
||||
|
||||
// @Test
|
||||
// void testDop(){
|
||||
// final Song song = songService.addSong("song", 2.50);
|
||||
// Assertions.assertNotNull(song.getId());
|
||||
//
|
||||
// Song song2 = songService.addSong("song2", 3.10);
|
||||
//
|
||||
// List<Song> songs = new ArrayList<>();
|
||||
// songs.add(song);
|
||||
// songs.add(song2);
|
||||
//
|
||||
// Artist artist = artistService.addArtist("artist", "genre");
|
||||
// Assertions.assertNotNull(artist.getId());
|
||||
//
|
||||
// Artist artist2 = artistService.addArtist("artist2", "genre");
|
||||
//
|
||||
// List<Artist> artists = new ArrayList<>();
|
||||
// artists.add(artist);
|
||||
// artists.add(artist2);
|
||||
//
|
||||
// Album album = albumService.addAlbum("album");
|
||||
// Album album2 = albumService.addAlbum("album2");
|
||||
// Assertions.assertNotNull(album.getId());
|
||||
//
|
||||
// List<Album> albums = new ArrayList<>();
|
||||
// albums.add(album);
|
||||
// albums.add(album2);
|
||||
//
|
||||
// findService.findAllSongs("song");
|
||||
//
|
||||
// albumService.deleteAllAlbums();
|
||||
// songService.deleteAllSongs();
|
||||
// artistService.deleteAllArtists();
|
||||
// }
|
||||
|
||||
@Test
|
||||
void test1(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user