forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollaboration.controller.ts
More file actions
118 lines (105 loc) · 3.42 KB
/
Copy pathcollaboration.controller.ts
File metadata and controls
118 lines (105 loc) · 3.42 KB
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
import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
Query,
Req,
UseGuards,
ParseUUIDPipe,
BadRequestException,
} from '@nestjs/common';
import { Request } from 'express';
import { CollaborationService } from './collaboration.service';
import { CreateCollaborationDto } from './dto/create-collaboration.dto';
import { RespondToCollaborationDto, RemoveCollaborationDto } from './dto/update-collaboration.dto';
import { CollaborationStatus } from './entities/collaboration.entity';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { CurrentUser } from '../auth/decorators/current-user.decorator';
import { AuthUser } from '../auth/types/auth-user.interface';
@Controller('collaborations')
@UseGuards(JwtAuthGuard)
export class CollaborationController {
constructor(private readonly collaborationService: CollaborationService) {}
@Post()
async createCollaboration(
@CurrentUser() user: AuthUser,
@Body() createDto: CreateCollaborationDto,
) {
return this.collaborationService.createCollaboration(user.walletAddress, createDto);
}
@Get()
async getCollaborations(
@CurrentUser() user: AuthUser,
@Query('status') status?: CollaborationStatus,
@Query('page') page?: string,
@Query('limit') limit?: string,
) {
const pageNum = page ? parseInt(page, 10) : 1;
const limitNum = limit ? parseInt(limit, 10) : 10;
if (isNaN(pageNum) || pageNum < 1) {
throw new BadRequestException('Invalid page number');
}
if (isNaN(limitNum) || limitNum < 1 || limitNum > 100) {
throw new BadRequestException('Invalid limit number (must be between 1 and 100)');
}
return this.collaborationService.getCollaborationsForUser(
user.walletAddress,
status,
pageNum,
limitNum,
);
}
@Get('stats')
async getCollaborationStats(@CurrentUser() user: AuthUser) {
return this.collaborationService.getCollaborationStats(user.walletAddress);
}
@Get(':id')
async getCollaborationById(
@Param('id', ParseUUIDPipe) id: string,
@CurrentUser() user: AuthUser,
) {
return this.collaborationService.getCollaborationById(id, user.walletAddress);
}
@Put(':id/respond')
async respondToCollaboration(
@Param('id', ParseUUIDPipe) id: string,
@CurrentUser() user: AuthUser,
@Body() responseDto: RespondToCollaborationDto,
) {
return this.collaborationService.respondToCollaboration(id, user.walletAddress, responseDto);
}
@Delete(':id')
async removeCollaboration(
@Param('id', ParseUUIDPipe) id: string,
@CurrentUser() user: AuthUser,
@Body() removeDto: RemoveCollaborationDto,
) {
return this.collaborationService.removeCollaboration(
id,
user.walletAddress,
removeDto.removalReason,
);
}
@Get('track/:trackId')
async getTrackCollaborations(
@Param('trackId') trackId: string,
@CurrentUser() user: AuthUser,
@Query('status') status?: CollaborationStatus,
) {
// This endpoint would be useful for showing collaborations on a specific track
// For now, we'll delegate to the main service method
const result = await this.collaborationService.getCollaborationsForUser(user.walletAddress, status);
// Filter by track ID
const trackCollaborations = result.collaborations.filter(
collab => collab.trackId === trackId,
);
return {
collaborations: trackCollaborations,
total: trackCollaborations.length,
};
}
}