@@ -35,9 +35,9 @@ public static void MapAdditionalRoutes(IEndpointRouteBuilder parentRoute)
3535 _ = resourceRoute . MapGet ( RoutesV2 . Images , GetObjectImages ) ;
3636 }
3737
38- static async Task < IResult > CreateAsync ( DtoUploadDat request , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger , [ FromServices ] IServiceProvider sp )
38+ static async Task < IResult > CreateAsync ( DtoUploadDat request , LocoDbContext db , [ FromServices ] IServiceProvider sp , [ FromServices ] ILogger < ObjectRouteHandler > logger )
3939 {
40- logger . LogInformation ( "Upload requested" ) ;
40+ logger . LogInformation ( "[CreateAsync] Upload requested" ) ;
4141
4242 if ( string . IsNullOrEmpty ( request . DatBytesAsBase64 ) )
4343 {
@@ -135,6 +135,8 @@ static async Task<IResult> CreateAsync(DtoUploadDat request, LocoDbContext db, [
135135
136136 static async Task < IResult > ReadAsync ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] IServiceProvider sp , [ FromServices ] ILogger < ObjectRouteHandler > logger )
137137 {
138+ logger . LogInformation ( "[ReadAsync] Read requested for object {ObjectId}" , id ) ;
139+
138140 var eObj = await db . Objects
139141 . Where ( x => x . Id == id )
140142 . Include ( x => x . Licence )
@@ -147,16 +149,35 @@ static async Task<IResult> ReadAsync([FromRoute] UniqueObjectId id, LocoDbContex
147149 return ReturnObject ( eObj , sfm , logger ) ;
148150 }
149151
150- static async Task < IResult > UpdateAsync ( [ FromRoute ] UniqueObjectId id , DtoObjectDescriptor request , LocoDbContext db )
151- => await Task . Run ( ( ) => Results . Problem ( statusCode : StatusCodes . Status501NotImplemented ) ) ;
152+ static async Task < IResult > UpdateAsync ( [ FromRoute ] UniqueObjectId id , DtoObjectDescriptor request , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger )
153+ {
154+ logger . LogInformation ( "[UpdateAsync] Update requested for object {ObjectId}" , id ) ;
155+ return await Task . Run ( ( ) => Results . Problem ( statusCode : StatusCodes . Status501NotImplemented ) ) ;
156+ }
152157
153- static async Task < IResult > DeleteAsync ( [ FromRoute ] UniqueObjectId id , LocoDbContext db )
154- => await Task . Run ( ( ) => Results . Problem ( statusCode : StatusCodes . Status501NotImplemented ) ) ;
158+ static async Task < IResult > DeleteAsync ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger )
159+ {
160+ logger . LogInformation ( "[DeleteAsync] Delete requested for object {ObjectId}" , id ) ;
161+ // for now we could soft-delete by marking an object as Unavailable?
162+ return await Task . Run ( ( ) => Results . Problem ( statusCode : StatusCodes . Status501NotImplemented ) ) ;
163+ }
155164
156- static async Task < IResult > ListAsync ( HttpContext context , LocoDbContext db )
165+ static async Task < IResult > ListAsync ( HttpContext context , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger )
157166 {
158- if ( context . Request . Query . Count > 0 )
167+ logger . LogInformation ( "[ListAsync] List requested for object" ) ;
168+
169+ if ( context . Request . Query . Count == 0 )
159170 {
171+ return Results . Ok (
172+ await db . Objects
173+ . Include ( x => x . DatObjects )
174+ . Select ( x => x . ToDtoEntry ( ) )
175+ . ToListAsync ( ) ) ;
176+ }
177+ else
178+ {
179+ logger . LogInformation ( "[ListAsync] Request had {ParamCount} query params {Params}" , context . Request . Query . Count , context . Request . Query . ToString ( ) ) ;
180+
160181 var query = db . Objects . AsQueryable ( ) ;
161182 var filters = context . Request . Query ;
162183
@@ -215,22 +236,14 @@ static async Task<IResult> ListAsync(HttpContext context, LocoDbContext db)
215236
216237 //return Results.Problem(statusCode: StatusCodes.Status501NotImplemented);
217238 }
218- else
219- {
220- return Results . Ok (
221- await db . Objects
222- . Include ( x => x . DatObjects )
223- . Select ( x => x . ToDtoEntry ( ) )
224- . ToListAsync ( ) ) ;
225- }
226239 }
227240
228241 // eg: http://localhost:7229/v1/objects/{id}/images
229- static async Task < IResult > GetObjectImages ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger , [ FromServices ] IServiceProvider sp )
242+ static async Task < IResult > GetObjectImages ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] IServiceProvider sp , [ FromServices ] ILogger < ObjectRouteHandler > logger )
230243 {
231- // currently we MUST have a DAT backing object
232- logger . LogInformation ( "Object [{uniqueObjectId}] requested with images" , id ) ;
244+ logger . LogInformation ( "[GetObjectImages] Get requested for object {ObjectId}" , id ) ;
233245
246+ // currently we MUST have a DAT backing object
234247 var obj = await db . Objects
235248 . Include ( x => x . DatObjects )
236249 . Where ( x => x . Id == id )
@@ -241,6 +254,12 @@ static async Task<IResult> GetObjectImages([FromRoute] UniqueObjectId id, LocoDb
241254 return Results . NotFound ( ) ;
242255 }
243256
257+ if ( obj . ObjectSource is ObjectSource . LocomotionGoG or ObjectSource . LocomotionSteam )
258+ {
259+ logger . LogWarning ( "Indexed object is a vanilla object" ) ;
260+ return Results . Forbid ( ) ;
261+ }
262+
244263 if ( obj . Availability == Definitions . ObjectAvailability . Unavailable )
245264 {
246265 logger . LogWarning ( "Object [Id={Id} Name={Name}] is marked as Unavailable and cannot be downloaded" , obj . Id , obj . Name ) ;
@@ -266,12 +285,6 @@ static async Task<IResult> GetObjectImages([FromRoute] UniqueObjectId id, LocoDb
266285 return Results . NotFound ( ) ;
267286 }
268287
269- if ( obj . ObjectSource is ObjectSource . LocomotionGoG or ObjectSource . LocomotionSteam )
270- {
271- logger . LogWarning ( "Indexed object is a vanilla object" ) ;
272- return Results . Forbid ( ) ;
273- }
274-
275288 var dummyLogger = new Logger ( ) ; // todo: make both libraries and server use a single logging interface
276289
277290 var locoObj = SawyerStreamReader . LoadFullObjectFromFile ( pathOnDisk , dummyLogger , true ) ;
@@ -307,8 +320,10 @@ static async Task<IResult> GetObjectImages([FromRoute] UniqueObjectId id, LocoDb
307320 }
308321
309322 // eg: https://localhost:7230/objects/114
310- static async Task < IResult > GetObjectFile ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger , [ FromServices ] IServiceProvider sp )
323+ static async Task < IResult > GetObjectFile ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] IServiceProvider sp , [ FromServices ] ILogger < ObjectRouteHandler > logger )
311324 {
325+ logger . LogInformation ( "[GetObjectFile] Get requested for object {ObjectId}" , id ) ;
326+
312327 var obj = await db . Objects
313328 . Include ( x => x . DatObjects )
314329 . Where ( x => x . Id == id )
0 commit comments