Spaces:
Sleeping
Sleeping
File size: 3,860 Bytes
b0798af | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | import {
Controller,
Get,
Post,
Patch,
Delete,
Param,
Body,
UseGuards,
Req,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { PlaylistsService } from './playlists.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
@ApiTags('Playlists')
@Controller('playlists')
export class PlaylistsController {
constructor(private readonly playlistsService: PlaylistsService) {}
@Get()
@ApiOperation({ summary: 'List public playlists' })
getAllPlaylists() {
return this.playlistsService.findAll();
}
@Get(':id')
@ApiOperation({ summary: 'Get playlist details' })
getPlaylistById(@Param('id') id: string) {
return this.playlistsService.findOne(id);
}
@Post()
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create a new playlist' })
createPlaylist(
@Req() req: any,
@Body()
dto: {
title: string;
description?: string;
is_public?: boolean;
is_collaborative?: boolean;
},
) {
return this.playlistsService.create(dto, req.user?.userId);
}
@Patch(':id')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({
summary: 'Edit playlist title, description, or visibility flags',
})
updatePlaylist(@Param('id') id: string, @Body() dto: any) {
return this.playlistsService.update(id, dto);
}
@Delete(':id')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete a playlist' })
deletePlaylist(@Param('id') id: string) {
return this.playlistsService.remove(id);
}
@Post(':id/tracks')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Add one or more tracks to a playlist' })
addTracks(@Param('id') id: string, @Body() body: { track_ids: string[] }) {
return this.playlistsService.addTracks(id, body.track_ids || []);
}
@Delete(':id/tracks/:trackId')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Remove a track from a playlist' })
removeTrack(@Param('id') id: string, @Param('trackId') trackId: string) {
return this.playlistsService.removeTrack(id, trackId);
}
@Patch(':id/tracks/reorder')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Reorder playlist tracks via position indices' })
reorderTracks(
@Param('id') id: string,
@Body() body: { from_index: number; to_index: number },
) {
return this.playlistsService.reorderTracks(id, body);
}
@Post(':id/collaborators')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Invite a user as collaborative editor' })
addCollaborator(@Param('id') id: string, @Body() body: { user_id: string }) {
return this.playlistsService.addCollaborator(id, body.user_id);
}
@Get(':id/collaborators')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'List playlist collaborators' })
getCollaborators(@Param('id') id: string) {
return this.playlistsService.getCollaborators(id);
}
@Post(':id/cover')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Upload custom playlist cover image' })
uploadCover(@Param('id') id: string, @Body() body: { cover_url: string }) {
return this.playlistsService.uploadCover(id, body.cover_url);
}
@Post(':id/follow')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Follow (save) another user public playlist' })
followPlaylist(@Req() req: any, @Param('id') id: string) {
return this.playlistsService.followPlaylist(req.user.userId, id);
}
@Delete(':id/follow')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Unfollow a playlist' })
unfollowPlaylist(@Req() req: any, @Param('id') id: string) {
return this.playlistsService.unfollowPlaylist(req.user.userId, id);
}
}
|