feat(data): 统一数据结构处理并优化音乐播放功能
- 添加 extractList 函数统一处理不同数据结构(list、records、items) - 添加 extractPageData 函数标准化分页数据处理逻辑 - 修复音乐播放器移除播放列表项时的索引问题 - 优化播放列表清空时的音频暂停和状态重置 - 调整收藏按钮图标显示逻辑(实心星和空心星对调) - 更新前端API调用路径 /user/profile 为 /user/current - 修复后端收藏歌单查询的字段映射和排序问题 - 在主布局中引入 ArrowDown 图标用于下拉功能 - 改进用户中心头像上传的认证头构建方式 - 优化用户统计数据显示的数据提取逻辑
This commit is contained in:
@@ -36,6 +36,6 @@ public class UserCollectPlaylist {
|
||||
* 收藏时间
|
||||
*/
|
||||
@CreationTimestamp
|
||||
@Column(name = "collect_time", nullable = false, updatable = false)
|
||||
@Column(name = "create_time", nullable = false, updatable = false)
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
|
||||
@@ -3,19 +3,15 @@ package com.test.musichouduan.repository;
|
||||
import com.test.musichouduan.entity.Playlist;
|
||||
import com.test.musichouduan.entity.User;
|
||||
import com.test.musichouduan.entity.UserCollectPlaylist;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
@@ -89,7 +85,7 @@ public interface UserCollectPlaylistRepository extends JpaRepository<UserCollect
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query(value = "INSERT INTO user_collect_playlist (user_id, playlist_id, collect_time) VALUES (?1, ?2, NOW())", nativeQuery = true)
|
||||
@Query(value = "INSERT INTO user_collect_playlist (user_id, playlist_id, create_time) VALUES (?1, ?2, NOW())", nativeQuery = true)
|
||||
void collectPlaylist(Long userId, Long playlistId);
|
||||
|
||||
@Modifying
|
||||
@@ -97,7 +93,10 @@ public interface UserCollectPlaylistRepository extends JpaRepository<UserCollect
|
||||
@Query(value = "DELETE FROM user_collect_playlist WHERE user_id = ?1 AND playlist_id = ?2", nativeQuery = true)
|
||||
void uncollectPlaylist(Long userId, Long playlistId);
|
||||
|
||||
@Query("SELECT ucp.playlist FROM UserCollectPlaylist ucp WHERE ucp.user.id = ?1")
|
||||
@Query(
|
||||
value = "SELECT ucp.playlist FROM UserCollectPlaylist ucp WHERE ucp.user.id = ?1 ORDER BY ucp.createTime DESC",
|
||||
countQuery = "SELECT COUNT(ucp) FROM UserCollectPlaylist ucp WHERE ucp.user.id = ?1"
|
||||
)
|
||||
Page<Playlist> findCollectedPlaylist(Long userId, Pageable pageable);
|
||||
|
||||
Optional<UserCollectPlaylist> findByUserIdAndPlaylistId(Long userId, Long playlistId);
|
||||
|
||||
@@ -483,11 +483,11 @@ public class PlaylistServiceImpl implements PlaylistService {
|
||||
// 获取当前登录用户
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
|
||||
// 获取用户收藏的歌单
|
||||
Page<Playlist> playlistPage = userCollectPlaylistRepository.findCollectedPlaylist(
|
||||
userId,
|
||||
PageRequest.of(page - 1, size, Sort.by(Sort.Direction.DESC, "createTime"))
|
||||
);
|
||||
// 获取用户收藏的歌单
|
||||
Page<Playlist> playlistPage = userCollectPlaylistRepository.findCollectedPlaylist(
|
||||
userId,
|
||||
PageRequest.of(page - 1, size)
|
||||
);
|
||||
|
||||
// 转换为DTO
|
||||
List<PlaylistDTO> playlistDTOs = playlistPage.getContent().stream()
|
||||
|
||||
Reference in New Issue
Block a user