fix: bố cục lại cách hiển thị thông tin ảnh

This commit is contained in:
2026-06-20 08:04:12 +07:00
parent 5081546cdf
commit ac11bb56db
13 changed files with 749 additions and 393 deletions
+46
View File
@@ -1723,6 +1723,52 @@ class PhotoController {
}
});
}
@Post(':id/toggle-like')
@UseGuards(JwtAuthGuard)
async toggleLikePhoto(@Param('id', ParseUUIDPipe) id: string, @Req() req: any) {
const userId = req.user.id;
const photo = await this.prisma.photo.findUnique({
where: { id }
});
if (!photo) {
throw new NotFoundException('Không tìm thấy ảnh.');
}
const currentMetadata = (photo.metadata as any) || {};
const likedUserIds = Array.isArray(currentMetadata.likedUserIds)
? currentMetadata.likedUserIds
: [];
const index = likedUserIds.indexOf(userId);
let updatedLikedUserIds = [...likedUserIds];
if (index > -1) {
// Unlike
updatedLikedUserIds.splice(index, 1);
} else {
// Like
updatedLikedUserIds.push(userId);
}
const updatedMetadata = {
...currentMetadata,
likedUserIds: updatedLikedUserIds
};
return this.prisma.photo.update({
where: { id },
data: {
metadata: updatedMetadata
},
include: {
uploader: {
select: { id: true, name: true }
}
}
});
}
}
@UseGuards(JwtAuthGuard)