File size: 2,055 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
import {
  Controller,
  Get,
  Post,
  Patch,
  Param,
  Body,
  UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { ArtistsService } from './artists.service';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';

@ApiTags('Artists')
@Controller('artists')
export class ArtistsController {
  constructor(private readonly artistsService: ArtistsService) {}

  @Get(':id')
  @ApiOperation({ summary: 'Get artist profile & monthly listener count' })
  getArtistById(@Param('id') id: string) {
    return this.artistsService.findOne(id);
  }

  @Get(':id/albums')
  @ApiOperation({ summary: 'List artist discography (albums, EPs, singles)' })
  getArtistAlbums(@Param('id') id: string) {
    return this.artistsService.getAlbums(id);
  }

  @Get(':id/top-tracks')
  @ApiOperation({ summary: 'Get top 10 tracks by play_count' })
  getArtistTopTracks(@Param('id') id: string) {
    return this.artistsService.getTopTracks(id);
  }

  @Get(':id/related')
  @ApiOperation({ summary: 'Get related artists via pgvector similarity' })
  getRelatedArtists(@Param('id') id: string) {
    return this.artistsService.getRelated(id);
  }

  @Post()
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: 'Create new artist profile (onboarding)' })
  createArtist(
    @Body() dto: { name: string; bio?: string; image_url?: string },
  ) {
    return this.artistsService.create(dto);
  }

  @Patch(':id')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: 'Update artist bio, image, or name' })
  updateArtist(
    @Param('id') id: string,
    @Body() dto: { name?: string; bio?: string; image_url?: string },
  ) {
    return this.artistsService.update(id, dto);
  }

  @Get(':id/monthly-listeners')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({
    summary: 'Time-series monthly listener counts for artist dashboard',
  })
  getMonthlyListeners(@Param('id') id: string) {
    return this.artistsService.getMonthlyListenersTimeSeries(id);
  }
}