2025-02-21 13:31:37 -05:00
import { Body , Controller , Delete , Get , HttpCode , HttpStatus , Param , Post , Put , Query } from '@nestjs/common' ;
2025-11-13 08:18:43 -05:00
import { ApiTags } from '@nestjs/swagger' ;
import { Endpoint , HistoryBuilder } from 'src/decorators' ;
2024-04-02 10:23:17 -04:00
import { BulkIdResponseDto , BulkIdsDto } from 'src/dtos/asset-ids.response.dto' ;
import { AuthDto } from 'src/dtos/auth.dto' ;
2025-06-10 23:47:46 +10:00
import {
MemoryCreateDto ,
MemoryResponseDto ,
MemorySearchDto ,
MemoryStatisticsResponseDto ,
MemoryUpdateDto ,
} from 'src/dtos/memory.dto' ;
2025-11-11 17:01:14 -05:00
import { ApiTag , Permission } from 'src/enum' ;
2024-04-02 10:23:17 -04:00
import { Auth , Authenticated } from 'src/middleware/auth.guard' ;
import { MemoryService } from 'src/services/memory.service' ;
import { UUIDParamDto } from 'src/validation' ;
2025-11-11 17:01:14 -05:00
@ApiTags ( ApiTag . Memories )
2024-04-02 10:23:17 -04:00
@Controller ( 'memories' )
export class MemoryController {
constructor ( private service : MemoryService ) { }
@Get ( )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.MemoryRead } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Retrieve memories' ,
description :
'Retrieve a list of memories. Memories are sorted descending by creation date by default, although they can also be sorted in ascending order, or randomly.' ,
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
} )
2025-02-21 13:31:37 -05:00
searchMemories ( @Auth ( ) auth : AuthDto , @Query ( ) dto : MemorySearchDto ) : Promise < MemoryResponseDto [ ] > {
return this . service . search ( auth , dto ) ;
2024-04-02 10:23:17 -04:00
}
@Post ( )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.MemoryCreate } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Create a memory' ,
description :
'Create a new memory by providing a name, description, and a list of asset IDs to include in the memory.' ,
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-04-02 10:23:17 -04:00
createMemory ( @Auth ( ) auth : AuthDto , @Body ( ) dto : MemoryCreateDto ) : Promise < MemoryResponseDto > {
return this . service . create ( auth , dto ) ;
}
2025-06-10 23:47:46 +10:00
@Get ( 'statistics' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.MemoryStatistics } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Retrieve memories statistics' ,
description : 'Retrieve statistics about memories, such as total count and other relevant metrics.' ,
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
} )
2025-06-10 23:47:46 +10:00
memoriesStatistics ( @Auth ( ) auth : AuthDto , @Query ( ) dto : MemorySearchDto ) : Promise < MemoryStatisticsResponseDto > {
return this . service . statistics ( auth , dto ) ;
}
2024-04-02 10:23:17 -04:00
@Get ( ':id' )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.MemoryRead } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Retrieve a memory' ,
description : 'Retrieve a specific memory by its ID.' ,
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-04-02 10:23:17 -04:00
getMemory ( @Auth ( ) auth : AuthDto , @Param ( ) { id } : UUIDParamDto ) : Promise < MemoryResponseDto > {
return this . service . get ( auth , id ) ;
}
@Put ( ':id' )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.MemoryUpdate } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Update a memory' ,
description : 'Update an existing memory by its ID.' ,
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-04-02 10:23:17 -04:00
updateMemory (
@Auth ( ) auth : AuthDto ,
@Param ( ) { id } : UUIDParamDto ,
@Body ( ) dto : MemoryUpdateDto ,
) : Promise < MemoryResponseDto > {
return this . service . update ( auth , id , dto ) ;
}
@Delete ( ':id' )
2025-07-15 14:50:13 -04:00
@Authenticated ( { permission : Permission.MemoryDelete } )
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 a memory' ,
description : 'Delete a specific memory by its ID.' ,
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-04-02 10:23:17 -04:00
deleteMemory ( @Auth ( ) auth : AuthDto , @Param ( ) { id } : UUIDParamDto ) : Promise < void > {
return this . service . remove ( auth , id ) ;
}
@Put ( ':id/assets' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.MemoryAssetCreate } )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Add assets to a memory' ,
description : 'Add a list of asset IDs to a specific memory.' ,
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-04-02 10:23:17 -04:00
addMemoryAssets (
@Auth ( ) auth : AuthDto ,
@Param ( ) { id } : UUIDParamDto ,
@Body ( ) dto : BulkIdsDto ,
) : Promise < BulkIdResponseDto [ ] > {
return this . service . addAssets ( auth , id , dto ) ;
}
@Delete ( ':id/assets' )
2025-07-25 15:25:23 -04:00
@Authenticated ( { permission : Permission.MemoryAssetDelete } )
2025-08-08 15:56:37 -04:00
@HttpCode ( HttpStatus . OK )
2025-11-13 08:18:43 -05:00
@Endpoint ( {
2025-11-11 17:01:14 -05:00
summary : 'Remove assets from a memory' ,
description : 'Remove a list of asset IDs from a specific memory.' ,
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-04-02 10:23:17 -04:00
removeMemoryAssets (
@Auth ( ) auth : AuthDto ,
@Body ( ) dto : BulkIdsDto ,
@Param ( ) { id } : UUIDParamDto ,
) : Promise < BulkIdResponseDto [ ] > {
return this . service . removeAssets ( auth , id , dto ) ;
}
}