|
|
|
@ -11,7 +11,7 @@ from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from app.models import HTTPError, User
|
|
|
|
|
from app.models.image import Image
|
|
|
|
|
from app.dto.image import ImageUploadDTO, ImageUpdateCaptionDTO
|
|
|
|
|
from app.dto.image import ImageUploadDTO, ImageCaptionDTO, ImageMetadataDTO
|
|
|
|
|
from .utils import get_current_user, objectid_misformatted
|
|
|
|
|
import app.config as config
|
|
|
|
|
|
|
|
|
@ -194,7 +194,7 @@ async def delete_image(id: str, current_user: User = Depends(get_current_user)):
|
|
|
|
|
)
|
|
|
|
|
async def update_caption(
|
|
|
|
|
id: str,
|
|
|
|
|
caption_data: ImageUpdateCaptionDTO,
|
|
|
|
|
caption_data: ImageCaptionDTO,
|
|
|
|
|
current_user: User = Depends(get_current_user)
|
|
|
|
|
):
|
|
|
|
|
check_image_permissions(id, current_user)
|
|
|
|
@ -204,4 +204,26 @@ async def update_caption(
|
|
|
|
|
{"$set": {"caption": caption_data.caption}}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return {"message": "Caption updated successfully"}
|
|
|
|
|
return {"message": "Caption updated successfully"}
|
|
|
|
|
|
|
|
|
|
@images_router.get(
|
|
|
|
|
path="/{id}/caption",
|
|
|
|
|
response_model=ImageCaptionDTO,
|
|
|
|
|
responses={401: {"model": HTTPError}, 403: {"model": HTTPError}, 404: {"model": HTTPError}}
|
|
|
|
|
)
|
|
|
|
|
async def get_caption(id: str, current_user: User = Depends(get_current_user)):
|
|
|
|
|
image = check_image_permissions(id, current_user)
|
|
|
|
|
return ImageCaptionDTO(caption=image.get("caption", ""))
|
|
|
|
|
|
|
|
|
|
@images_router.get(
|
|
|
|
|
path="/{id}/metadata",
|
|
|
|
|
response_model=ImageMetadataDTO,
|
|
|
|
|
responses={401: {"model": HTTPError}, 403: {"model": HTTPError}, 404: {"model": HTTPError}}
|
|
|
|
|
)
|
|
|
|
|
async def get_metadata(id: str, current_user: User = Depends(get_current_user)):
|
|
|
|
|
image = check_image_permissions(id, current_user)
|
|
|
|
|
return ImageMetadataDTO(
|
|
|
|
|
metadata=image.get("metadata", {}),
|
|
|
|
|
pin_id=str(image.get("pin_id")) if image.get("pin_id") else None
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|