#25 rename image, #24 Paste Image form Clipboard, keep selekted Deck

This commit is contained in:
Your Name
2025-02-02 17:28:20 +01:00
parent 28393570a6
commit 576689a3ed
9 changed files with 220 additions and 71 deletions

View File

@@ -124,6 +124,15 @@ export class DecksController {
return this.drizzleService.updateImage(data, user);
}
@Put('image/:bildid/rename')
async renameImage(@Request() req, @Param('bildid') bildid: string, @Body() data: { newImageName: string }) {
if (!data.newImageName) {
throw new HttpException('New image name is required', HttpStatus.BAD_REQUEST);
}
const user: User = req['user'];
return this.drizzleService.renameImage(bildid, data.newImageName, user);
}
@Delete('image/:bildid')
async deleteImagesByBildId(@Request() req, @Param('bildid') bildid: string) {
const user: User = req['user'];

View File

@@ -216,7 +216,32 @@ export class DrizzleService {
return { status: 'success', moved_entries: existingImages.length };
}
/**
* Methode zum Umbenennen eines Decks
*/
async renameImage(bildId: string, newImagename: string, user: User) {
const existingImages = this.db
.select()
.from(Deck)
.where(and(eq(Deck.bildid, bildId), eq(Deck.user, user.email)));
if (existingImages.length === 0) {
throw new HttpException('Deck not found', HttpStatus.NOT_FOUND);
}
// const existingNewDeck = await this.getDeckByName(newDeckname, user);
// if (existingNewDeck.length > 0) {
// throw new HttpException('Deck with the new name already exists', HttpStatus.CONFLICT);
// }
await this.db
.update(Deck)
.set({
bildname: newImagename,
updated: sql`CURRENT_TIMESTAMP`, // Setze 'updated' auf CURRENT_TIMESTAMP
})
.where(and(eq(Deck.bildid, bildId), eq(Deck.user, user.email)));
return { status: 'success', message: 'Image Entries renamed successfully' };
}
/**
* Methode zum Aktualisieren einer Box
*/