@@ -35,9 +35,9 @@ public static void MapAdditionalRoutes(IEndpointRouteBuilder parentRoute)
35
35
_ = resourceRoute . MapGet ( RoutesV2 . Images , GetObjectImages ) ;
36
36
}
37
37
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 )
39
39
{
40
- logger . LogInformation ( "Upload requested" ) ;
40
+ logger . LogInformation ( "[CreateAsync] Upload requested" ) ;
41
41
42
42
if ( string . IsNullOrEmpty ( request . DatBytesAsBase64 ) )
43
43
{
@@ -135,6 +135,8 @@ static async Task<IResult> CreateAsync(DtoUploadDat request, LocoDbContext db, [
135
135
136
136
static async Task < IResult > ReadAsync ( [ FromRoute ] UniqueObjectId id , LocoDbContext db , [ FromServices ] IServiceProvider sp , [ FromServices ] ILogger < ObjectRouteHandler > logger )
137
137
{
138
+ logger . LogInformation ( "[ReadAsync] Read requested for object {ObjectId}" , id ) ;
139
+
138
140
var eObj = await db . Objects
139
141
. Where ( x => x . Id == id )
140
142
. Include ( x => x . Licence )
@@ -147,16 +149,35 @@ static async Task<IResult> ReadAsync([FromRoute] UniqueObjectId id, LocoDbContex
147
149
return ReturnObject ( eObj , sfm , logger ) ;
148
150
}
149
151
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
+ }
152
157
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
+ }
155
164
156
- static async Task < IResult > ListAsync ( HttpContext context , LocoDbContext db )
165
+ static async Task < IResult > ListAsync ( HttpContext context , LocoDbContext db , [ FromServices ] ILogger < ObjectRouteHandler > logger )
157
166
{
158
- if ( context . Request . Query . Count > 0 )
167
+ logger . LogInformation ( "[ListAsync] List requested for object" ) ;
168
+
169
+ if ( context . Request . Query . Count == 0 )
159
170
{
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
+
160
181
var query = db . Objects . AsQueryable ( ) ;
161
182
var filters = context . Request . Query ;
162
183
@@ -215,22 +236,14 @@ static async Task<IResult> ListAsync(HttpContext context, LocoDbContext db)
215
236
216
237
//return Results.Problem(statusCode: StatusCodes.Status501NotImplemented);
217
238
}
218
- else
219
- {
220
- return Results . Ok (
221
- await db . Objects
222
- . Include ( x => x . DatObjects )
223
- . Select ( x => x . ToDtoEntry ( ) )
224
- . ToListAsync ( ) ) ;
225
- }
226
239
}
227
240
228
241
// 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 )
230
243
{
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 ) ;
233
245
246
+ // currently we MUST have a DAT backing object
234
247
var obj = await db . Objects
235
248
. Include ( x => x . DatObjects )
236
249
. Where ( x => x . Id == id )
@@ -241,6 +254,12 @@ static async Task<IResult> GetObjectImages([FromRoute] UniqueObjectId id, LocoDb
241
254
return Results . NotFound ( ) ;
242
255
}
243
256
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
+
244
263
if ( obj . Availability == Definitions . ObjectAvailability . Unavailable )
245
264
{
246
265
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
266
285
return Results . NotFound ( ) ;
267
286
}
268
287
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
-
275
288
var dummyLogger = new Logger ( ) ; // todo: make both libraries and server use a single logging interface
276
289
277
290
var locoObj = SawyerStreamReader . LoadFullObjectFromFile ( pathOnDisk , dummyLogger , true ) ;
@@ -307,8 +320,10 @@ static async Task<IResult> GetObjectImages([FromRoute] UniqueObjectId id, LocoDb
307
320
}
308
321
309
322
// 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 )
311
324
{
325
+ logger . LogInformation ( "[GetObjectFile] Get requested for object {ObjectId}" , id ) ;
326
+
312
327
var obj = await db . Objects
313
328
. Include ( x => x . DatObjects )
314
329
. Where ( x => x . Id == id )
0 commit comments