Skip to content

Commit 929ca5a

Browse files
committed
add more logging to object handler routes
1 parent 7d5abef commit 929ca5a

File tree

2 files changed

+59
-34
lines changed

2 files changed

+59
-34
lines changed

ObjectService/RouteHandlers/TableHandlers/ObjectRouteHandler.cs

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

ObjectService/RouteHandlers/TableHandlers/V1RouteHandler.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ public static async Task<IResult> ListObjects(
106106
[FromQuery] string? authorName,
107107
[FromQuery] string? tagName,
108108
[FromQuery] ObjectSource? objectSource,
109-
LocoDbContext db)
109+
LocoDbContext db,
110+
[FromServices] ILogger<LegacyRouteHandler> logger)
110111
{
112+
logger.LogInformation("[ListObjects]");
113+
111114
var query = db.Objects
112115
.Include(x => x.DatObjects)
113116
.AsQueryable();
@@ -179,7 +182,7 @@ public static async Task<IResult> ListObjects(
179182
// eg: https://localhost:7230/v1/objects/getdat?objectName=114&checksum=123$returnObjBytes=false
180183
public static async Task<IResult> GetDat([FromQuery] string datName, [FromQuery] uint datChecksum, [FromQuery] bool? returnObjBytes, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger, [FromServices] IServiceProvider sp)
181184
{
182-
logger.LogInformation("Object [({ObjectName}, {Checksum})] requested", datName, datChecksum);
185+
logger.LogInformation("[GetDat] Object [({ObjectName}, {Checksum})] requested", datName, datChecksum);
183186

184187
var eObj = await db.Objects
185188
.Include(x => x.DatObjects)
@@ -195,7 +198,7 @@ public static async Task<IResult> GetDat([FromQuery] string datName, [FromQuery]
195198
// eg: http://localhost:7229/v1/objects/getobjectimages?uniqueObjectId=1
196199
public static async Task<IResult> GetObjectImages(UniqueObjectId uniqueObjectId, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger, [FromServices] IServiceProvider sp)
197200
{
198-
logger.LogDebug($"Object [{uniqueObjectId}] requested with images");
201+
logger.LogInformation("[GetObjectImages] Object [{ObjectId}] requested with images", uniqueObjectId);
199202

200203
var obj = await db.Objects
201204
.Include(x => x.DatObjects)
@@ -268,7 +271,7 @@ public static async Task<IResult> GetObjectImages(UniqueObjectId uniqueObjectId,
268271
// eg: https://localhost:7230/v1/objects/getobject?uniqueObjectId=246263256&returnObjBytes=false
269272
public static async Task<IResult> GetObject([FromQuery] int uniqueObjectId, [FromQuery] bool? returnObjBytes, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger, [FromServices] IServiceProvider sp)
270273
{
271-
logger.LogInformation("Object [{UniqueObjectId}] requested", uniqueObjectId);
274+
logger.LogInformation("[GetObject] Object [{ObjectId}] requested", uniqueObjectId);
272275

273276
var eObj = await db.Objects
274277
.Where(x => (int)x.Id == uniqueObjectId && x.Availability == Definitions.ObjectAvailability.Available)
@@ -331,8 +334,10 @@ static async Task<IResult> ReturnObject(bool? returnObjBytes, ILogger<LegacyRout
331334
}
332335

333336
// eg: https://localhost:7230/v1/objects/originaldatfile?objectName=114&checksum=123
334-
public static async Task<IResult> GetDatFile([FromQuery] string datName, [FromQuery] uint datChecksum, LocoDbContext db, [FromServices] IServiceProvider sp)
337+
public static async Task<IResult> GetDatFile([FromQuery] string datName, [FromQuery] uint datChecksum, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger, [FromServices] IServiceProvider sp)
335338
{
339+
logger.LogInformation("[GetDatFile] DatName={DatName} DatChecksum={DatChecksum}", datName, datChecksum);
340+
336341
var obj = await db.DatObjects
337342
.Include(x => x.Object)
338343
.Where(x => x.DatName == datName && x.DatChecksum == datChecksum && x.Object.Availability == Definitions.ObjectAvailability.Available)
@@ -348,8 +353,10 @@ public static async Task<IResult> GetDatFile([FromQuery] string datName, [FromQu
348353
}
349354

350355
// eg: https://localhost:7230/v1/objects/getobjectfile?objectName=114&checksum=123
351-
public static async Task<IResult> GetObjectFile([FromQuery] int uniqueObjectId, LocoDbContext db, [FromServices] IServiceProvider sp)
356+
public static async Task<IResult> GetObjectFile([FromQuery] int uniqueObjectId, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger, [FromServices] IServiceProvider sp)
352357
{
358+
logger.LogInformation("[GetObjectFile] Object [{ObjectId}] requested", uniqueObjectId);
359+
353360
var obj = await db.DatObjects
354361
.Include(x => x.Object)
355362
.Where(x => (int)x.Object.Id == uniqueObjectId && x.Object.Availability == Definitions.ObjectAvailability.Available)
@@ -407,7 +414,10 @@ public static async Task<IResult> ListScenarios([FromServices] IServiceProvider
407414

408415
// eg: https://localhost:7230/v1/scenarios/getscenario?uniqueScenarioId=246263256&returnObjBytes=false
409416
public static async Task<IResult> GetScenario([FromQuery] int uniqueScenarioId, [FromQuery] bool? returnObjBytes, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger)
410-
=> await Task.Run(() => Results.Problem(statusCode: StatusCodes.Status501NotImplemented));
417+
{
418+
logger.LogInformation("[GetScenario] Scenario [{ScenarioId}] requested", uniqueScenarioId);
419+
return await Task.Run(() => Results.Problem(statusCode: StatusCodes.Status501NotImplemented));
420+
}
411421

412422
#endregion
413423

@@ -474,7 +484,7 @@ public static async Task<IResult> GetSC5FilePack([FromQuery] int uniqueId, LocoD
474484
// eg: https://localhost:7230/v1/uploaddat/...
475485
public static async Task<IResult> UploadDat(DtoUploadDat request, LocoDbContext db, [FromServices] ILogger<LegacyRouteHandler> logger, [FromServices] IServiceProvider sp)
476486
{
477-
logger.LogInformation("Upload requested");
487+
logger.LogInformation("[UploadDat] Upload requested");
478488

479489
if (string.IsNullOrEmpty(request.DatBytesAsBase64))
480490
{

0 commit comments

Comments
 (0)