2023-11-01 04:13:34 +01:00
import { Body , Controller , Delete , Get , HttpCode , HttpStatus , Param , Post , Query , Res } from '@nestjs/common' ;
2025-11-13 08:18:43 -05:00
import { ApiTags } from '@nestjs/swagger' ;
2023-11-01 04:13:34 +01:00
import { Response } from 'express' ;
2025-11-13 08:18:43 -05:00
import { Endpoint , HistoryBuilder } from 'src/decorators' ;
2024-03-20 19:32:04 +01:00
import {
ActivityCreateDto ,
ActivityDto ,
ActivityResponseDto ,
ActivitySearchDto ,
ActivityStatisticsResponseDto ,
2024-03-20 23:53:07 +01:00
} from 'src/dtos/activity.dto' ;
import { AuthDto } from 'src/dtos/auth.dto' ;
2025-11-11 17:01:14 -05:00
import { ApiTag , Permission } from 'src/enum' ;
2024-03-20 15:15:01 -05:00
import { Auth , Authenticated } from 'src/middleware/auth.guard' ;
2024-03-21 00:07:30 +01:00
import { ActivityService } from 'src/services/activity.service' ;
2024-03-20 15:04:03 -05:00
import { UUIDParamDto } from 'src/validation' ;
2023-11-01 04:13:34 +01:00
2025-11-11 17:01:14 -05:00
@ApiTags ( ApiTag . Activities )
2024-05-22 13:24:57 -04:00
@Controller ( 'activities' )
2023-11-01 04:13:34 +01:00
export class ActivityController {
constructor ( private service : ActivityService ) { }
@Get ( )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.ActivityRead } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'List all activities' ,
description :
'Returns a list of activities for the selected asset or album. The activities are returned in sorted order, with the oldest activities appearing first.' ,
2025-11-13 08:18:43 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) ,
2025-11-11 17:01:14 -05:00
} )
2024-03-20 19:32:04 +01:00
getActivities ( @Auth ( ) auth : AuthDto , @Query ( ) dto : ActivitySearchDto ) : Promise < ActivityResponseDto [ ] > {
2023-12-09 23:34:12 -05:00
return this . service . getAll ( auth , dto ) ;
2023-11-01 04:13:34 +01:00
}
@Post ( )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.ActivityCreate } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Create an activity' ,
description : 'Create a like or a comment for an album, or an asset in an album.' ,
2025-11-13 08:18:43 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) ,
2025-11-11 17:01:14 -05:00
} )
2023-11-01 04:13:34 +01:00
async createActivity (
2023-12-09 23:34:12 -05:00
@Auth ( ) auth : AuthDto ,
2024-03-20 19:32:04 +01:00
@Body ( ) dto : ActivityCreateDto ,
2023-11-01 04:13:34 +01:00
@Res ( { passthrough : true } ) res : Response ,
2024-03-20 19:32:04 +01:00
) : Promise < ActivityResponseDto > {
2023-12-09 23:34:12 -05:00
const { duplicate , value } = await this . service . create ( auth , dto ) ;
2023-11-01 04:13:34 +01:00
if ( duplicate ) {
res . status ( HttpStatus . OK ) ;
}
return value ;
}
2024-08-20 08:50:14 -04:00
@Get ( 'statistics' )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.ActivityStatistics } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Retrieve activity statistics' ,
description : 'Returns the number of likes and comments for a given album or asset in an album.' ,
2025-11-13 08:18:43 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) ,
2025-11-11 17:01:14 -05:00
} )
2024-08-20 08:50:14 -04:00
getActivityStatistics ( @Auth ( ) auth : AuthDto , @Query ( ) dto : ActivityDto ) : Promise < ActivityStatisticsResponseDto > {
return this . service . getStatistics ( auth , dto ) ;
}
2023-11-01 04:13:34 +01:00
@Delete ( ':id' )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.ActivityDelete } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . NO_CONTENT )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Delete an activity' ,
description : 'Removes a like or comment from a given album or asset in an album.' ,
2025-11-13 08:18:43 -05:00
history : new HistoryBuilder ( ) . added ( 'v1' ) . beta ( 'v1' ) . stable ( 'v2' ) ,
2025-11-11 17:01:14 -05:00
} )
2023-12-09 23:34:12 -05:00
deleteActivity ( @Auth ( ) auth : AuthDto , @Param ( ) { id } : UUIDParamDto ) : Promise < void > {
return this . service . delete ( auth , id ) ;
2023-11-01 04:13:34 +01:00
}
}