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

@ApiTags('Users & Profiles')
@Controller('users')
export class UsersController {
  constructor(private readonly usersService: UsersService) {}

  @Get('me')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: 'Get logged-in user profile' })
  getMe(@Req() req: any) {
    return this.usersService.getPublicProfile(req.user.userId);
  }

  @Patch('me')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: 'Update logged-in user profile' })
  updateMe(
    @Req() req: any,
    @Body()
    dto: {
      display_name?: string;
      username?: string;
      bio?: string;
      country?: string;
    },
  ) {
    return this.usersService.updateProfile(req.user.userId, dto);
  }

  @Post('me/avatar')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: 'Upload/replace profile picture' })
  uploadAvatar(@Req() req: any, @Body() dto: { avatar_url: string }) {
    return this.usersService.uploadAvatar(req.user.userId, dto.avatar_url);
  }

  @Delete('me')
  @UseGuards(JwtAuthGuard)
  @ApiBearerAuth()
  @ApiOperation({ summary: 'Soft-delete/deactivate account' })
  deleteMe(@Req() req: any) {
    return this.usersService.deleteAccount(req.user.userId);
  }

  @Get(':id')
  @ApiOperation({ summary: 'Get public user profile' })
  getPublicProfile(@Param('id') id: string) {
    return this.usersService.getPublicProfile(id);
  }

  @Get(':id/playlists')
  @ApiOperation({ summary: 'List a user public playlists' })
  getUserPlaylists(@Param('id') id: string) {
    return [
      {
        id: 'playlist-001',
        title: 'Kannada Hits & Melodies 2026',
        is_public: true,
        owner_id: id,
      },
    ];
  }

  @Get(':id/followers')
  @ApiOperation({ summary: 'List followers of a user' })
  getUserFollowers(@Param('id') id: string) {
    return [
      { id: 'user-002', username: 'music_lover', display_name: 'Music Lover' },
    ];
  }

  @Get(':id/following')
  @ApiOperation({ summary: 'List artists and users followed' })
  getUserFollowing(@Param('id') id: string) {
    return [{ id: 'artist-001', name: 'Anirudh Ravichander', type: 'artist' }];
  }
}