@@ -131,6 +131,46 @@ def get_current_version(
131131 current_version = current_version
132132 )
133133
134+
135+ @router .get ("/{bulletin_id}/current-version-published" , response_model = BulletinWithCurrentVersion )
136+ def get_current_version_published (
137+ bulletin_id : str = Path (..., description = "ID del boletín" ),
138+ ):
139+ """
140+ Public endpoint that returns the bulletin master and its current version
141+ ONLY if the bulletin status is PUBLISHED. No authentication required.
142+ Returns 404 if the bulletin doesn't exist or is not published.
143+ """
144+
145+ # Get bulletin master without authentication
146+ bulletin_master = bulletins_master_service .get_by_id (id = bulletin_id )
147+ if not bulletin_master :
148+ raise HTTPException (status_code = 404 , detail = "Bulletin not found" )
149+
150+ print ("Bulletin master status:" , bulletin_master .status )
151+
152+ # Verify the bulletin is PUBLISHED (security check for public access)
153+ if bulletin_master .status != StatusBulletin .PUBLISHED :
154+ raise HTTPException (status_code = 404 , detail = "Bulletin not found" )
155+
156+ # Get the current version
157+ version_id = bulletins_master_service .get_current_version_id (bulletin_id )
158+ if not version_id :
159+ raise HTTPException (status_code = 404 , detail = "Bulletin not found" )
160+
161+ try :
162+ current_version = bulletins_version_service .read_schema .model_validate (
163+ bulletins_version_service ._serialize_document (version_id )
164+ )
165+ except Exception as e :
166+ raise HTTPException (status_code = 404 , detail = "Bulletin not found" )
167+
168+ return BulletinWithCurrentVersion (
169+ master = bulletin_master ,
170+ current_version = current_version
171+ )
172+
173+
134174# --- CRUD and queries for bulletin versions ---
135175
136176@router .post ("/versions" , response_model = BulletinsVersionRead )
0 commit comments