File size: 2,076 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
import {
  Controller,
  Get,
  Post,
  Delete,
  Param,
  UseGuards,
  Req,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { LibraryService } from './library.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@ApiTags('Your Library')
@Controller('me/library')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class LibraryController {
  constructor(private readonly libraryService: LibraryService) {}

  @Get('tracks')
  @ApiOperation({ summary: 'Get Liked Songs list' })
  getSavedTracks(@Req() req: any) {
    return this.libraryService.getSavedTracks(req.user.userId);
  }

  @Post('tracks/:trackId')
  @ApiOperation({ summary: 'Save (like) a track' })
  saveTrack(@Req() req: any, @Param('trackId') trackId: string) {
    return this.libraryService.saveTrack(req.user.userId, trackId);
  }

  @Delete('tracks/:trackId')
  @ApiOperation({ summary: 'Unsave (unlike) a track' })
  unsaveTrack(@Req() req: any, @Param('trackId') trackId: string) {
    return this.libraryService.unsaveTrack(req.user.userId, trackId);
  }

  @Get('albums')
  @ApiOperation({ summary: 'Get saved albums' })
  getSavedAlbums(@Req() req: any) {
    return this.libraryService.getSavedAlbums(req.user.userId);
  }

  @Post('albums/:albumId')
  @ApiOperation({ summary: 'Save an album' })
  saveAlbum(@Req() req: any, @Param('albumId') albumId: string) {
    return this.libraryService.saveAlbum(req.user.userId, albumId);
  }

  @Delete('albums/:albumId')
  @ApiOperation({ summary: 'Unsave an album' })
  unsaveAlbum(@Req() req: any, @Param('albumId') albumId: string) {
    return this.libraryService.unsaveAlbum(req.user.userId, albumId);
  }

  @Get('artists')
  @ApiOperation({ summary: 'Get followed artists' })
  getFollowedArtists(@Req() req: any) {
    return this.libraryService.getFollowedArtists(req.user.userId);
  }

  @Get('playlists')
  @ApiOperation({ summary: 'Get owned & followed playlists' })
  getUserPlaylists(@Req() req: any) {
    return this.libraryService.getUserPlaylists(req.user.userId);
  }
}