Skip to content

Commit

Permalink
#212 replaced PlayQueueDao to SavedPlayQueueRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
kagemomiji committed Jan 2, 2024
1 parent 89deece commit 7ee1110
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.airsonic.player.ajax.LyricsInfo;
import org.airsonic.player.ajax.LyricsWSController;
import org.airsonic.player.command.UserSettingsCommand;
import org.airsonic.player.dao.PlayQueueDao;
import org.airsonic.player.domain.*;
import org.airsonic.player.domain.Bookmark;
import org.airsonic.player.domain.CoverArt.EntityType;
Expand Down Expand Up @@ -147,8 +146,6 @@ public class SubsonicRESTController {
@Autowired
private BookmarkService bookmarkService;
@Autowired
private PlayQueueDao playQueueDao;
@Autowired
private MediaScannerService mediaScannerService;
@Autowired
private MediaFolderService mediaFolderService;
Expand Down Expand Up @@ -1779,21 +1776,20 @@ public void getPlayQueue(HttpServletRequest request, HttpServletResponse respons
String username = securityService.getCurrentUsername(request);
Player player = playerService.getPlayer(request, response, username);

SavedPlayQueue playQueue = playQueueDao.getPlayQueue(username);
SavedPlayQueue playQueue = playQueueService.loadSavedPlayQueueForRest(username);
if (playQueue == null) {
writeEmptyResponse(request, response);
return;
}

org.subsonic.restapi.PlayQueue restPlayQueue = new org.subsonic.restapi.PlayQueue();
restPlayQueue.setUsername(playQueue.getUsername());
restPlayQueue.setCurrent(playQueue.getCurrentMediaFileId());
restPlayQueue.setCurrent(Optional.ofNullable(playQueue.getCurrentMediaFile()).map(MediaFile::getId).orElse(null));
restPlayQueue.setPosition(playQueue.getPositionMillis());
restPlayQueue.setChanged(jaxbWriter.convertDate(playQueue.getChanged()));
restPlayQueue.setChangedBy(playQueue.getChangedBy());

for (Integer mediaFileId : playQueue.getMediaFileIds()) {
MediaFile mediaFile = mediaFileService.getMediaFile(mediaFileId);
for (MediaFile mediaFile : playQueue.getMediaFiles()) {
if (mediaFile != null) {
restPlayQueue.getEntry().add(createJaxbChild(player, mediaFile, username));
}
Expand All @@ -1818,8 +1814,8 @@ public void savePlayQueue(HttpServletRequest request, HttpServletResponse respon
return;
}

SavedPlayQueue playQueue = new SavedPlayQueue(null, username, mediaFileIds, current, position, Instant.now(), changedBy);
playQueueDao.savePlayQueue(playQueue);
playQueueService.savePlayQueue(username, mediaFileIds, current, position, changedBy);

writeEmptyResponse(request, response);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with Airsonic. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2024 (C) Y.Tory
* Copyright 2015 (C) Sindre Mehus
*/

package org.airsonic.player.domain;

import javax.persistence.*;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -31,22 +35,43 @@
* @author Sindre Mehus
* @version $Id$
*/
@Entity
@Table(name = "play_queue", uniqueConstraints = @UniqueConstraint(columnNames = {"username"}))
public class SavedPlayQueue {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "username", nullable = false)
private String username;
private List<Integer> mediaFileIds;
private Integer currentMediaFileId;
@ManyToMany
@JoinTable(name = "play_queue_file",
joinColumns = @JoinColumn(name = "play_queue_id", referencedColumnName = "id"),
inverseJoinColumns = @JoinColumn(name = "media_file_id", referencedColumnName = "id"))
private List<MediaFile> mediaFiles = new ArrayList<>();
@OneToOne
@JoinColumn(name = "current_media_file_id", referencedColumnName = "id")
private MediaFile currentMediaFile;
@Column(name = "position_millis")
private Long positionMillis;
@Column(name = "changed")
private Instant changed;
@Column(name = "changed_by")
private String changedBy;

public SavedPlayQueue(Integer id, String username, List<Integer> mediaFileIds, Integer currentMediaFileId,
public SavedPlayQueue() {
}

public SavedPlayQueue(String username) {
this.username = username;
}

public SavedPlayQueue(Integer id, String username, List<MediaFile> mediaFiles, MediaFile currentMediaFile,
Long positionMillis, Instant changed, String changedBy) {
this.id = id;
this.username = username;
this.mediaFileIds = mediaFileIds;
this.currentMediaFileId = currentMediaFileId;
this.mediaFiles = mediaFiles;
this.currentMediaFile = currentMediaFile;
this.positionMillis = positionMillis;
this.changed = changed;
this.changedBy = changedBy;
Expand All @@ -68,20 +93,20 @@ public void setUsername(String username) {
this.username = username;
}

public List<Integer> getMediaFileIds() {
return mediaFileIds;
public List<MediaFile> getMediaFiles() {
return mediaFiles;
}

public void setMediaFileIds(List<Integer> mediaFileIds) {
this.mediaFileIds = mediaFileIds;
public void setMediaFiles(List<MediaFile> mediaFiles) {
this.mediaFiles = mediaFiles;
}

public Integer getCurrentMediaFileId() {
return currentMediaFileId;
public MediaFile getCurrentMediaFile() {
return currentMediaFile;
}

public void setCurrentMediaFileId(Integer currentMediaFileId) {
this.currentMediaFileId = currentMediaFileId;
public void setCurrentMediaFile(MediaFile currentMediaFile) {
this.currentMediaFile = currentMediaFile;
}

public Long getPositionMillis() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.airsonic.player.repository;

import org.airsonic.player.domain.SavedPlayQueue;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface SavedPlayQueueRepository extends JpaRepository<SavedPlayQueue, Integer> {

Optional<SavedPlayQueue> findByUsername(String username);

}
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ private boolean needsUpdate(MediaFile mediaFile, boolean minimizeDiskAccess) {
);
}

/**
* Return the media file for checking last modified.
*
* @param mediaFile The media file.
* @return updated media file.
*/
public MediaFile checkLastModified(MediaFile mediaFile) {
return checkLastModified(mediaFile, settingsService.isFastCacheEnabled());
}

private MediaFile checkLastModified(MediaFile mediaFile, boolean minimizeDiskAccess) {
MusicFolder folder = mediaFile.getFolder();
if (!needsUpdate(mediaFile, minimizeDiskAccess)) {
Expand Down
Loading

0 comments on commit 7ee1110

Please sign in to comment.