66from fastapi import APIRouter , Depends , HTTPException , Query , status
77from sqlalchemy .ext .asyncio import AsyncSession
88
9+ from app .auth .dependencies import get_current_user
910from app .crud import link as crud
1011from app .db .session import get_db
12+ from app .models .user import User
1113from app .schemas .link import (
1214 BulkReviewRequest ,
1315 LinkCreate ,
2123
2224# Link endpoints
2325@router .post ("/links" , response_model = LinkResponse , status_code = status .HTTP_201_CREATED )
24- async def create_link (link : LinkCreate , db : AsyncSession = Depends (get_db )):
26+ async def create_link (
27+ link : LinkCreate ,
28+ db : AsyncSession = Depends (get_db ),
29+ current_user : User = Depends (get_current_user ),
30+ ):
2531 """Create a new requirement-test case link"""
2632 try :
2733 return await crud .create_link (db , link )
@@ -36,13 +42,22 @@ async def create_link(link: LinkCreate, db: AsyncSession = Depends(get_db)):
3642
3743
3844@router .get ("/links" , response_model = list [LinkResponse ])
39- async def list_links (skip : int = 0 , limit : int = 100 , db : AsyncSession = Depends (get_db )):
45+ async def list_links (
46+ skip : int = 0 ,
47+ limit : int = 100 ,
48+ db : AsyncSession = Depends (get_db ),
49+ current_user : User = Depends (get_current_user ),
50+ ):
4051 """List all links"""
4152 return await crud .get_links (db , skip = skip , limit = limit )
4253
4354
4455@router .get ("/links/{link_id}" , response_model = LinkResponse )
45- async def get_link (link_id : UUID , db : AsyncSession = Depends (get_db )):
56+ async def get_link (
57+ link_id : UUID ,
58+ db : AsyncSession = Depends (get_db ),
59+ current_user : User = Depends (get_current_user ),
60+ ):
4661 """Get a specific link by ID"""
4762 link = await crud .get_link (db , link_id )
4863 if not link :
@@ -51,19 +66,31 @@ async def get_link(link_id: UUID, db: AsyncSession = Depends(get_db)):
5166
5267
5368@router .get ("/requirements/{requirement_id}/links" , response_model = list [LinkResponse ])
54- async def get_requirement_links (requirement_id : UUID , db : AsyncSession = Depends (get_db )):
69+ async def get_requirement_links (
70+ requirement_id : UUID ,
71+ db : AsyncSession = Depends (get_db ),
72+ current_user : User = Depends (get_current_user ),
73+ ):
5574 """Get all links for a specific requirement"""
5675 return await crud .get_links_by_requirement (db , requirement_id )
5776
5877
5978@router .get ("/test-cases/{test_case_id}/links" , response_model = list [LinkResponse ])
60- async def get_test_case_links (test_case_id : UUID , db : AsyncSession = Depends (get_db )):
79+ async def get_test_case_links (
80+ test_case_id : UUID ,
81+ db : AsyncSession = Depends (get_db ),
82+ current_user : User = Depends (get_current_user ),
83+ ):
6184 """Get all links for a specific test case"""
6285 return await crud .get_links_by_test_case (db , test_case_id )
6386
6487
6588@router .delete ("/links/{link_id}" , status_code = status .HTTP_204_NO_CONTENT )
66- async def delete_link (link_id : UUID , db : AsyncSession = Depends (get_db )):
89+ async def delete_link (
90+ link_id : UUID ,
91+ db : AsyncSession = Depends (get_db ),
92+ current_user : User = Depends (get_current_user ),
93+ ):
6794 """Delete a link"""
6895 deleted = await crud .delete_link (db , link_id )
6996 if not deleted :
@@ -72,7 +99,12 @@ async def delete_link(link_id: UUID, db: AsyncSession = Depends(get_db)):
7299
73100# Suggestion endpoints
74101@router .get ("/suggestions" , response_model = list [SuggestionResponse ])
75- async def list_suggestions (skip : int = 0 , limit : int = 100 , db : AsyncSession = Depends (get_db )):
102+ async def list_suggestions (
103+ skip : int = 0 ,
104+ limit : int = 100 ,
105+ db : AsyncSession = Depends (get_db ),
106+ current_user : User = Depends (get_current_user ),
107+ ):
76108 """List all link suggestions"""
77109 return await crud .get_suggestions (db , skip = skip , limit = limit )
78110
@@ -87,6 +119,7 @@ async def list_pending_suggestions(
87119 limit : int | None = Query (100 , le = 500 , description = "Maximum results to return" ),
88120 search : str | None = Query (None , description = "Search term to filter by requirement/test case title or description" ),
89121 db : AsyncSession = Depends (get_db ),
122+ current_user : User = Depends (get_current_user ),
90123):
91124 """List pending suggestions with filtering and sorting"""
92125 return await crud .get_pending_suggestions (
@@ -102,7 +135,11 @@ async def list_pending_suggestions(
102135
103136
104137@router .get ("/suggestions/{suggestion_id}" , response_model = SuggestionResponse )
105- async def get_suggestion (suggestion_id : UUID , db : AsyncSession = Depends (get_db )):
138+ async def get_suggestion (
139+ suggestion_id : UUID ,
140+ db : AsyncSession = Depends (get_db ),
141+ current_user : User = Depends (get_current_user ),
142+ ):
106143 """Get a specific suggestion by ID"""
107144 suggestion = await crud .get_suggestion (db , suggestion_id )
108145 if not suggestion :
@@ -111,7 +148,12 @@ async def get_suggestion(suggestion_id: UUID, db: AsyncSession = Depends(get_db)
111148
112149
113150@router .post ("/suggestions/{suggestion_id}/review" , response_model = SuggestionResponse )
114- async def review_suggestion (suggestion_id : UUID , review : SuggestionReview , db : AsyncSession = Depends (get_db )):
151+ async def review_suggestion (
152+ suggestion_id : UUID ,
153+ review : SuggestionReview ,
154+ db : AsyncSession = Depends (get_db ),
155+ current_user : User = Depends (get_current_user ),
156+ ):
115157 """Review a suggestion (accept/reject)"""
116158 reviewed = await crud .review_suggestion (db , suggestion_id , review )
117159 if not reviewed :
@@ -120,7 +162,11 @@ async def review_suggestion(suggestion_id: UUID, review: SuggestionReview, db: A
120162
121163
122164@router .post ("/suggestions/bulk-review" , response_model = dict [str , Any ])
123- async def bulk_review_suggestions (request : BulkReviewRequest , db : AsyncSession = Depends (get_db )):
165+ async def bulk_review_suggestions (
166+ request : BulkReviewRequest ,
167+ db : AsyncSession = Depends (get_db ),
168+ current_user : User = Depends (get_current_user ),
169+ ):
124170 """Review multiple suggestions at once"""
125171 reviewed = await crud .bulk_review_suggestions (
126172 db , request .suggestion_ids , request .status , request .feedback , request .reviewed_by
0 commit comments