1414from fastapi .responses import FileResponse , Response
1515from pydantic import ValidationError
1616
17- from app .api .dependencies import get_source_id , get_source_service
17+ from app .api .dependencies import get_source_id , get_source_update_service
1818from app .schemas import Source , SourceCreate
1919from app .schemas .source import SourceCreateAdapter
2020from app .services import (
2121 ResourceInUseError ,
2222 ResourceNotFoundError ,
2323 ResourceWithIdAlreadyExistsError ,
2424 ResourceWithNameAlreadyExistsError ,
25- SourceService ,
25+ SourceUpdateService ,
2626)
2727
2828logger = logging .getLogger (__name__ )
@@ -109,11 +109,11 @@ def create_source(
109109 source_create : Annotated [
110110 SourceCreate , Body (description = CREATE_SOURCE_BODY_DESCRIPTION , openapi_examples = CREATE_SOURCE_BODY_EXAMPLES )
111111 ],
112- source_service : Annotated [SourceService , Depends (get_source_service )],
112+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
113113) -> Source :
114114 """Create and configure a new source"""
115115 try :
116- return source_service .create (source_create )
116+ return source_update_service .create (source_create )
117117 except (ResourceWithNameAlreadyExistsError , ResourceWithIdAlreadyExistsError ) as e :
118118 raise HTTPException (status_code = status .HTTP_409_CONFLICT , detail = str (e ))
119119
@@ -125,10 +125,10 @@ def create_source(
125125 },
126126)
127127def list_sources (
128- source_service : Annotated [SourceService , Depends (get_source_service )],
128+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
129129) -> list [Source ]:
130130 """List the available sources"""
131- return source_service .list_all ()
131+ return source_update_service .list_all ()
132132
133133
134134@router .get (
@@ -141,11 +141,11 @@ def list_sources(
141141)
142142def get_source (
143143 source_id : Annotated [UUID , Depends (get_source_id )],
144- source_service : Annotated [SourceService , Depends (get_source_service )],
144+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
145145) -> Source :
146146 """Get info about a source"""
147147 try :
148- return source_service .get_by_id (source_id )
148+ return source_update_service .get_by_id (source_id )
149149 except ResourceNotFoundError as e :
150150 raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = str (e ))
151151
@@ -168,14 +168,14 @@ def update_source(
168168 openapi_examples = UPDATE_SOURCE_BODY_EXAMPLES ,
169169 ),
170170 ],
171- source_service : Annotated [SourceService , Depends (get_source_service )],
171+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
172172) -> Source :
173173 """Reconfigure an existing source"""
174174 if "source_type" in source_config :
175175 raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "The 'source_type' field cannot be changed" )
176176 try :
177- source = source_service .get_by_id (source_id )
178- return source_service .update (source , source_config )
177+ source = source_update_service .get_by_id (source_id )
178+ return source_update_service .update (source , source_config )
179179 except ResourceNotFoundError as e :
180180 raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = str (e ))
181181 except ResourceWithNameAlreadyExistsError as e :
@@ -198,10 +198,10 @@ def update_source(
198198)
199199def export_source (
200200 source_id : Annotated [UUID , Depends (get_source_id )],
201- source_service : Annotated [SourceService , Depends (get_source_service )],
201+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
202202) -> Response :
203203 """Export a source to file"""
204- source = source_service .get_by_id (source_id )
204+ source = source_update_service .get_by_id (source_id )
205205 if not source :
206206 raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = f"Source with ID { source_id } not found" )
207207
@@ -226,14 +226,14 @@ def export_source(
226226)
227227def import_source (
228228 yaml_file : Annotated [UploadFile , File (description = "YAML file containing the source configuration" )],
229- source_service : Annotated [SourceService , Depends (get_source_service )],
229+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
230230) -> Source :
231231 """Import a source from file"""
232232 try :
233233 yaml_content = yaml_file .file .read ()
234234 source_data = yaml .safe_load (yaml_content )
235235 source_create = SourceCreateAdapter .validate_python (source_data )
236- return source_service .create (source_create )
236+ return source_update_service .create (source_create )
237237 except yaml .YAMLError as e :
238238 raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = f"Invalid YAML format: { str (e )} " )
239239 except (ResourceWithNameAlreadyExistsError , ResourceWithIdAlreadyExistsError ) as e :
@@ -256,11 +256,11 @@ def import_source(
256256)
257257def delete_source (
258258 source_id : Annotated [UUID , Depends (get_source_id )],
259- source_service : Annotated [SourceService , Depends (get_source_service )],
259+ source_update_service : Annotated [SourceUpdateService , Depends (get_source_update_service )],
260260) -> None :
261261 """Remove a source"""
262262 try :
263- source_service .delete_by_id (source_id )
263+ source_update_service .delete_by_id (source_id )
264264 except ResourceNotFoundError as e :
265265 raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = str (e ))
266266 except ResourceInUseError as e :
0 commit comments