22from typing import Any
33
44from fastapi import APIRouter , HTTPException
5- from sqlmodel import func , select
65
76from app import crud
87from app .api .deps import CurrentUser , SessionDep
98from app .models import (
10- Message ,
11- Gallery ,
9+ GalleriesPublic ,
1210 GalleryCreate ,
1311 GalleryPublic ,
14- GalleriesPublic ,
1512 GalleryUpdate ,
16- Project ,
13+ Message ,
1714)
1815
1916router = APIRouter ()
@@ -32,26 +29,31 @@ def read_galleries(
3229 Otherwise, get all galleries for the user's organization.
3330 """
3431 if not current_user .organization_id :
35- raise HTTPException (status_code = 400 , detail = "User is not part of an organization" )
36-
32+ raise HTTPException (
33+ status_code = 400 , detail = "User is not part of an organization"
34+ )
35+
3736 if project_id :
3837 # Verify project belongs to user's organization
3938 project = crud .get_project (session = session , project_id = project_id )
4039 if not project or project .organization_id != current_user .organization_id :
4140 raise HTTPException (status_code = 403 , detail = "Not enough permissions" )
42-
41+
4342 galleries = crud .get_galleries_by_project (
4443 session = session , project_id = project_id , skip = skip , limit = limit
4544 )
4645 count = len (galleries ) # Simple count for project galleries
4746 else :
4847 galleries = crud .get_galleries_by_organization (
49- session = session , organization_id = current_user .organization_id , skip = skip , limit = limit
48+ session = session ,
49+ organization_id = current_user .organization_id ,
50+ skip = skip ,
51+ limit = limit ,
5052 )
5153 count = crud .count_galleries_by_organization (
5254 session = session , organization_id = current_user .organization_id
5355 )
54-
56+
5557 return GalleriesPublic (data = galleries , count = count )
5658
5759
@@ -63,13 +65,15 @@ def create_gallery(
6365 Create new gallery.
6466 """
6567 if not current_user .organization_id :
66- raise HTTPException (status_code = 400 , detail = "User is not part of an organization" )
67-
68+ raise HTTPException (
69+ status_code = 400 , detail = "User is not part of an organization"
70+ )
71+
6872 # Verify project belongs to user's organization
6973 project = crud .get_project (session = session , project_id = gallery_in .project_id )
7074 if not project or project .organization_id != current_user .organization_id :
7175 raise HTTPException (status_code = 403 , detail = "Not enough permissions" )
72-
76+
7377 gallery = crud .create_gallery (session = session , gallery_in = gallery_in )
7478 return gallery
7579
@@ -82,12 +86,12 @@ def read_gallery(session: SessionDep, current_user: CurrentUser, id: uuid.UUID)
8286 gallery = crud .get_gallery (session = session , gallery_id = id )
8387 if not gallery :
8488 raise HTTPException (status_code = 404 , detail = "Gallery not found" )
85-
89+
8690 # Check if gallery's project belongs to user's organization
8791 project = crud .get_project (session = session , project_id = gallery .project_id )
8892 if not project or project .organization_id != current_user .organization_id :
8993 raise HTTPException (status_code = 403 , detail = "Not enough permissions" )
90-
94+
9195 return gallery
9296
9397
@@ -105,13 +109,15 @@ def update_gallery(
105109 gallery = crud .get_gallery (session = session , gallery_id = id )
106110 if not gallery :
107111 raise HTTPException (status_code = 404 , detail = "Gallery not found" )
108-
112+
109113 # Check if gallery's project belongs to user's organization
110114 project = crud .get_project (session = session , project_id = gallery .project_id )
111115 if not project or project .organization_id != current_user .organization_id :
112116 raise HTTPException (status_code = 403 , detail = "Not enough permissions" )
113-
114- gallery = crud .update_gallery (session = session , db_gallery = gallery , gallery_in = gallery_in )
117+
118+ gallery = crud .update_gallery (
119+ session = session , db_gallery = gallery , gallery_in = gallery_in
120+ )
115121 return gallery
116122
117123
@@ -125,12 +131,11 @@ def delete_gallery(
125131 gallery = crud .get_gallery (session = session , gallery_id = id )
126132 if not gallery :
127133 raise HTTPException (status_code = 404 , detail = "Gallery not found" )
128-
134+
129135 # Check if gallery's project belongs to user's organization
130136 project = crud .get_project (session = session , project_id = gallery .project_id )
131137 if not project or project .organization_id != current_user .organization_id :
132138 raise HTTPException (status_code = 403 , detail = "Not enough permissions" )
133-
139+
134140 crud .delete_gallery (session = session , gallery_id = id )
135141 return Message (message = "Gallery deleted successfully" )
136-
0 commit comments