Merge branch 'lukas'

This commit is contained in:
Lukas Weger 2025-08-02 00:43:28 +02:00
commit 6acefcf69a
3 changed files with 50 additions and 9 deletions

View file

@ -3,7 +3,6 @@ package com.serena.backend.controller;
import com.serena.backend.dto.ApiResponse;
import com.serena.backend.dto.ConnectClientRequest;
import com.serena.backend.dto.AddSongRequest;
import com.serena.backend.dto.AddSongToStationRequest;
import com.serena.backend.service.RadioStationService;
import com.serena.backend.service.JwtService;
import org.springframework.beans.factory.annotation.Autowired;
@ -30,7 +29,7 @@ public class SongController {
}
boolean success = radioStationService.addSongToQueue(request.getRadioStationId(), request.getSong());
if (success) {
return ResponseEntity.ok(new ApiResponse<>(true, "Song added to queue successfully", null));
} else {

View file

@ -1,17 +1,31 @@
package com.serena.backend.model;
import java.util.Map;
import java.util.HashMap;
public class Song {
private String id;
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) {
this.id = id;
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() {
return id;
}
@ -27,4 +41,20 @@ public class Song {
public void setPopularity(int 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;
}
}

View file

@ -38,11 +38,6 @@ public class RadioStationService {
return new ArrayList<>(radioStations.values());
}
public List<RadioStation> getActiveRadioStations() {
return radioStations.values().stream()
.toList();
}
public Optional<RadioStation> updateRadioStation(String stationId, String name, String description) {
RadioStation station = radioStations.get(stationId);
if (station != null) {
@ -120,4 +115,21 @@ public class RadioStationService {
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();
}
}