Merge branch 'lukas'
This commit is contained in:
commit
6acefcf69a
3 changed files with 50 additions and 9 deletions
|
@ -3,7 +3,6 @@ package com.serena.backend.controller;
|
||||||
import com.serena.backend.dto.ApiResponse;
|
import com.serena.backend.dto.ApiResponse;
|
||||||
import com.serena.backend.dto.ConnectClientRequest;
|
import com.serena.backend.dto.ConnectClientRequest;
|
||||||
import com.serena.backend.dto.AddSongRequest;
|
import com.serena.backend.dto.AddSongRequest;
|
||||||
import com.serena.backend.dto.AddSongToStationRequest;
|
|
||||||
import com.serena.backend.service.RadioStationService;
|
import com.serena.backend.service.RadioStationService;
|
||||||
import com.serena.backend.service.JwtService;
|
import com.serena.backend.service.JwtService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -30,7 +29,7 @@ public class SongController {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean success = radioStationService.addSongToQueue(request.getRadioStationId(), request.getSong());
|
boolean success = radioStationService.addSongToQueue(request.getRadioStationId(), request.getSong());
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
return ResponseEntity.ok(new ApiResponse<>(true, "Song added to queue successfully", null));
|
return ResponseEntity.ok(new ApiResponse<>(true, "Song added to queue successfully", null));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,17 +1,31 @@
|
||||||
package com.serena.backend.model;
|
package com.serena.backend.model;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Song {
|
public class Song {
|
||||||
private String id;
|
private String id;
|
||||||
private int popularity;
|
private int popularity;
|
||||||
|
private double tempo;
|
||||||
|
private Map<String, Double> audioFeatures;
|
||||||
|
|
||||||
public Song() {}
|
public Song() {
|
||||||
|
this.audioFeatures = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
public Song(String id, int popularity) {
|
public Song(String id, int popularity) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.popularity = popularity;
|
this.popularity = popularity;
|
||||||
|
this.audioFeatures = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Song(String id, int popularity, double tempo, Map<String, Double> audioFeatures) {
|
||||||
|
this.id = id;
|
||||||
|
this.popularity = popularity;
|
||||||
|
this.tempo = tempo;
|
||||||
|
this.audioFeatures = audioFeatures != null ? audioFeatures : new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters and Setters
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -27,4 +41,20 @@ public class Song {
|
||||||
public void setPopularity(int popularity) {
|
public void setPopularity(int popularity) {
|
||||||
this.popularity = popularity;
|
this.popularity = popularity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double getTempo() {
|
||||||
|
return tempo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTempo(double tempo) {
|
||||||
|
this.tempo = tempo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Double> getAudioFeatures() {
|
||||||
|
return audioFeatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAudioFeatures(Map<String, Double> audioFeatures) {
|
||||||
|
this.audioFeatures = audioFeatures;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,6 @@ public class RadioStationService {
|
||||||
return new ArrayList<>(radioStations.values());
|
return new ArrayList<>(radioStations.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RadioStation> getActiveRadioStations() {
|
|
||||||
return radioStations.values().stream()
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Optional<RadioStation> updateRadioStation(String stationId, String name, String description) {
|
public Optional<RadioStation> updateRadioStation(String stationId, String name, String description) {
|
||||||
RadioStation station = radioStations.get(stationId);
|
RadioStation station = radioStations.get(stationId);
|
||||||
if (station != null) {
|
if (station != null) {
|
||||||
|
@ -120,4 +115,21 @@ public class RadioStationService {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean addSongToQueue(String radioStationId, Song song) {
|
||||||
|
RadioStation station = radioStations.get(radioStationId);
|
||||||
|
if (station != null) {
|
||||||
|
station.addSongToQueue(song);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Song> getNextSong(String radioStationId) {
|
||||||
|
RadioStation station = radioStations.get(radioStationId);
|
||||||
|
if (station != null) {
|
||||||
|
return Optional.ofNullable(station.getNextSong());
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue