-
-
Notifications
You must be signed in to change notification settings - Fork 620
feat: implement albums feature with create, edit, delete, and image management UI #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
afcecea
5841ada
67e9937
634140f
3078e9d
6ab8ede
a25088f
262874a
4884638
828781f
4fac437
f942bbe
28966fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| from fastapi import APIRouter, HTTPException, status, Query, Body, Path | ||
| from fastapi import APIRouter, HTTPException, status, Body, Path | ||
| import uuid | ||
| from app.schemas.album import ( | ||
| GetAlbumsResponse, | ||
|
|
@@ -11,6 +11,7 @@ | |
| SuccessResponse, | ||
| ErrorResponse, | ||
| ImageIdsRequest, | ||
| SetCoverImageRequest, | ||
| Album, | ||
| ) | ||
| from app.database.albums import ( | ||
|
|
@@ -24,24 +25,33 @@ | |
| db_add_images_to_album, | ||
| db_remove_image_from_album, | ||
| db_remove_images_from_album, | ||
| db_update_album_cover_image, | ||
| verify_album_password, | ||
| db_get_image_path, | ||
| ) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
| # GET /albums/ - Get all albums | ||
| # GET /albums/ - Get all albums (including locked ones) | ||
| @router.get("/", response_model=GetAlbumsResponse) | ||
| def get_albums(show_hidden: bool = Query(False)): | ||
| albums = db_get_all_albums(show_hidden) | ||
| def get_albums(): | ||
| """Get all albums. Always returns both locked and unlocked albums.""" | ||
| albums = db_get_all_albums() | ||
| album_list = [] | ||
| for album in albums: | ||
| # Get image count for each album | ||
| image_ids = db_get_album_images(album[0]) | ||
| image_count = len(image_ids) | ||
|
|
||
| album_list.append( | ||
| Album( | ||
| album_id=album[0], | ||
| album_name=album[1], | ||
| description=album[2] or "", | ||
| is_hidden=bool(album[3]), | ||
| is_locked=bool(album[3]), | ||
| cover_image_path=album[5] if len(album) > 5 else None, | ||
| image_count=image_count, | ||
| ) | ||
| ) | ||
|
Comment on lines
42
to
56
|
||
| return GetAlbumsResponse(success=True, albums=album_list) | ||
|
|
@@ -64,7 +74,7 @@ def create_album(body: CreateAlbumRequest): | |
| album_id = str(uuid.uuid4()) | ||
| try: | ||
| db_insert_album( | ||
| album_id, body.name, body.description, body.is_hidden, body.password | ||
| album_id, body.name, body.description, body.is_locked, body.password | ||
| ) | ||
| return CreateAlbumResponse(success=True, album_id=album_id) | ||
| except Exception as e: | ||
|
|
@@ -91,11 +101,17 @@ def get_album(album_id: str = Path(...)): | |
| ) | ||
|
|
||
| try: | ||
| # Get image count for the album | ||
| image_ids = db_get_album_images(album_id) | ||
| image_count = len(image_ids) | ||
|
|
||
| album_obj = Album( | ||
| album_id=album[0], | ||
| album_name=album[1], | ||
| description=album[2] or "", | ||
| is_hidden=bool(album[3]), | ||
| is_locked=bool(album[3]), | ||
| cover_image_path=album[5] if len(album) > 5 else None, | ||
| image_count=image_count, | ||
| ) | ||
| return GetAlbumResponse(success=True, data=album_obj) | ||
| except Exception as e: | ||
|
|
@@ -127,11 +143,11 @@ def update_album(album_id: str = Path(...), body: UpdateAlbumRequest = Body(...) | |
| "album_id": album[0], | ||
| "album_name": album[1], | ||
| "description": album[2], | ||
| "is_hidden": bool(album[3]), | ||
| "is_locked": bool(album[3]), | ||
| "password_hash": album[4], | ||
| } | ||
|
|
||
| if album_dict["password_hash"]: | ||
| if album_dict["is_locked"]: | ||
| if not body.current_password: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_401_UNAUTHORIZED, | ||
|
|
@@ -154,7 +170,7 @@ def update_album(album_id: str = Path(...), body: UpdateAlbumRequest = Body(...) | |
|
|
||
| try: | ||
| db_update_album( | ||
| album_id, body.name, body.description, body.is_hidden, body.password | ||
| album_id, body.name, body.description, body.is_locked, body.password | ||
| ) | ||
| return SuccessResponse(success=True, msg="Album updated successfully") | ||
| except Exception as e: | ||
|
|
@@ -215,18 +231,18 @@ def get_album_images( | |
| "album_id": album[0], | ||
| "album_name": album[1], | ||
| "description": album[2], | ||
| "is_hidden": bool(album[3]), | ||
| "is_locked": bool(album[3]), | ||
| "password_hash": album[4], | ||
| } | ||
|
|
||
| if album_dict["is_hidden"]: | ||
| if album_dict["is_locked"]: | ||
| if not body.password: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_401_UNAUTHORIZED, | ||
| detail=ErrorResponse( | ||
| success=False, | ||
| error="Password Required", | ||
| message="Password is required to access this hidden album.", | ||
| message="Password is required to access this locked album.", | ||
| ).model_dump(), | ||
| ) | ||
| if not verify_album_password(album_id, body.password): | ||
|
|
@@ -355,3 +371,60 @@ def remove_images_from_album( | |
| success=False, error="Failed to Remove Images", message=str(e) | ||
| ).model_dump(), | ||
| ) | ||
|
|
||
|
|
||
| # PUT /albums/{album_id}/cover - Set album cover image | ||
| @router.put("/{album_id}/cover", response_model=SuccessResponse) | ||
| def set_album_cover_image( | ||
| album_id: str = Path(...), body: SetCoverImageRequest = Body(...) | ||
| ): | ||
| """Set or update the cover image for an album""" | ||
| album = db_get_album(album_id) | ||
| if not album: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| detail=ErrorResponse( | ||
| success=False, | ||
| error="Album Not Found", | ||
| message="No album exists with the provided ID.", | ||
| ).model_dump(), | ||
| ) | ||
|
|
||
| # Verify the image exists in the album | ||
| album_image_ids = db_get_album_images(album_id) | ||
| if body.image_id not in album_image_ids: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_400_BAD_REQUEST, | ||
| detail=ErrorResponse( | ||
| success=False, | ||
| error="Image Not In Album", | ||
| message="The specified image is not in this album.", | ||
| ).model_dump(), | ||
| ) | ||
|
|
||
| try: | ||
| # Get the image path from the database | ||
| image_path = db_get_image_path(body.image_id) | ||
|
|
||
| if not image_path: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_404_NOT_FOUND, | ||
| detail=ErrorResponse( | ||
| success=False, | ||
| error="Image Not Found", | ||
| message="The specified image does not exist.", | ||
| ).model_dump(), | ||
| ) | ||
|
|
||
| db_update_album_cover_image(album_id, image_path) | ||
|
SiddharthJiyani marked this conversation as resolved.
|
||
|
|
||
| return SuccessResponse( | ||
| success=True, msg="Album cover image updated successfully" | ||
| ) | ||
| except Exception as e: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
| detail=ErrorResponse( | ||
| success=False, error="Failed to Set Cover Image", message=str(e) | ||
| ).model_dump(), | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.