Skip to content

Commit dc5ed80

Browse files
authored
Merge pull request #5 from CIAT-DAPA/develop
add enpoint for published bulletins
2 parents 05ba1dc + 73a69a1 commit dc5ed80

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/api/bulletins_management.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)